1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Just accept const char ptr in ImGuiColorTextEdit.

This commit is contained in:
Bartosz Taudul 2018-08-18 01:16:15 +02:00
parent 2c7d457755
commit 69dd0b72c1
3 changed files with 9 additions and 8 deletions

View File

@ -746,21 +746,22 @@ void TextEditor::Render(const char* aTitle, const ImVec2& aSize, bool aBorder)
mWithinRender = false; mWithinRender = false;
} }
void TextEditor::SetText(const std::string & aText) void TextEditor::SetText(const char* aText)
{ {
mLines.clear(); mLines.clear();
for (auto chr : aText) while( *aText )
{ {
if (mLines.empty()) if (mLines.empty())
mLines.push_back(Line()); mLines.push_back(Line());
if (chr == '\n') if (*aText == '\n')
mLines.push_back(Line()); mLines.push_back(Line());
else else
{ {
mLines.back().push_back(Glyph(chr, PaletteIndex::Default)); mLines.back().push_back(Glyph(*aText, PaletteIndex::Default));
} }
mTextChanged = true; mTextChanged = true;
aText++;
} }
mUndoBuffer.clear(); mUndoBuffer.clear();

View File

@ -179,7 +179,7 @@ public:
void SetBreakpoints(const Breakpoints& aMarkers) { mBreakpoints = aMarkers; } void SetBreakpoints(const Breakpoints& aMarkers) { mBreakpoints = aMarkers; }
void Render(const char* aTitle, const ImVec2& aSize = ImVec2(), bool aBorder = false); void Render(const char* aTitle, const ImVec2& aSize = ImVec2(), bool aBorder = false);
void SetText(const std::string& aText); void SetText(const char* aText);
std::string GetText() const; std::string GetText() const;
std::string GetSelectedText() const; std::string GetSelectedText() const;

View File

@ -416,11 +416,11 @@ void View::SetTextEditorFile( const char* fileName, int line )
fseek( f, 0, SEEK_END ); fseek( f, 0, SEEK_END );
const auto sz = ftell( f ); const auto sz = ftell( f );
fseek( f, 0, SEEK_SET ); fseek( f, 0, SEEK_SET );
std::string data; auto data = new char[sz];
data.resize( sz ); fread( data, 1, sz, f );
fread( data.data(), 1, sz, f );
fclose( f ); fclose( f );
m_textEditor->SetText( data ); m_textEditor->SetText( data );
delete[] data;
} }
m_textEditor->SetCursorPosition( TextEditor::Coordinates( line-1, 0 ) ); m_textEditor->SetCursorPosition( TextEditor::Coordinates( line-1, 0 ) );