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”):
| token | values |
|---|---|
| spacing | SPACE = 4, 8, 12, 16, 24, 32 |
| radii | RADIUS_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§
- Button
Motion - Eased hover/press/focus amounts for one button (critically damped springs, so state changes glide without overshoot). Keep one per button.
- Button
State - Pointer/focus state of a button for one frame.
- KitTheme
- Colors and sizes for kit widgets.
alphamultiplies everything, which is how fades fromAppearanceare applied (KitTheme::faded).
Enums§
- Button
Kind - 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::ButtonStylewhose own paint is fully transparent, for buttons that keepUiinput/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
rectabout its center per anAppearance. - 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 buttonwith a pictogram before its label (or alone whenlabelis empty):[▶ Play],[↻ Retry],[⚙]. The icon takes the label’s ink.- card
panelwith 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) incolor. Wipes have a soft leading edge; the iris closes onfocus(screen units). UseScreenTransition::kind(motion)so reduced motion fades. - icon_
value - The standard HUD stat:
iconthenvalue, vertically centered oncyand starting atx(for example a heart and12).sizeis 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
keycapforlabelwithout 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
ghostvalue 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 beforecurrent(one-based) are filled,currentis 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
itemsleft to right fromx, vertically centered oncy, 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
rowforitemswithout drawing, for centering and fitting. - toast
- A toast centered horizontally on
center_xwith its top attop. Pass theAppearancefrom aferravex_play::tween::Entranceto slide/fade it.iconis drawn in the tone’s color before the text. Returns its rectangle. - toast_
icon toastled by a pictogram in the tone’s color instead of a font glyph.- ui_
button_ state - State of a
UibuttonidafterUi::finish(hover, pointer capture and keyboard/gamepad focus), for painting it with the kit. - ui_rect
- Screen rectangle of a
Uilayout rectangle.