Commit 6f60e63
committed
menu: wire parent_menu at build time and fix ESC dismiss
Three related fixes for submenu dismiss behavior in PopupMenu:
1. Wire parent_menu in PopupMenu::build (one-shot at construction).
Submenus added via PopupMenuItem::submenu(label, entity) — the data
constructor — can't reach the parent's entity at build time, so they
land with parent_menu = None. After the user closure populates the
menu, iterate menu_items once and wire any orphan submenus to point
at the menu being built. Zero per-frame cost, handles arbitrary
nesting because every submenu also goes through PopupMenu::build.
This was previously done in Render::render which iterated and
notified every frame — replaced with the one-shot approach.
2. Fix ESC not closing menus when a submenu is open. When a submenu is
opened by hover, the parent menu retains focus. Pressing ESC hit the
parent's dismiss(), which bailed out early because active_submenu()
was Some. Split dismiss into dismiss (Cancel handler — clears the
active submenu first) and dismiss_menu (internal — propagates up the
chain).
3. Guard handle_dismiss for submenu clicks. handle_dismiss
(click-outside) now returns early if a submenu is active. Without
this, clicking a submenu item triggers the parent's
on_mouse_down_out, tearing down the submenu before the item's
on_click fires.
Fixes #22291 parent 9e252d8 commit 6f60e63
1 file changed
Lines changed: 39 additions & 8 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
325 | 342 | | |
326 | 343 | | |
327 | 344 | | |
| |||
753 | 770 | | |
754 | 771 | | |
755 | 772 | | |
756 | | - | |
| 773 | + | |
757 | 774 | | |
758 | 775 | | |
759 | 776 | | |
| |||
763 | 780 | | |
764 | 781 | | |
765 | 782 | | |
766 | | - | |
| 783 | + | |
767 | 784 | | |
768 | 785 | | |
769 | 786 | | |
| |||
932 | 949 | | |
933 | 950 | | |
934 | 951 | | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
935 | 955 | | |
936 | | - | |
937 | | - | |
938 | | - | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
939 | 959 | | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
940 | 963 | | |
941 | 964 | | |
942 | 965 | | |
| |||
951 | 974 | | |
952 | 975 | | |
953 | 976 | | |
954 | | - | |
| 977 | + | |
955 | 978 | | |
956 | 979 | | |
957 | 980 | | |
| |||
970 | 993 | | |
971 | 994 | | |
972 | 995 | | |
973 | | - | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
974 | 1005 | | |
975 | 1006 | | |
976 | 1007 | | |
| |||
0 commit comments