Module kit

Source
Expand description

Modern UI kit: cards, buttons, meters, toasts, key caps and screen transitions drawn with crate::shapes and the modern text face.

The kit is visual only. Input, focus, hit testing and activation stay in super::Ui: submit buttons there with INVISIBLE_BUTTON (or your own style), then paint them here with ui_button_state and ui_rect. Everything draws in screen units (the default 2D camera), writes straight to the frame’s vertex stream and allocates nothing.

Recommended style (see docs/UI.md, “Modern UI kit”):

tokenvalues
spacingSPACE = 4, 8, 12, 16, 24, 32
radiiRADIUS_SMALL 6 (chips), RADIUS 10 (buttons), RADIUS_LARGE 16 (cards)
type (modern)TYPE_CAPTION 8, TYPE_BODY 16, TYPE_TITLE 24, TYPE_DISPLAY 32

Type sizes are multiples of 8 so every font pixel lands on whole screen pixels. Pair the modern face for copy with the classic face for big retro numerals or titles when a game wants more attitude.

use ferravex_render::{Rect, ui::kit::{self, ButtonKind, ButtonMotion, ButtonState, KitTheme}};
use ferravex_play::tween::Motion;
let theme = KitTheme::default();
let content = kit::card(Rect::new(40., 40., 320., 200.), Some("Settings"), &theme);
let mut motion = ButtonMotion::default();
let state = ButtonState { hovered: true, ..ButtonState::default() };
motion.update(state, 1. / 60., Motion::Full);
let button = Rect::new(content.x, content.y, 140., 36.);
kit::button(button, "Resume", ButtonKind::Primary, &motion, &theme);
kit::meter(Rect::new(content.x, content.y + 52., 200., 12.), 0.7, Some(0.85), theme.success, &theme);

Structs§

ButtonMotion
Eased hover/press/focus amounts for one button (critically damped springs, so state changes glide without overshoot). Keep one per button.
ButtonState
Pointer/focus state of a button for one frame.
KitTheme
Colors and sizes for kit widgets. alpha multiplies everything, which is how fades from Appearance are applied (KitTheme::faded).

Enums§

ButtonKind
Button emphasis.
RowItem
One piece of a row: the vocabulary of an icon-first HUD line.
Tone
Notification tone for toast.

Constants§

INVISIBLE_BUTTON
A super::ButtonStyle whose own paint is fully transparent, for buttons that keep Ui input/focus but are drawn by the kit.
RADIUS
Corner radius for buttons, fields and toasts.
RADIUS_LARGE
Corner radius for cards and dialogs.
RADIUS_SMALL
Corner radius for chips, key caps and small tags.
SPACE
Spacing scale in screen units.
TYPE_BODY
TYPE_CAPTION
Modern-face sizes (multiples of 8 stay pixel-crisp).
TYPE_DISPLAY
TYPE_TITLE

Functions§

appear
Moves and scales rect about its center per an Appearance.
button
Paints a button: rounded fill that brightens on hover, sinks and darkens on press, and an eased focus ring outside the edge. Disabled buttons are flat and muted. The label is centered in the modern face.
button_icon
button with a pictogram before its label (or alone when label is empty): [▶ Play], [↻ Retry], [⚙]. The icon takes the label’s ink.
card
panel with an optional header band and title; returns the content area inset by the spacing scale.
draw_screen_transition
Draws a full-screen scene transition at coverage (0 clear … 1 covered) in color. Wipes have a soft leading edge; the iris closes on focus (screen units). Use ScreenTransition::kind(motion) so reduced motion fades.
icon_value
The standard HUD stat: icon then value, vertically centered on cy and starting at x (for example a heart and 12). size is the icon’s box; the value uses the theme’s body size scaled to match. Returns the width.
key_prompt
Key caps followed by an action label, e.g. [E] Open. Returns the total width.
keycap
A keyboard/gamepad key cap (e.g. "Space", "E", "A") with a raised lip, its top-left at (x, y). Returns its rectangle so prompts can flow.
keycap_width
Width of keycap for label without drawing it, for laying out rows.
meter
Horizontal meter (health, XP, loading): an inset rounded track, a gradient fill with a top highlight and an optional lighter ghost value trailing behind (show the pre-damage value and tween it down for a “chip” effect). Values are clamped to [0, 1].
panel
Raised surface: soft shadow, subtle top-lit gradient and a hairline edge.
pips
A row of progress pips centered on cy: pips before current (one-based) are filled, current is enlarged with a glow, later ones are hollow. Totals above 16 draw a compact meter instead. Returns the width.
ring_meter
Circular progress: a faint track and a bright arc clockwise from 12 o’clock covering fraction (timers, cooldowns, charge).
row
Lay out items left to right from x, vertically centered on cy, with an 8-unit gap between pieces; returns the width. This is the standard icon-first HUD line ([E] gem 3/6 ●●○), shared so games don’t each rebuild it.
row_width
Width of row for items without drawing, for centering and fitting.
toast
A toast centered horizontally on center_x with its top at top. Pass the Appearance from a ferravex_play::tween::Entrance to slide/fade it. icon is drawn in the tone’s color before the text. Returns its rectangle.
toast_icon
toast led by a pictogram in the tone’s color instead of a font glyph.
ui_button_state
State of a Ui button id after Ui::finish (hover, pointer capture and keyboard/gamepad focus), for painting it with the kit.
ui_rect
Screen rectangle of a Ui layout rectangle.