textbox:paste(...) scroll fix
This commit is contained in:
@@ -132,7 +132,10 @@ void TextBox::drawBackground(const DrawContext* pctx, Assets*) {
|
|||||||
line++;
|
line++;
|
||||||
} while (line < label->getLinesNumber() && label->isFakeLine(line));
|
} while (line < label->getLinesNumber() && label->isFakeLine(line));
|
||||||
}
|
}
|
||||||
|
refreshLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextBox::refreshLabel() {
|
||||||
label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f));
|
label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f));
|
||||||
label->setText(getText());
|
label->setText(getText());
|
||||||
if (multiline && font) {
|
if (multiline && font) {
|
||||||
@@ -157,9 +160,7 @@ void TextBox::paste(const std::wstring& text) {
|
|||||||
input = left + text + right;
|
input = left + text + right;
|
||||||
}
|
}
|
||||||
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
|
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
|
||||||
// refresh label lines configuration for correct setCaret work
|
refreshLabel();
|
||||||
label->setText(input);
|
|
||||||
|
|
||||||
setCaret(caret + text.length());
|
setCaret(caret + text.length());
|
||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
@@ -600,7 +601,7 @@ uint TextBox::getCaret() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::setCaret(uint position) {
|
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();
|
caretLastMove = Window::time();
|
||||||
|
|
||||||
int width = label->getSize().x;
|
int width = label->getSize().x;
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ namespace gui {
|
|||||||
void resetMaxLocalCaret();
|
void resetMaxLocalCaret();
|
||||||
|
|
||||||
void performEditingKeyboardEvents(keycode key);
|
void performEditingKeyboardEvents(keycode key);
|
||||||
|
|
||||||
|
void refreshLabel();
|
||||||
public:
|
public:
|
||||||
TextBox(
|
TextBox(
|
||||||
std::wstring placeholder,
|
std::wstring placeholder,
|
||||||
|
|||||||
Reference in New Issue
Block a user