textbox:paste(...) scroll fix

This commit is contained in:
MihailRis 2024-05-16 09:58:47 +03:00
parent 46e9c7dbec
commit 2bb6ad523e
2 changed files with 7 additions and 4 deletions

View File

@ -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<size_t>(position), input.length());
caretLastMove = Window::time();
int width = label->getSize().x;

View File

@ -62,6 +62,8 @@ namespace gui {
void resetMaxLocalCaret();
void performEditingKeyboardEvents(keycode key);
void refreshLabel();
public:
TextBox(
std::wstring placeholder,