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() {