Fix specific bug related to submenus in PopupMenu

This commit is contained in:
Michael Alexsander 2022-06-04 01:21:15 -03:00
parent a6b27b526f
commit b4e4f88cd9

View file

@ -167,6 +167,7 @@ void PopupMenu::_activate_submenu(int over) {
pm->set_position(pos); pm->set_position(pos);
pm->set_scale(get_global_transform().get_scale()); pm->set_scale(get_global_transform().get_scale());
pm->popup();
PopupMenu *pum = Object::cast_to<PopupMenu>(pm); PopupMenu *pum = Object::cast_to<PopupMenu>(pm);
if (pum) { if (pum) {
@ -175,6 +176,7 @@ void PopupMenu::_activate_submenu(int over) {
pum->set_current_index(0); 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(); pr.position -= pum->get_global_position();
pum->clear_autohide_areas(); pum->clear_autohide_areas();
pum->add_autohide_area(Rect2(pr.position.x, pr.position.y, pr.size.x, items[over]._ofs_cache)); 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)); 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() { void PopupMenu::_submenu_timeout() {