Popup menu and pickers doesn't capture the input used to close it
One can close popup menus and, e.g., the colour picker by clicking outside of it or hitting escape. Unfortunately, these inputs are not captured and thus potentially have an unwanted secondary effect.
In the case of rerun, escape will have the effect of deselecting whatever is currently selected, and the click will be processed by whatever happens to be under the mouse cursor (often, the view, which again leads to deselection).
https://github.com/user-attachments/assets/d3cbd005-2132-4c2c-af4c-52daba8a7308
This is by design (though arguably not good design). The thinking (within egui) is: pressing escape should escape everything. Otherwise what it escapes would depend on the order of which the UI is laid out, which is not obvious to a user ("why did A close instead of B?").
What is the "correct" way to opt-out of a popup menu then?
Otherwise what it escapes would depend on the order of which the UI is laid out, which is not obvious to a user ("why did A close instead of B?").
Perhaps naively, I'm expecting popup-menu/picker to be modal, so (1) they may not have sibling areas—only parent, over which they have precedence and (2) they may have zero or one "child" modal (e.g. a sub-menu), which would have precedence. In this model, it feels quite natural in how keystroke would be captured. Surely I'm missing dozen of edge cases and assorted implementation trickeries here, though.
pressing escape should escape everything.
My mental model doesn't conform to that. If have a stack of "modal things" open, I'm expecting to get out of it by hitting escape as many times as the number of modal things that are opened.
Related:
- https://github.com/emilk/egui/issues/2549 (in this case, the opt-out behaviour is natural: just release the click outside of the menu).
- https://github.com/emilk/egui/issues/3718
Switching all i.key_pressed(Key::Escape) to use consume_key instead might be the right solution, we just need to be careful to do it in the right place so that:
- Pressing escape closes all
Menu:s (not just the innermost submenu) - Pressing escape closes the innermost popup (if nested)
- …?
Pressing escape closes all Menu:s (not just the innermost submenu)
Debatable :)
Personally I'd rather have to ESC twice when I want full out than having no way to opt-out of a single level of sub-menu.
Counter argument: macOS closes all layers of menu on ESC.
In my popups / modals I show a second area right below the popup area that covers the entire screen and "catches" any clicks outside of the popup, which seems to work really well. I also use this to slightly darken everything in the background but that is of course optional.
I'm not sure if this is tracking the same issue, but in my hex editor, I have this color picker nested in a menu, and it would be nice if it didn't close when I interact with it. It doesn't seem to close if the underlying layers don't care about the input (like middle click), so I have this funny label for it.
Let's test if this is still an issue after the recent Popup changes
My issue I commented about has been fixed after I reimplemented it using the new popup system.