Expand description
Renderer-independent anchored rectangles, clipped hit testing, pointer capture, and keyboard focus. Rendering and accessibility adapters remain host concerns.
For a HUD that keeps readable pixel-sized text when resized, use
Viewport::responsive, Anchor::place and hud_slots. These helpers
return geometry/borrowed text without allocating; reuse UiState each frame.
Use UiState::focus_direction for spatial arrow/gamepad navigation, and
UiState::focus_next for submission-order tab navigation.
HudRegions reserves screen-space strips before fitting a world canvas.
Modules§
- flow
- Bounded, content-sized horizontal rows with optional wrapping.
- layout
- Fixed-capacity screen-space reservations around an aspect-fitted world.
- meters
- Bounded horizontal meter geometry in logical UI units, without rendering, clocks, input, smoothing, allocation or gameplay availability decisions.
- minimap
- Checked, allocation-free projection of caller-authorized planar points.
- notices
- Bounded transient text/semantic notices, driven by accepted game events.
- scroll
- Allocation-free vertical scrolling in logical UI units, positive Y down.
- theme
- Opt-in, caller-owned UI tokens in logical screen pixels, before viewport/DPR projection. No game palette, renderer default, global state, input, motion or flash preference is changed. Rebuild measured layout and share its rectangles with paint/hits after changing tokens; wrap, scroll or report overflow rather than reducing essential text. A fitted viewport can still scale these units; use a responsive viewport when readable pixel-sized UI is intended.
Structs§
- Anchors
- Canvas
Fit - Pure adapter data for an existing
ferravex_render::canvas::Canvas2D. This crate cannot depend on the renderer, which already depends on play. - Fitted
Label - A borrowed, single-line prefix and static ASCII ellipsis. Draw the two pieces
consecutively at the original font size; no temporary
Stringis needed. - 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::newor reuse the current screen/safe area withSelf::clear. There is no retained input, simulation, font, renderer or clock state. - Rect
- UiState
- Viewport
- Logical UI units mapped into a safe-area-aware pixel viewport.
Self::fitletterboxes a design canvas;Self::responsivekeeps one logical unit per host logical pixel and lets layout reflow. - Widget
Enums§
- Anchor
- Placement within a parent; oversized requests shrink to its available extent.
Unlike stretched
Anchors, this keeps a fixed HUD size whenever it fits. - Focus
Direction - Spatial navigation in logical UI coordinates; positive Y points down.
See
UiState::focus_directionfor a complete example. - Focus
Wrap - Edge behavior for
UiState::focus_direction, chosen on each call. - HudEdge
- The edge of the remaining content from which a strip is taken.
- HudLayout
Error - Layout failure; no failed operation changes existing reservations.
- UiError
Constants§
- HUD_
REGION_ CAPACITY - Maximum number of named strips, including zero-thickness strips.
Functions§
- fit_
label - Fit monospaced text without shrinking its glyphs or allocating.
advanceis the positive, finite glyph advance, not the font height. The renderer’s bitmap font usessize * 0.75. Unicode scalar values count as one glyph (unsupported glyphs are rendered as?); UTF-8 is never split. Newlines end the label and signal truncation. A width fitting fewer than three glyphs shows only as many dots as fit; a zero width returns empty pieces. Work is bounded by the visible prefix, even for very long input strings. - hud_
slots - Reflow equal-width HUD cells left-to-right, then top-to-bottom, without allocation.
Each row fits as many
min_widthcells as possible (at least one), distributing spare width equally. Rows keepheight; a narrow viewport shrinks the one column. The last row keeps the same column widths, even when not full. Cells clip toparent, so overflow rows become empty, non-interactive rectangles. This never scales text: combine withfit_labelfor long labels. - slots
- Equal-width/height slots without temporary layout allocations.