Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide MenuButton / OptionButton popup on click if it's already visible. #64768

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions editor/editor_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 6 additions & 5 deletions scene/gui/menu_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions scene/gui/option_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down