Expand description
Shared game UI kit for the Repame template line: one action queue, one run flow, focus-navigable controls, one palette and one touch overlay.
The kit exists because a measurement across the template-derived games found
the same four things in every ui/ module: eleven files define the same
mix/lighten, eight to ten define the same rect/chunky/label
shapes, thirteen files across nine games — four of them outside the template
line — hand-roll the same Sink/UiActions/drain_actions action queue,
and eight ship the same virtual stick. Nothing in those games can be
navigated with a keyboard or a gamepad, because the overlay root asks for
focus for itself and the buttons are boxes with a click handler.
§What the kit owns
queue:ActionQueue/Sinkto push from a click closure and drain from the sim, plusIntents, the ordered edge view of a drained batch that replaces a per-action boolean struct.flow:Flow,TransitionandSuspensionasrepame_sim::statestate sets with enter/exit/transition schedules, plusFlowState, the playing / modal / transitional / suspended predicates every game’sPhaseandRunStatere-derive.nav: focus traversal over the kit’s own controls, built on repose’sspatial_focus_nextandFocusRequester, with an entry point, focus groups, boundary wrap and analog-stick repeat. This is the part the template games are missing entirely.paletteandkit: palette tokens and the button/chip/panel/label voices every game redraws, with the colour blending in one place.touch: the virtual stick and tap buttons as kit controls, driving the same queue and the sameapply_stickcurve as the pads.
§Adoption
Nothing here has to be an ECS resource, and the crate deliberately carries no
bevy_ecs dependency. A game keeps the wrapper resource it already declares
and puts the kit’s handle inside it:
#[derive(Resource, Clone, Default)]
pub struct UiActions(pub repame_ui::Sink<UiAction>);
#[derive(Resource, Default)]
pub struct UiIntents(pub repame_ui::Intents<UiAction>);The frame then drains once, and hands the same sink to the kit:
let mut ui = self.sim.world.resource_mut::<UiActions>();
let mut intents = self.sim.world.resource_mut::<UiIntents>();
repame_ui::absorb(&ui.0, &mut intents.0);
let kit = repame_ui::Kit::new(scale, repame_ui::Tokens::default(), ui.0.clone());
kit.begin_frame();
sim.add_chained_systems(update.run_if(repame_ui::flow::run_live));What stays in the game: its action enum, its panel list, its art colours and its font registration. What the kit removes: the copies of the queue, the flow predicates, the palette blending, the shapes, the stick, and the reason the menus could not be navigated.
Re-exports§
pub use flow::Flow;pub use flow::FlowState;pub use flow::InputOwner;pub use flow::Suspension;pub use flow::Transition;pub use flow::panel_owns_input;pub use flow::run_live;pub use kit::Button;pub use kit::Kit;pub use kit::overlay_root;pub use layout::DESIGN;pub use layout::Scale;pub use layout::ScaleError;pub use layout::anchor_edges;pub use layout::anchor_rect;pub use layout::design_units;pub use layout::disc;pub use layout::ring;pub use nav::GroupId;pub use nav::Wrap;pub use nav::chain_of;pub use nav::dpad_dirs;pub use nav::pad_confirm;pub use palette::FONT;pub use palette::ICON_BUTTON;pub use palette::ICON_GLYPH;pub use palette::MATERIAL_SYMBOLS;pub use palette::Tokens;pub use palette::chip;pub use palette::chunky;pub use palette::darken;pub use palette::hand_cut;pub use palette::lighten;pub use palette::mix;pub use palette::state_colors;pub use queue::ActionQueue;pub use queue::Intents;pub use queue::Sink;pub use queue::UiAction;pub use queue::absorb;pub use touch::STICK_RADIUS;pub use touch::TouchError;pub use touch::TouchPad;
Modules§
- flow
- Menu and run flow on
repame_sim::state, not on a per-gamePhaseenum. - kit
- The kit: palette tokens, one scale, one action sink and one nav map, handed to every control a panel is built from.
- layout
- Design-space placement: the viewport scale every game recomputes, and the anchor/offset rectangle they all place panels with.
- nav
- Focus traversal over kit controls, built on repose’s own focus machinery.
- palette
- Palette tokens and the chip/button shapes the per-game palettes redraw.
- queue
- One ordered action queue: the view pushes, the sim drains.
- touch
- The virtual stick and tap buttons, as kit controls.