refactor(engine): name HUD popover Z-layers; replace raw arithmetic (M-24)
ZIndex(Z_HUD + 4) and ZIndex(Z_HUD + 5) across four sites in hud_plugin.rs were magic-number expressions. Define named constants in ui_theme: Z_HUD_POPOVER_BACKDROP = Z_HUD + 4 (fullscreen dismiss backdrop) Z_HUD_POPOVER = Z_HUD + 5 (popover panel) The score-delta floater (Z_HUD + 10) now uses the existing Z_HUD_TOP constant, whose doc is updated to mention transient annotations. Both new constants are added to the monotonic z-hierarchy test. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -371,6 +371,9 @@ pub enum MenuOption {
|
||||
/// Mirrors `ui_theme::Z_HUD` and is duplicated here only so the hud module
|
||||
/// can use it as a `const` without a non-const expression in `ZIndex(...)`.
|
||||
const Z_HUD: i32 = crate::ui_theme::Z_HUD;
|
||||
const Z_HUD_POPOVER_BACKDROP: i32 = crate::ui_theme::Z_HUD_POPOVER_BACKDROP;
|
||||
const Z_HUD_POPOVER: i32 = crate::ui_theme::Z_HUD_POPOVER;
|
||||
const Z_HUD_TOP: i32 = crate::ui_theme::Z_HUD_TOP;
|
||||
|
||||
/// Idle / hover / pressed colours shared by every action button. Aliased
|
||||
/// to the theme tokens so the HUD picks up palette changes for free.
|
||||
@@ -1184,7 +1187,7 @@ fn spawn_modes_popover(
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(BG_ELEVATED),
|
||||
ZIndex(Z_HUD + 5),
|
||||
ZIndex(Z_HUD_POPOVER),
|
||||
))
|
||||
.with_children(|panel| {
|
||||
for (option, label, tooltip) in rows {
|
||||
@@ -1211,8 +1214,8 @@ fn spawn_modes_popover(
|
||||
}
|
||||
});
|
||||
|
||||
// Fullscreen transparent backdrop at Z_HUD+4 (below the popover at
|
||||
// Z_HUD+5) so tapping outside the panel light-dismisses it.
|
||||
// Fullscreen transparent backdrop at Z_HUD_POPOVER_BACKDROP (below the
|
||||
// popover at Z_HUD_POPOVER) so tapping outside light-dismisses it.
|
||||
commands.spawn((
|
||||
ModesPopoverBackdrop,
|
||||
Button,
|
||||
@@ -1225,7 +1228,7 @@ fn spawn_modes_popover(
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(Color::NONE),
|
||||
ZIndex(Z_HUD + 4),
|
||||
ZIndex(Z_HUD_POPOVER_BACKDROP),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1382,7 +1385,7 @@ fn spawn_menu_popover(commands: &mut Commands, font_res: Option<&FontResource>)
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(BG_ELEVATED),
|
||||
ZIndex(Z_HUD + 5),
|
||||
ZIndex(Z_HUD_POPOVER),
|
||||
))
|
||||
.with_children(|panel| {
|
||||
for (option, label, tooltip) in rows {
|
||||
@@ -1423,7 +1426,7 @@ fn spawn_menu_popover(commands: &mut Commands, font_res: Option<&FontResource>)
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(Color::NONE),
|
||||
ZIndex(Z_HUD + 4),
|
||||
ZIndex(Z_HUD_POPOVER_BACKDROP),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1797,7 +1800,7 @@ fn detect_score_change(
|
||||
top: Val::Px(0.0),
|
||||
..default()
|
||||
},
|
||||
ZIndex(Z_HUD + 10),
|
||||
ZIndex(Z_HUD_TOP),
|
||||
Text::new(format!("+{delta}")),
|
||||
font,
|
||||
TextColor(ACCENT_PRIMARY),
|
||||
|
||||
@@ -401,8 +401,13 @@ pub const Z_BACKGROUND: i32 = -10;
|
||||
pub const Z_PILE_MARKER: i32 = -1;
|
||||
/// Base layer for HUD readouts (top-left).
|
||||
pub const Z_HUD: i32 = 50;
|
||||
/// Action bar + popovers — above HUD readouts so dropdowns can overlap.
|
||||
pub const Z_HUD_TOP: i32 = 60;
|
||||
/// Fullscreen transparent dismiss-backdrop spawned behind a HUD popover so
|
||||
/// tapping outside it light-dismisses the panel without blocking other input.
|
||||
pub const Z_HUD_POPOVER_BACKDROP: i32 = Z_HUD + 4;
|
||||
/// HUD popovers (Modes dropdown, etc.) — above the dismiss backdrop.
|
||||
pub const Z_HUD_POPOVER: i32 = Z_HUD + 5;
|
||||
/// Transient HUD annotations (score-delta floaters) — above popovers.
|
||||
pub const Z_HUD_TOP: i32 = Z_HUD + 10;
|
||||
pub const Z_MODAL_SCRIM: i32 = 200;
|
||||
pub const Z_MODAL_PANEL: i32 = 210;
|
||||
/// Pause overlay outranks normal modals — pausing should always be on top.
|
||||
@@ -648,6 +653,8 @@ mod tests {
|
||||
Z_BACKGROUND,
|
||||
Z_PILE_MARKER,
|
||||
Z_HUD,
|
||||
Z_HUD_POPOVER_BACKDROP,
|
||||
Z_HUD_POPOVER,
|
||||
Z_HUD_TOP,
|
||||
Z_MODAL_SCRIM,
|
||||
Z_MODAL_PANEL,
|
||||
|
||||
Reference in New Issue
Block a user