Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SpinBox will reset unsubmitted text when redrawing #81638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions scene/gui/spin_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Size2 SpinBox::get_minimum_size() const {
return ms;
}

void SpinBox::_update_text() {
void SpinBox::_update_text(bool p_keep_line_edit) {
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
if (is_localizing_numeral_system()) {
value = TS->format_number(value);
Expand All @@ -55,7 +55,12 @@ void SpinBox::_update_text() {
}
}

if (p_keep_line_edit && value == last_updated_text && value != line_edit->get_text()) {
return;
}

line_edit->set_text_with_selection(value);
last_updated_text = value;
}

void SpinBox::_text_submitted(const String &p_string) {
Expand Down Expand Up @@ -245,7 +250,7 @@ inline void SpinBox::_adjust_width_for_icon(const Ref<Texture2D> &icon) {
void SpinBox::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
_update_text();
_update_text(true);
_adjust_width_for_icon(theme_cache.updown_icon);

RID ci = get_canvas_item();
Expand Down
3 changes: 2 additions & 1 deletion scene/gui/spin_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class SpinBox : public Range {
void _range_click_timeout();
void _release_mouse();

void _update_text();
void _update_text(bool p_keep_line_edit = false);
void _text_submitted(const String &p_string);
void _text_changed(const String &p_string);

String prefix;
String suffix;
String last_updated_text;
double custom_arrow_step = 0.0;

void _line_edit_input(const Ref<InputEvent> &p_event);
Expand Down
Loading