|
@@ -40,12 +40,16 @@ Size2 SpinBox::get_minimum_size() const {
|
|
|
|
|
|
void SpinBox::_value_changed(double) {
|
|
|
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
|
|
|
- if (prefix != "") {
|
|
|
- value = prefix + " " + value;
|
|
|
- }
|
|
|
- if (suffix != "") {
|
|
|
- value += " " + suffix;
|
|
|
+
|
|
|
+ if (!line_edit->has_focus()) {
|
|
|
+ if (prefix != "") {
|
|
|
+ value = prefix + " " + value;
|
|
|
+ }
|
|
|
+ if (suffix != "") {
|
|
|
+ value += " " + suffix;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
line_edit->set_text(value);
|
|
|
}
|
|
|
|
|
@@ -161,6 +165,12 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void SpinBox::_line_edit_focus_enter() {
|
|
|
+ int col = line_edit->get_cursor_position();
|
|
|
+ _value_changed(0); // Update the LineEdit's text.
|
|
|
+ line_edit->set_cursor_position(col);
|
|
|
+}
|
|
|
+
|
|
|
void SpinBox::_line_edit_focus_exit() {
|
|
|
// discontinue because the focus_exit was caused by right-click context menu
|
|
|
if (line_edit->get_menu()->is_visible()) {
|
|
@@ -253,6 +263,7 @@ void SpinBox::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_editable", "editable"), &SpinBox::set_editable);
|
|
|
ClassDB::bind_method(D_METHOD("is_editable"), &SpinBox::is_editable);
|
|
|
ClassDB::bind_method(D_METHOD("apply"), &SpinBox::apply);
|
|
|
+ ClassDB::bind_method(D_METHOD("_line_edit_focus_enter"), &SpinBox::_line_edit_focus_enter);
|
|
|
ClassDB::bind_method(D_METHOD("_line_edit_focus_exit"), &SpinBox::_line_edit_focus_exit);
|
|
|
ClassDB::bind_method(D_METHOD("get_line_edit"), &SpinBox::get_line_edit);
|
|
|
ClassDB::bind_method(D_METHOD("_line_edit_input"), &SpinBox::_line_edit_input);
|
|
@@ -273,6 +284,7 @@ SpinBox::SpinBox() {
|
|
|
line_edit->set_mouse_filter(MOUSE_FILTER_PASS);
|
|
|
//connect("value_changed",this,"_value_changed");
|
|
|
line_edit->connect("text_entered", this, "_text_entered", Vector<Variant>(), CONNECT_DEFERRED);
|
|
|
+ line_edit->connect("focus_entered", this, "_line_edit_focus_enter", Vector<Variant>(), CONNECT_DEFERRED);
|
|
|
line_edit->connect("focus_exited", this, "_line_edit_focus_exit", Vector<Variant>(), CONNECT_DEFERRED);
|
|
|
line_edit->connect("gui_input", this, "_line_edit_input");
|
|
|
|