From b4e4f88cd952b2ded259b7ab9abf3e3f0040050f Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Sat, 4 Jun 2022 01:21:15 -0300 Subject: [PATCH] Fix specific bug related to submenus in `PopupMenu` --- scene/gui/popup_menu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 888b6145042..f7492876128 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -167,6 +167,7 @@ void PopupMenu::_activate_submenu(int over) { pm->set_position(pos); pm->set_scale(get_global_transform().get_scale()); + pm->popup(); PopupMenu *pum = Object::cast_to(pm); if (pum) { @@ -175,6 +176,7 @@ void PopupMenu::_activate_submenu(int over) { pum->set_current_index(0); } + // Setting autohide areas *must* be done after `popup()` which can move the popup (to fit it into the viewport). pr.position -= pum->get_global_position(); pum->clear_autohide_areas(); pum->add_autohide_area(Rect2(pr.position.x, pr.position.y, pr.size.x, items[over]._ofs_cache)); @@ -183,8 +185,6 @@ void PopupMenu::_activate_submenu(int over) { pum->add_autohide_area(Rect2(pr.position.x, pr.position.y + from, pr.size.x, pr.size.y - from)); } } - - pm->popup(); } void PopupMenu::_submenu_timeout() {