Merge pull request #81638 from jsjtxietian/fix-spinBox-reset-text-when-redraw

Fix SpinBox will reset unsubmited text when redrawing
This commit is contained in:
Rémi Verschelde 2023-10-18 16:54:32 +02:00
commit 680b59954b
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 9 additions and 3 deletions

View File

@ -40,7 +40,7 @@ Size2 SpinBox::get_minimum_size() const {
return ms; 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())); String value = String::num(get_value(), Math::range_step_decimals(get_step()));
if (is_localizing_numeral_system()) { if (is_localizing_numeral_system()) {
value = TS->format_number(value); value = TS->format_number(value);
@ -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); line_edit->set_text_with_selection(value);
last_updated_text = value;
} }
void SpinBox::_text_submitted(const String &p_string) { void SpinBox::_text_submitted(const String &p_string) {
@ -245,7 +250,7 @@ inline void SpinBox::_adjust_width_for_icon(const Ref<Texture2D> &icon) {
void SpinBox::_notification(int p_what) { void SpinBox::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_DRAW: { case NOTIFICATION_DRAW: {
_update_text(); _update_text(true);
_adjust_width_for_icon(theme_cache.updown_icon); _adjust_width_for_icon(theme_cache.updown_icon);
RID ci = get_canvas_item(); RID ci = get_canvas_item();

View File

@ -46,12 +46,13 @@ class SpinBox : public Range {
void _range_click_timeout(); void _range_click_timeout();
void _release_mouse(); void _release_mouse();
void _update_text(); void _update_text(bool p_keep_line_edit = false);
void _text_submitted(const String &p_string); void _text_submitted(const String &p_string);
void _text_changed(const String &p_string); void _text_changed(const String &p_string);
String prefix; String prefix;
String suffix; String suffix;
String last_updated_text;
double custom_arrow_step = 0.0; double custom_arrow_step = 0.0;
void _line_edit_input(const Ref<InputEvent> &p_event); void _line_edit_input(const Ref<InputEvent> &p_event);