Module layout

Source
Expand description

Fixed-capacity screen-space reservations around an aspect-fitted world.

All rectangles use absolute host logical pixels, including safe-area offsets; device pixel ratio belongs to the host. Draw HUD regions with a full-screen Viewport::responsive using zero insets to avoid applying the safe area twice. HUD text stays at its authored size. Only the world is scaled.

Reservations consume the current content rectangle in call order. An earlier top strip spans the full width; a later left strip starts below it. Reversing those calls assigns the corner to the left strip instead. Shared boundaries follow Rect::contains’s half-open convention.

use ferravex_play::ui::{HudEdge, HudRegions, Viewport};
// Reserve readable rows and a 44-pixel action target; keep a useful world area.
let screen = [390., 844.];
let mut hud = HudRegions::new(screen, [8., 24., 8., 16.], [160., 100.])?;
let header = hud.reserve("header", HudEdge::Top, 76.)?;
let actions = hud.reserve("actions", HudEdge::Bottom, 44.)?;
let footer = hud.reserve("footer", HudEdge::Bottom, 40.)?;
assert_eq!(hud.region("header"), Some(header));
assert_eq!(hud.content().min, [8., 100.]);
assert!(header.intersect(actions).is_none());
assert!(footer.intersect(hud.content()).is_none());
let ui = Viewport::responsive(screen, [0.; 4]).unwrap();
assert_eq!(ui.scale(), 1.); // No font scaling, including in portrait.
assert_eq!(ui.unproject(header.min), Some(header.min));

Structs§

CanvasFit
Pure adapter data for an existing ferravex_render::canvas::Canvas2D. This crate cannot depend on the renderer, which already depends on play.
HudRegion
One strip in reservation order. Names are borrowed static labels, never copied into allocated storage. Use the same rectangle for painting and hit testing.
HudRegions
An allocation-free, bounded HUD composition. Rebuild on resize with Self::new or reuse the current screen/safe area with Self::clear. There is no retained input, simulation, font, renderer or clock state.

Enums§

HudEdge
The edge of the remaining content from which a strip is taken.
HudLayoutError
Layout failure; no failed operation changes existing reservations.

Constants§

HUD_REGION_CAPACITY
Maximum number of named strips, including zero-thickness strips.