diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-08-26 13:39:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-26 13:39:14 +0200 |
commit | 0c639428dd4e4d92a6211c3bb4d04c3af1a4d266 (patch) | |
tree | 5bc431a79d447c6231445c5a44891cce76887980 /scene | |
parent | dc4193b478dec409132bf50d90fdb4c6760a109a (diff) | |
parent | da0c4221f0b8a26daadf5684ef62635661d4d52e (diff) |
Merge pull request #64529 from KoBeWi/suffix_begone
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/spin_box.cpp | 23 | ||||
-rw-r--r-- | scene/gui/spin_box.h | 1 |
2 files changed, 18 insertions, 6 deletions
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 517c83545c..0ac4d9d8ce 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -41,12 +41,16 @@ Size2 SpinBox::get_minimum_size() const { void SpinBox::_value_changed(double p_value) { String value = TS->format_number(String::num(get_value(), Math::range_step_decimals(get_step()))); - if (!prefix.is_empty()) { - value = prefix + " " + value; - } - if (!suffix.is_empty()) { - value += " " + suffix; + + if (!line_edit->has_focus()) { + if (!prefix.is_empty()) { + value = prefix + " " + value; + } + if (!suffix.is_empty()) { + value += " " + suffix; + } } + line_edit->set_text(value); Range::_value_changed(p_value); } @@ -181,8 +185,14 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) { } } +void SpinBox::_line_edit_focus_enter() { + int col = line_edit->get_caret_column(); + _value_changed(0); // Update the LineEdit's text. + line_edit->set_caret_column(col); +} + void SpinBox::_line_edit_focus_exit() { - // discontinue because the focus_exit was caused by right-click context menu + // Discontinue because the focus_exit was caused by right-click context menu. if (line_edit->is_menu_visible()) { return; } @@ -346,6 +356,7 @@ SpinBox::SpinBox() { line_edit->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); line_edit->connect("text_submitted", callable_mp(this, &SpinBox::_text_submitted), CONNECT_DEFERRED); + line_edit->connect("focus_entered", callable_mp(this, &SpinBox::_line_edit_focus_enter), CONNECT_DEFERRED); line_edit->connect("focus_exited", callable_mp(this, &SpinBox::_line_edit_focus_exit), CONNECT_DEFERRED); line_edit->connect("gui_input", callable_mp(this, &SpinBox::_line_edit_input)); diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h index 0aae9efe78..3fcb85ac99 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -64,6 +64,7 @@ class SpinBox : public Range { double diff_y = 0.0; } drag; + void _line_edit_focus_enter(); void _line_edit_focus_exit(); inline void _adjust_width_for_icon(const Ref<Texture2D> &icon); |