pub fn close_dialogs_on_escape(
keys: MessageReader<'_, '_, KeyPressed>,
press_cancel: Option<Res<'_, EscapePressCancel>>,
store: ResMut<'_, PropertyStore>,
blocks: Query<'_, '_, (&IfMarker, Option<&Visible>, Option<&DialogMarker>)>,
)Expand description
On Escape, close the top-most open popup layer - one press peels off exactly one layer.
Priority mirrors paint order (later-painted popups sit on top):
- an open
<dropdown>panel (__dropdown_open:*signal istrue), - otherwise an open
<menu>panel (__menu_open:*signal istrue), - otherwise the top-most open
<dialog>.
Dropdown / menu panels are gated by <if eq="true" mode="hide">
blocks whose IfMarker::signal_name is the synthetic open signal,
so the same IfMarker query that drives dialogs finds them too -
no dependency on the panel’s runtime marker components (which the
<if>-body template path does not propagate). Closing writes the
open signal to false (dropdown / menu) or "" (dialog); the next
reconcile_if_blocks tick flips Visible(false) on the subtree
(IfMode::Hide preserves child state across the toggle).
Bare Esc keypresses with nothing open pass through untouched.
An Escape that cancelled an in-flight press
(lumen_input::cancel_press_on_escape sets
EscapePressCancel earlier
in the Input stage) is consumed by the cancel - the dialog stays
open on that keystroke.