mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
fix: Incorrect horizontal scrollbar displayed. (#2209)
The horizontal scroll bar length is set using the maximum line length across the input file. The original setup had the lengths of imported and included files added so changes are made to insure that only changes from the input file are taken. This required changes to the Pattern Language library so the library is updated to the latest version as well.
This commit is contained in:
2
lib/external/pattern_language
vendored
2
lib/external/pattern_language
vendored
Submodule lib/external/pattern_language updated: 9833500589...5a83e9e685
@@ -295,6 +295,9 @@ public:
|
||||
void SetText(const std::string& aText);
|
||||
void JumpToLine(int line=-1);
|
||||
void JumpToCoords(const Coordinates &coords);
|
||||
void SetLongestLineLength(size_t line) {
|
||||
mLongestLineLength = line;
|
||||
}
|
||||
std::string GetText() const;
|
||||
bool isEmpty() const {
|
||||
auto text = GetText();
|
||||
@@ -555,7 +558,6 @@ private:
|
||||
int GetCharacterColumn(int aLine, int aIndex) const;
|
||||
int GetLineCharacterCount(int aLine) const;
|
||||
int Utf8CharsToBytes(const Coordinates &aCoordinates) const;
|
||||
int GetLongestLineLength() const;
|
||||
unsigned long long GetLineByteCount(int aLine) const;
|
||||
int GetStringCharacterCount(std::string str) const;
|
||||
int GetLineMaxColumn(int aLine) const;
|
||||
@@ -594,7 +596,7 @@ private:
|
||||
bool mTextChanged = false;
|
||||
bool mColorizerEnabled = true;
|
||||
float mLineNumberFieldWidth = 0.0F;
|
||||
float mLongest = 0.0F;
|
||||
size_t mLongestLineLength = 0;
|
||||
float mTextStart = 20.0F; // position (in pixels) where a code line starts relative to the left of the TextEditor.
|
||||
float mLeftMargin = 10.0;
|
||||
float mTopLine = 0.0F;
|
||||
|
||||
@@ -847,13 +847,6 @@ void TextEditor::HandleMouseInputs() {
|
||||
}
|
||||
}
|
||||
|
||||
int TextEditor::GetLongestLineLength() const {
|
||||
int result = 0;
|
||||
for (int i = 0; i < (int)mLines.size(); i++)
|
||||
result = std::max(result, GetLineCharacterCount(i));
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void TextUnformattedColoredAt(const ImVec2 &pos, const ImU32 &color, const char *text) {
|
||||
ImGui::SetCursorScreenPos(pos);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text,color);
|
||||
@@ -913,7 +906,6 @@ void TextEditor::RenderText(const char *aTitle, const ImVec2 &lineNumbersStartPo
|
||||
float globalLineMax = mLines.size();
|
||||
auto lineMax = std::clamp(lineNo + mNumberOfLinesDisplayed, 0.0F, globalLineMax-1.0F);
|
||||
int totalDigitCount = std::floor(std::log10(globalLineMax)) + 1;
|
||||
mLongest = GetLongestLineLength() * mCharAdvance.x;
|
||||
|
||||
// Deduce mTextStart by evaluating mLines size (global lineMax) plus two spaces as text width
|
||||
char buf[16];
|
||||
@@ -1184,9 +1176,9 @@ void TextEditor::RenderText(const char *aTitle, const ImVec2 &lineNumbersStartPo
|
||||
ImGui::BeginChild(aTitle);
|
||||
|
||||
if (mShowLineNumbers)
|
||||
ImGui::Dummy(ImVec2(mLongest, (globalLineMax - lineMax - 2.0F) * mCharAdvance.y + ImGui::GetCurrentWindow()->InnerClipRect.GetHeight()));
|
||||
ImGui::Dummy(ImVec2(mLongestLineLength * mCharAdvance.x, (globalLineMax - lineMax - 2.0F) * mCharAdvance.y + ImGui::GetCurrentWindow()->InnerClipRect.GetHeight()));
|
||||
else
|
||||
ImGui::Dummy(ImVec2(mLongest, (globalLineMax - 1.0f - lineMax + GetPageSize() - 1.0f ) * mCharAdvance.y - 2 * ImGuiStyle().WindowPadding.y));
|
||||
ImGui::Dummy(ImVec2(mLongestLineLength * mCharAdvance.x, (globalLineMax - 1.0f - lineMax + GetPageSize() - 1.0f ) * mCharAdvance.y - 2 * ImGuiStyle().WindowPadding.y));
|
||||
|
||||
if (mScrollToCursor)
|
||||
EnsureCursorVisible();
|
||||
@@ -1247,8 +1239,7 @@ void TextEditor::Render(const char *aTitle, const ImVec2 &aSize, bool aBorder) {
|
||||
|
||||
ImVec2 textEditorSize = aSize;
|
||||
textEditorSize.x -= mLineNumberFieldWidth;
|
||||
mLongest = GetLongestLineLength() * mCharAdvance.x;
|
||||
bool scroll_x = mLongest > textEditorSize.x;
|
||||
bool scroll_x = mLongestLineLength * mCharAdvance.x > textEditorSize.x;
|
||||
bool scroll_y = mLines.size() > 1;
|
||||
if (!aBorder && scroll_y)
|
||||
textEditorSize.x -= scrollBarSize;
|
||||
|
||||
@@ -1846,6 +1846,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ContentRegistry::PatternLanguage::configureRuntime(*m_editorRuntime, nullptr);
|
||||
const auto &ast = m_editorRuntime->parseString(code, pl::api::Source::DefaultSource);
|
||||
m_textEditor.SetLongestLineLength(m_editorRuntime->getInternals().preprocessor.get()->getLongestLineLength());
|
||||
|
||||
auto &patternVariables = m_patternVariables.get(provider);
|
||||
auto oldPatternVariables = std::move(patternVariables);
|
||||
|
||||
Reference in New Issue
Block a user