From cd095ab64ad492ef0a775c3ef5b8fa2aa8d0edd5 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 23 Aug 2022 10:38:51 +0300 Subject: [PATCH] Hide MenuButton / OptionButton popup on click if it's already visible. --- editor/editor_path.cpp | 5 +++++ scene/gui/menu_button.cpp | 11 ++++++----- scene/gui/option_button.cpp | 5 +++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp index 87ebd3e1c1d..adbfacd1311 100644 --- a/editor/editor_path.cpp +++ b/editor/editor_path.cpp @@ -80,6 +80,11 @@ void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) { } void EditorPath::_show_popup() { + if (sub_objects_menu->is_visible()) { + sub_objects_menu->hide(); + return; + } + sub_objects_menu->clear(); Size2 size = get_size(); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 0252f25888c..aed92302cba 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 &p_event) { diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index a5a6240e27c..9adc7fb4e97 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));