Expand description
A bounded vertical region composed from the existing UiState and Ui.
Keep one ScrollRegion and a dedicated paint-only Ui across frames. Pass
all content items (including offscreen ones) to update, then queue labels
and buttons using the resulting offset. Do not call Ui::finish on that
paint-only UI: the region owns its focus/capture and reads the ordered host
journal itself. Other menus keep their own Ui and focus. The caller enables
only the active input owner; overlapping/nested scroll routing is unsupported.
All coordinates are logical UI units. A responsive viewport keeps fonts in
host logical pixels; use a zero-inset viewport with absolute HudRegions
rectangles. A fitted viewport is also supported: input is unprojected once.
No simulation clock, gameplay edge, camera or renderer is replaced.
use ferravex_render::ui::{ButtonStyle, Ui, UiRect, Viewport};
use ferravex_render::ui::scroll::{ScrollItem, ScrollRegion};
let viewport = Viewport::responsive([320., 240.], [0.; 4])?;
let bounds = UiRect { min: [12., 32.], size: [296., 100.] };
let items = [10, 20, 30].map(|id| ScrollItem {
id, rect: UiRect { min: [0., (id / 10 - 1) as f32 * 70.], size: [296., 44.] },
enabled: true,
});
let mut region = ScrollRegion::new(3);
let mut paint = Ui::new(); // Reuse both between frames.
region.update(viewport, bounds, 184., &items, true)?;
assert_eq!(region.focus_next(false), Some(10));
assert_eq!(region.focus_next(false), Some(20));
assert_eq!(region.focus_next(false), Some(30));
assert_eq!(region.scroll().offset(), 84.);
paint.begin(viewport);
for (item, label) in items.iter().zip(["COURSE", "BEST TIME", "CONTROLS"]) {
region.button(&mut paint, item.id, label, ButtonStyle::default())?;
}
// In a host frame: paint.paint(); inspect region.activated(item.id).
// For remapped confirmation: call activate_focused only on its accepted edge.
assert_eq!(region.activate_focused(), Some(30));
assert!(region.activated(30));Structs§
- Scroll
Item - A stable identity and unscrolled content-space rectangle. Items must fit the declared content width/height. Disabled items still occlude pointer hits. Slice order defines Tab/arrow order and back-to-front pointer hit order.
- Scroll
Region - Bounded content registry with the existing UI’s press/release capture rules. Construction reserves storage once; update/navigation/drag do not grow it. Focus survives scrolling and cancellation. Resize/reflow cancels a pending press, preserves eligible focus IDs, and clamps the offset without activation.
Constants§
- SCROLL_
ITEM_ CAPACITY - Region item ceiling, additionally subject to the paint UI’s command/text budgets.