From 99c66c61bb4da0b8defc7aa3219088de32ae4fab Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 29 Apr 2026 21:53:54 +0300 Subject: [PATCH] fix multiline textbox wrappping --- src/graphics/ui/elements/Label.cpp | 17 +++++++++-------- src/graphics/ui/elements/TextBox.cpp | 6 +++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/graphics/ui/elements/Label.cpp b/src/graphics/ui/elements/Label.cpp index 9387e91c5..14cbeea2d 100644 --- a/src/graphics/ui/elements/Label.cpp +++ b/src/graphics/ui/elements/Label.cpp @@ -48,17 +48,18 @@ void LabelCache::update(std::wstring_view text, bool multiline, bool wrap) { } if (multiline) { - size_t len = 0; - for (size_t i = 0; i < text.length(); i++, len++) { + size_t lineStart = 0; + for (size_t i = 0; i < text.length(); i++) { if (text[i] == L'\n') { - lines.push_back(LineScheme {i+1, false}); - len = 0; - } else if (i > 0 && i+1 < text.length() && wrap && text[i+1] != L'\n') { - size_t width = metrics.calcWidth(text, i-len-1, i-(i-len)+2); + lines.push_back(LineScheme {i + 1, false}); + lineStart = i + 1; + } else if (i + 1 < text.length() && wrap && text[i + 1] != L'\n') { + size_t width = + metrics.calcWidth(text, lineStart, i - lineStart + 2); if (width >= wrapWidth) { // starting a fake line - lines.push_back(LineScheme {i+1, true}); - len = 0; + lines.push_back(LineScheme {i + 1, true}); + lineStart = i + 1; } } } diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index f93ae3b95..1daab49c5 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -646,7 +646,11 @@ void TextBox::reposition() { void TextBox::refresh() { Container::refresh(); label->setSize( - size - glm::vec2(padding.z + padding.x, padding.w + padding.y) + size - glm::vec2( + padding.z + padding.x + + LINE_NUMBERS_PANE_WIDTH * showLineNumbers + textOffset, + padding.w + padding.y + ) ); label->setPos(glm::vec2( padding.x + LINE_NUMBERS_PANE_WIDTH * showLineNumbers + textInitX -