mirror of https://github.com/godotengine/godot
Allow overriding SpinBox value on `focus_exited`
This commit is contained in:
parent
89001f91d2
commit
3c1ac98f37
|
|
@ -40,7 +40,7 @@ Size2 SpinBox::get_minimum_size() const {
|
||||||
return ms;
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpinBox::_update_text(bool p_keep_line_edit) {
|
void SpinBox::_update_text(bool p_only_update_if_value_changed) {
|
||||||
double step = get_step();
|
double step = get_step();
|
||||||
if (use_custom_arrow_step && custom_arrow_step != 0.0) {
|
if (use_custom_arrow_step && custom_arrow_step != 0.0) {
|
||||||
step = custom_arrow_step;
|
step = custom_arrow_step;
|
||||||
|
|
@ -50,6 +50,11 @@ void SpinBox::_update_text(bool p_keep_line_edit) {
|
||||||
value = TS->format_number(value);
|
value = TS->format_number(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_only_update_if_value_changed && value == last_text_value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
last_text_value = value;
|
||||||
|
|
||||||
if (!line_edit->is_editing()) {
|
if (!line_edit->is_editing()) {
|
||||||
if (!prefix.is_empty()) {
|
if (!prefix.is_empty()) {
|
||||||
value = prefix + " " + value;
|
value = prefix + " " + value;
|
||||||
|
|
@ -58,17 +63,12 @@ void SpinBox::_update_text(bool p_keep_line_edit) {
|
||||||
value += " " + suffix;
|
value += " " + suffix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
if (p_string.is_empty()) {
|
if (p_string.is_empty()) {
|
||||||
|
_update_text();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -288,14 +288,12 @@ void SpinBox::_line_edit_editing_toggled(bool p_toggled_on) {
|
||||||
line_edit->select_all();
|
line_edit->select_all();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Discontinue because the focus_exit was caused by canceling or the text is empty.
|
|
||||||
if (Input::get_singleton()->is_action_pressed("ui_cancel") || line_edit->get_text().is_empty()) {
|
if (Input::get_singleton()->is_action_pressed("ui_cancel") || line_edit->get_text().is_empty()) {
|
||||||
_update_text();
|
_update_text(); // Revert text if editing was canceled.
|
||||||
return;
|
} else {
|
||||||
|
_update_text(true); // Update text in case value was changed this frame (e.g. on `focus_exited`).
|
||||||
|
_text_submitted(line_edit->get_text());
|
||||||
}
|
}
|
||||||
|
|
||||||
line_edit->deselect();
|
|
||||||
_text_submitted(line_edit->get_text());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,13 +58,13 @@ class SpinBox : public Range {
|
||||||
void _range_click_timeout();
|
void _range_click_timeout();
|
||||||
void _release_mouse_from_drag_mode();
|
void _release_mouse_from_drag_mode();
|
||||||
|
|
||||||
void _update_text(bool p_keep_line_edit = false);
|
void _update_text(bool p_only_update_if_value_changed = 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;
|
String last_text_value;
|
||||||
double custom_arrow_step = 0.0;
|
double custom_arrow_step = 0.0;
|
||||||
bool use_custom_arrow_step = false;
|
bool use_custom_arrow_step = false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue