1
0
mirror of https://github.com/wolfpld/tracy synced 2025-05-02 05:33:53 +00:00

Update ImGuiColorTextEdit to 0a88824f7de8d.

This commit is contained in:
Bartosz Taudul 2019-06-22 14:19:10 +02:00
parent 18cef20db9
commit 53fe688bff
2 changed files with 798 additions and 339 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,6 @@
#include <unordered_map> #include <unordered_map>
#include <map> #include <map>
#include <regex> #include <regex>
#include "../imgui/imgui.h" #include "../imgui/imgui.h"
namespace tracy namespace tracy
@ -61,7 +60,14 @@ public:
, mEnabled(false) , mEnabled(false)
{} {}
}; };
// Represents a character coordinate from the user's point of view,
// i. e. consider an uniform grid (assuming fixed-width font) on the
// screen as it is rendered, and each cell has its own coordinate, starting from 0.
// Tabs are counted as [1..mTabSize] count empty spaces, depending on
// how many space is necessary to reach the next tab stop.
// For example, coordinate (1, 5) represents the character 'B' in a line "\tABC", when mTabSize = 4,
// because it is rendered as " ABC" on the screen.
struct Coordinates struct Coordinates
{ {
int mLine, mColumn; int mLine, mColumn;
@ -128,8 +134,8 @@ public:
typedef std::map<int, std::string> ErrorMarkers; typedef std::map<int, std::string> ErrorMarkers;
typedef std::unordered_set<int> Breakpoints; typedef std::unordered_set<int> Breakpoints;
typedef std::array<ImU32, (unsigned)PaletteIndex::Max> Palette; typedef std::array<ImU32, (unsigned)PaletteIndex::Max> Palette;
typedef char Char; typedef uint8_t Char;
struct Glyph struct Glyph
{ {
Char mChar; Char mChar;
@ -138,7 +144,7 @@ public:
bool mMultiLineComment : 1; bool mMultiLineComment : 1;
bool mPreprocessor : 1; bool mPreprocessor : 1;
Glyph(Char aChar, PaletteIndex aColorIndex) : mChar(aChar), mColorIndex(aColorIndex), Glyph(Char aChar, PaletteIndex aColorIndex) : mChar(aChar), mColorIndex(aColorIndex),
mComment(false), mMultiLineComment(false), mPreprocessor(false) {} mComment(false), mMultiLineComment(false), mPreprocessor(false) {}
}; };
@ -149,7 +155,7 @@ public:
{ {
typedef std::pair<std::string, PaletteIndex> TokenRegexString; typedef std::pair<std::string, PaletteIndex> TokenRegexString;
typedef std::vector<TokenRegexString> TokenRegexStrings; typedef std::vector<TokenRegexString> TokenRegexStrings;
typedef bool (*TokenizeCallback)(const char * in_begin, const char * in_end, const char *& out_begin, const char *& out_end, PaletteIndex & paletteIndex); typedef bool(*TokenizeCallback)(const char * in_begin, const char * in_end, const char *& out_begin, const char *& out_end, PaletteIndex & paletteIndex);
std::string mName; std::string mName;
Keywords mKeywords; Keywords mKeywords;
@ -164,12 +170,12 @@ public:
TokenRegexStrings mTokenRegexStrings; TokenRegexStrings mTokenRegexStrings;
bool mCaseSensitive; bool mCaseSensitive;
LanguageDefinition() LanguageDefinition()
: mPreprocChar('#'), mAutoIndentation(true), mTokenize(nullptr), mCaseSensitive(true) : mPreprocChar('#'), mAutoIndentation(true), mTokenize(nullptr), mCaseSensitive(true)
{ {
} }
static const LanguageDefinition& CPlusPlus(); static const LanguageDefinition& CPlusPlus();
static const LanguageDefinition& HLSL(); static const LanguageDefinition& HLSL();
static const LanguageDefinition& GLSL(); static const LanguageDefinition& GLSL();
@ -193,12 +199,14 @@ public:
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 std::string& aText);
void SetTextLines(const std::vector<std::string>& aLines);
std::string GetText() const; std::string GetText() const;
void SetTextLines(const std::vector<std::string>& aLines);
std::vector<std::string> GetTextLines() const; std::vector<std::string> GetTextLines() const;
std::string GetSelectedText() const; std::string GetSelectedText() const;
std::string GetCurrentLineText()const; std::string GetCurrentLineText()const;
int GetTotalLines() const { return (int)mLines.size(); } int GetTotalLines() const { return (int)mLines.size(); }
bool IsOverwrite() const { return mOverwrite; } bool IsOverwrite() const { return mOverwrite; }
@ -207,9 +215,27 @@ public:
bool IsTextChanged() const { return mTextChanged; } bool IsTextChanged() const { return mTextChanged; }
bool IsCursorPositionChanged() const { return mCursorPositionChanged; } bool IsCursorPositionChanged() const { return mCursorPositionChanged; }
bool IsColorizerEnabled() const { return mColorizerEnabled; }
void SetColorizerEnable(bool aValue);
Coordinates GetCursorPosition() const { return GetActualCursorCoordinates(); } Coordinates GetCursorPosition() const { return GetActualCursorCoordinates(); }
void SetCursorPosition(const Coordinates& aPosition); void SetCursorPosition(const Coordinates& aPosition);
inline void SetHandleMouseInputs (bool aValue){ mHandleMouseInputs = aValue;}
inline bool IsHandleMouseInputsEnabled() const { return mHandleKeyboardInputs; }
inline void SetHandleKeyboardInputs (bool aValue){ mHandleKeyboardInputs = aValue;}
inline bool IsHandleKeyboardInputsEnabled() const { return mHandleKeyboardInputs; }
inline void SetImGuiChildIgnored (bool aValue){ mIgnoreImGuiChild = aValue;}
inline bool IsImGuiChildIgnored() const { return mIgnoreImGuiChild; }
inline void SetShowWhitespaces(bool aValue) { mShowWhitespaces = aValue; }
inline bool IsShowingWhitespaces() const { return mShowWhitespaces; }
void SetTabSize(int aValue);
inline int GetTabSize() const { return mTabSize; }
void InsertText(const std::string& aValue); void InsertText(const std::string& aValue);
void InsertText(const char* aValue); void InsertText(const char* aValue);
@ -261,14 +287,14 @@ private:
UndoRecord( UndoRecord(
const std::string& aAdded, const std::string& aAdded,
const TextEditor::Coordinates aAddedStart, const TextEditor::Coordinates aAddedStart,
const TextEditor::Coordinates aAddedEnd, const TextEditor::Coordinates aAddedEnd,
const std::string& aRemoved, const std::string& aRemoved,
const TextEditor::Coordinates aRemovedStart, const TextEditor::Coordinates aRemovedStart,
const TextEditor::Coordinates aRemovedEnd, const TextEditor::Coordinates aRemovedEnd,
TextEditor::EditorState& aBefore, TextEditor::EditorState& aBefore,
TextEditor::EditorState& aAfter); TextEditor::EditorState& aAfter);
void Undo(TextEditor* aEditor); void Undo(TextEditor* aEditor);
@ -295,7 +321,6 @@ private:
float TextDistanceToLineStart(const Coordinates& aFrom) const; float TextDistanceToLineStart(const Coordinates& aFrom) const;
void EnsureCursorVisible(); void EnsureCursorVisible();
int GetPageSize() const; int GetPageSize() const;
int AppendBuffer(std::string& aBuffer, char chr, int aIndex);
std::string GetText(const Coordinates& aStart, const Coordinates& aEnd) const; std::string GetText(const Coordinates& aStart, const Coordinates& aEnd) const;
Coordinates GetActualCursorCoordinates() const; Coordinates GetActualCursorCoordinates() const;
Coordinates SanitizeCoordinates(const Coordinates& aValue) const; Coordinates SanitizeCoordinates(const Coordinates& aValue) const;
@ -306,12 +331,17 @@ private:
Coordinates ScreenPosToCoordinates(const ImVec2& aPosition) const; Coordinates ScreenPosToCoordinates(const ImVec2& aPosition) const;
Coordinates FindWordStart(const Coordinates& aFrom) const; Coordinates FindWordStart(const Coordinates& aFrom) const;
Coordinates FindWordEnd(const Coordinates& aFrom) const; Coordinates FindWordEnd(const Coordinates& aFrom) const;
Coordinates FindNextWord(const Coordinates& aFrom) const;
int GetCharacterIndex(const Coordinates& aCoordinates) const;
int GetCharacterColumn(int aLine, int aIndex) const;
int GetLineCharacterCount(int aLine) const;
int GetLineMaxColumn(int aLine) const;
bool IsOnWordBoundary(const Coordinates& aAt) const; bool IsOnWordBoundary(const Coordinates& aAt) const;
void RemoveLine(int aStart, int aEnd); void RemoveLine(int aStart, int aEnd);
void RemoveLine(int aIndex); void RemoveLine(int aIndex);
Line& InsertLine(int aIndex); Line& InsertLine(int aIndex);
void EnterCharacter(Char aChar, bool aShift); void EnterCharacter(ImWchar aChar, bool aShift);
void BackSpace(); void Backspace();
void DeleteSelection(); void DeleteSelection();
std::string GetWordUnderCursor() const; std::string GetWordUnderCursor() const;
std::string GetWordAt(const Coordinates& aCoords) const; std::string GetWordAt(const Coordinates& aCoords) const;
@ -326,7 +356,7 @@ private:
EditorState mState; EditorState mState;
UndoBuffer mUndoBuffer; UndoBuffer mUndoBuffer;
int mUndoIndex; int mUndoIndex;
int mTabSize; int mTabSize;
bool mOverwrite; bool mOverwrite;
bool mReadOnly; bool mReadOnly;
@ -334,11 +364,16 @@ private:
bool mScrollToCursor; bool mScrollToCursor;
bool mScrollToTop; bool mScrollToTop;
bool mTextChanged; bool mTextChanged;
float mTextStart; // position (in pixels) where a code line starts relative to the left of the TextEditor. bool mColorizerEnabled;
float mTextStart; // position (in pixels) where a code line starts relative to the left of the TextEditor.
int mLeftMargin; int mLeftMargin;
bool mCursorPositionChanged; bool mCursorPositionChanged;
int mColorRangeMin, mColorRangeMax; int mColorRangeMin, mColorRangeMax;
SelectionMode mSelectionMode; SelectionMode mSelectionMode;
bool mHandleKeyboardInputs;
bool mHandleMouseInputs;
bool mIgnoreImGuiChild;
bool mShowWhitespaces;
Palette mPaletteBase; Palette mPaletteBase;
Palette mPalette; Palette mPalette;
@ -350,7 +385,9 @@ private:
ErrorMarkers mErrorMarkers; ErrorMarkers mErrorMarkers;
ImVec2 mCharAdvance; ImVec2 mCharAdvance;
Coordinates mInteractiveStart, mInteractiveEnd; Coordinates mInteractiveStart, mInteractiveEnd;
std::string mLineBuffer;
uint64_t mStartTime;
float mLastClick; float mLastClick;
}; };