From 2bb6ad523e2f37b1a3cddbc0bc9614c9a6a107b5 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 16 May 2024 09:58:47 +0300 Subject: [PATCH] textbox:paste(...) scroll fix --- src/graphics/ui/elements/TextBox.cpp | 9 +++++---- src/graphics/ui/elements/TextBox.hpp | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index 97cfa159..cf32a1b8 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -132,7 +132,10 @@ void TextBox::drawBackground(const DrawContext* pctx, Assets*) { line++; } while (line < label->getLinesNumber() && label->isFakeLine(line)); } + refreshLabel(); +} +void TextBox::refreshLabel() { label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f)); label->setText(getText()); if (multiline && font) { @@ -157,9 +160,7 @@ void TextBox::paste(const std::wstring& text) { input = left + text + right; } input.erase(std::remove(input.begin(), input.end(), '\r'), input.end()); - // refresh label lines configuration for correct setCaret work - label->setText(input); - + refreshLabel(); setCaret(caret + text.length()); validate(); } @@ -600,7 +601,7 @@ uint TextBox::getCaret() const { } void TextBox::setCaret(uint position) { - this->caret = std::min(size_t(position), input.length()); + this->caret = std::min(static_cast(position), input.length()); caretLastMove = Window::time(); int width = label->getSize().x; diff --git a/src/graphics/ui/elements/TextBox.hpp b/src/graphics/ui/elements/TextBox.hpp index f8fa6a7f..8ca85bbc 100644 --- a/src/graphics/ui/elements/TextBox.hpp +++ b/src/graphics/ui/elements/TextBox.hpp @@ -62,6 +62,8 @@ namespace gui { void resetMaxLocalCaret(); void performEditingKeyboardEvents(keycode key); + + void refreshLabel(); public: TextBox( std::wstring placeholder,