minor refactor

This commit is contained in:
MihailRis 2024-02-22 23:53:41 +03:00
parent 636ea2666f
commit 9c31c6c8b7
2 changed files with 15 additions and 4 deletions

View File

@ -514,10 +514,7 @@ void TextBox::keyPressed(int key) {
// Select/deselect all
if (key == keycode::A) {
if (selectionStart == selectionEnd) {
selectionStart = 0;
selectionEnd = input.length();
selectionOrigin = 0;
setCaret(selectionEnd);
select(0, input.length());
} else {
resetSelection();
}
@ -525,6 +522,19 @@ void TextBox::keyPressed(int key) {
}
}
void TextBox::select(int start, int end) {
if (end < start) {
std::swap(start, end);
}
start = normalizeIndex(start);
end = normalizeIndex(end);
selectionStart = start;
selectionEnd = end;
selectionOrigin = start;
setCaret(selectionEnd);
}
std::shared_ptr<UINode> TextBox::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
return UINode::getAt(pos, self);
}

View File

@ -157,6 +157,7 @@ namespace gui {
virtual std::wstring getSelection() const;
virtual uint getCaret() const;
virtual void setCaret(uint position);
virtual void select(int start, int end);
virtual bool validate();
virtual void setValid(bool valid);
virtual bool isValid() const;