diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2022-08-23 10:38:51 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2022-08-23 10:38:51 +0300 |
commit | cd095ab64ad492ef0a775c3ef5b8fa2aa8d0edd5 (patch) | |
tree | 4c316343593fabe99c08902d197a1dd91e0dc161 /scene/gui | |
parent | b9919fd87dbac180f2d3ade766a8d074d4224dfe (diff) |
Hide MenuButton / OptionButton popup on click if it's already visible.
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/menu_button.cpp | 11 | ||||
-rw-r--r-- | scene/gui/option_button.cpp | 5 |
2 files changed, 11 insertions, 5 deletions
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 0252f25888..aed92302cb 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -86,6 +86,11 @@ void MenuButton::_popup_visibility_changed(bool p_visible) { } void MenuButton::pressed() { + if (popup->is_visible()) { + popup->hide(); + return; + } + emit_signal(SNAME("about_to_popup")); Size2 size = get_size() * get_viewport()->get_canvas_transform().get_scale(); @@ -105,11 +110,7 @@ void MenuButton::pressed() { popup->set_current_index(0); } - if (popup->is_visible()) { - popup->hide(); - } else { - popup->popup(); - } + popup->popup(); } void MenuButton::gui_input(const Ref<InputEvent> &p_event) { diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index a5a6240e27..9adc7fb4e9 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -198,6 +198,11 @@ void OptionButton::_selected(int p_which) { } void OptionButton::pressed() { + if (popup->is_visible()) { + popup->hide(); + return; + } + Size2 size = get_size() * get_viewport()->get_canvas_transform().get_scale(); popup->set_position(get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y)); popup->set_size(Size2(size.width, 0)); |