Module ui

Source
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
CanvasFit
Pure adapter data for an existing ferravex_render::canvas::Canvas2D. This crate cannot depend on the renderer, which already depends on play.
FittedLabel
A borrowed, single-line prefix and static ASCII ellipsis. Draw the two pieces consecutively at the original font size; no temporary String is 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::new or reuse the current screen/safe area with Self::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::fit letterboxes a design canvas; Self::responsive keeps 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.
FocusDirection
Spatial navigation in logical UI coordinates; positive Y points down. See UiState::focus_direction for a complete example.
FocusWrap
Edge behavior for UiState::focus_direction, chosen on each call.
HudEdge
The edge of the remaining content from which a strip is taken.
HudLayoutError
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. advance is the positive, finite glyph advance, not the font height. The renderer’s bitmap font uses size * 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_width cells as possible (at least one), distributing spare width equally. Rows keep height; a narrow viewport shrinks the one column. The last row keeps the same column widths, even when not full. Cells clip to parent, so overflow rows become empty, non-interactive rectangles. This never scales text: combine with fit_label for long labels.
slots
Equal-width/height slots without temporary layout allocations.

Type Aliases§

WidgetId