pub struct HudRegions { /* private fields */ }Expand description
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.
Implementations§
Source§impl HudRegions
impl HudRegions
Sourcepub fn new(
screen: [f32; 2],
insets: [f32; 4],
minimum_content: [f32; 2],
) -> Result<HudRegions, HudLayoutError>
pub fn new( screen: [f32; 2], insets: [f32; 4], minimum_content: [f32; 2], ) -> Result<HudRegions, HudLayoutError>
Create a layout in absolute logical screen coordinates. Insets are left,
top, right, bottom, with the same proportional collapse as
Viewport::responsive. Dimensions, insets and minimum_content must be
finite and nonnegative. Empty screens are valid when the minimum permits.
minimum_content is an authored size in screen units, independent of the
world’s design size. Insufficient space is explicit so callers can choose
a compact arrangement or omit secondary rows while retaining readable text.
Sourcepub fn content(&self) -> Rect
pub fn content(&self) -> Rect
Remaining world/content rectangle in absolute logical screen units.
Sourcepub fn regions(&self) -> &[HudRegion]
pub fn regions(&self) -> &[HudRegion]
Borrow the occupied slots in reservation order; no temporary allocation.
Sourcepub fn region(&self, name: &str) -> Option<Rect>
pub fn region(&self, name: &str) -> Option<Rect>
Look up a named rectangle. This accepts non-static queries as well.
Sourcepub fn reserve(
&mut self,
name: &'static str,
edge: HudEdge,
thickness: f32,
) -> Result<Rect, HudLayoutError>
pub fn reserve( &mut self, name: &'static str, edge: HudEdge, thickness: f32, ) -> Result<Rect, HudLayoutError>
Reserve a strip with the given thickness in logical screen units. Top/bottom consume height; left/right consume width. Repeated edges are allowed. A zero thickness creates an inert named strip and uses one slot.
Invalid requests, duplicate names, capacity and then available space are checked in that order. Every failure is atomic. Floating-point extents are rounded inward when necessary to keep rectangles disjoint; a positive thickness whose edge cannot be represented is rejected as invalid.
use ferravex_play::ui::{HudEdge, HudLayoutError, HudRegions};
let mut hud = HudRegions::new([320., 200.], [0.; 4], [160., 100.])?;
hud.reserve("header", HudEdge::Top, 60.)?;
let before = hud;
assert_eq!(hud.reserve("footer", HudEdge::Bottom, 44.),
Err(HudLayoutError::InsufficientSpace));
assert_eq!(hud, before);Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all reservations and restore the original safe area/minimum policy. Reuses the fixed storage, including after a failed reservation.
use ferravex_play::ui::{HudEdge, HudRegions};
let mut hud = HudRegions::new([640., 360.], [8.; 4], [160., 90.])?;
hud.reserve("header", HudEdge::Top, 44.)?;
hud.clear();
assert!(hud.regions().is_empty());
assert_eq!(hud.region("header"), None);
assert_eq!(hud.content(), hud.bounds());
hud.reserve("header", HudEdge::Top, 60.)?;Sourcepub fn fit_canvas(
&self,
design: [f32; 2],
) -> Result<Option<CanvasFit>, HudLayoutError>
pub fn fit_canvas( &self, design: [f32; 2], ) -> Result<Option<CanvasFit>, HudLayoutError>
Fit a positive, finite world design size into the remaining content.
Returns None when either content dimension is below one logical pixel;
callers must skip world rendering and pointer handling in that case.
An unrepresentable scale, camera zoom or displayed extent returns an error.
HUD reservations and fonts are never scaled by this operation.
use ferravex_play::ui::{HudEdge, HudRegions};
let mut hud = HudRegions::new([800., 600.], [10., 20., 30., 40.], [0.; 2])?;
hud.reserve("header", HudEdge::Top, 60.)?;
let fit = hud.fit_canvas([400., 200.])?.unwrap();
let world = fit.viewport();
assert_eq!(world.scale(), 1.9);
assert_eq!(world.pixels().min, [10., 130.]);
assert_eq!(world.unproject([390., 320.]), Some([200., 100.]));
assert_eq!(world.unproject([40., 40.]), None); // Header is not world input.
assert_eq!(fit.screen(), [800., 600.]);
assert!((fit.camera_offset()[0] + 0.025).abs() < 0.00001);
assert!((fit.camera_offset()[1] + 1. / 15.).abs() < 0.00001);Trait Implementations§
Source§impl Clone for HudRegions
impl Clone for HudRegions
Source§fn clone(&self) -> HudRegions
fn clone(&self) -> HudRegions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more