diff options
author | toger5 <toger5@hotmail.de> | 2018-05-21 21:36:43 +0200 |
---|---|---|
committer | toger5 <toger5@hotmail.de> | 2018-07-04 22:04:30 +0200 |
commit | 7363be2575f9eefdd465dc2c85024e0a52f4017a (patch) | |
tree | a22a3825fd6a826f7a4889723d72b63a6b000b57 | |
parent | 1706f636d7b4e48c20a9e93950533262d1e27e40 (diff) |
better tab support for property editor
-rw-r--r-- | editor/editor_spin_slider.cpp | 74 | ||||
-rw-r--r-- | editor/editor_spin_slider.h | 4 |
2 files changed, 54 insertions, 24 deletions
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 5c1c5da9bc..498671c4ab 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -70,13 +70,7 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos); update(); } else { - Rect2 gr = get_global_rect(); - value_input->set_text(get_text_value()); - value_input->set_position(gr.position); - value_input->set_size(gr.size); - value_input->call_deferred("show_modal"); - value_input->call_deferred("grab_focus"); - value_input->call_deferred("select_all"); + _focus_entered(); } grabbing_spinner = false; @@ -122,25 +116,10 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; if (k.is_valid() && k->is_pressed() && k->is_action("ui_accept")) { - Rect2 gr = get_global_rect(); - value_input->set_text(get_text_value()); - value_input->set_position(gr.position); - value_input->set_size(gr.size); - value_input->call_deferred("show_modal"); - value_input->call_deferred("grab_focus"); - value_input->call_deferred("select_all"); + _focus_entered(); } } -void EditorSpinSlider::_value_input_closed() { - set_value(value_input->get_text().to_double()); -} - -void EditorSpinSlider::_value_input_entered(const String &p_text) { - set_value(p_text.to_double()); - value_input->hide(); -} - void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; @@ -270,6 +249,12 @@ void EditorSpinSlider::_notification(int p_what) { mouse_over_spin = false; update(); } + if (p_what == NOTIFICATION_FOCUS_ENTER) { + if (!Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && !value_input_just_closed) { + _focus_entered(); + } + value_input_just_closed = false; + } } Size2 EditorSpinSlider::get_minimum_size() const { @@ -301,6 +286,34 @@ String EditorSpinSlider::get_label() const { return label; } +//text_entered signal +void EditorSpinSlider::_value_input_entered(const String &p_text) { + value_input_just_closed = true; + value_input->hide(); +} + +//modal_closed signal +void EditorSpinSlider::_value_input_closed() { + set_value(value_input->get_text().to_double()); + value_input_just_closed = true; +} + +//focus_exited signal +void EditorSpinSlider::_value_focus_exited() { + set_value(value_input->get_text().to_double()); + // focus is not on the same element after the vlalue_input was exited + // -> focus is on next element + // -> TAB was pressed + // -> modal_close was not called + // -> need to close/hide manually + if (!value_input_just_closed) { //value_input_just_closed should do the same + value_input->hide(); + //tab was pressed + } else { + //enter, click, esc + } +} + void EditorSpinSlider::_grabber_mouse_entered() { mouse_over_grabber = true; update(); @@ -321,6 +334,18 @@ bool EditorSpinSlider::is_read_only() const { return read_only; } +void EditorSpinSlider::_focus_entered() { + Rect2 gr = get_global_rect(); + value_input->set_text(get_text_value()); + value_input->set_position(gr.position); + value_input->set_size(gr.size); + value_input->call_deferred("show_modal"); + value_input->call_deferred("grab_focus"); + value_input->call_deferred("select_all"); + value_input->set_focus_next(find_next_valid_focus()->get_path()); + value_input->set_focus_previous(find_prev_valid_focus()->get_path()); +} + void EditorSpinSlider::_bind_methods() { ClassDB::bind_method(D_METHOD("set_label", "label"), &EditorSpinSlider::set_label); ClassDB::bind_method(D_METHOD("get_label"), &EditorSpinSlider::get_label); @@ -334,6 +359,7 @@ void EditorSpinSlider::_bind_methods() { ClassDB::bind_method(D_METHOD("_grabber_gui_input"), &EditorSpinSlider::_grabber_gui_input); ClassDB::bind_method(D_METHOD("_value_input_closed"), &EditorSpinSlider::_value_input_closed); ClassDB::bind_method(D_METHOD("_value_input_entered"), &EditorSpinSlider::_value_input_entered); + ClassDB::bind_method(D_METHOD("_value_focus_exited"), &EditorSpinSlider::_value_focus_exited); ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only"); @@ -365,6 +391,8 @@ EditorSpinSlider::EditorSpinSlider() { value_input->hide(); value_input->connect("modal_closed", this, "_value_input_closed"); value_input->connect("text_entered", this, "_value_input_entered"); + value_input->connect("focus_exited", this, "_value_focus_exited"); + value_input_just_closed = false; hide_slider = false; read_only = false; } diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h index 000024be60..5316c0264a 100644 --- a/editor/editor_spin_slider.h +++ b/editor/editor_spin_slider.h @@ -61,11 +61,12 @@ class EditorSpinSlider : public Range { Vector2 grabbing_spinner_mouse_pos; LineEdit *value_input; + bool value_input_just_closed; void _grabber_gui_input(const Ref<InputEvent> &p_event); void _value_input_closed(); void _value_input_entered(const String &); - + void _value_focus_exited(); bool hide_slider; protected: @@ -74,6 +75,7 @@ protected: static void _bind_methods(); void _grabber_mouse_entered(); void _grabber_mouse_exited(); + void _focus_entered(); public: String get_text_value() const; |