Expand description
Bounded, content-sized horizontal rows with optional wrapping.
Supply measured widths in logical screen units; this helper never measures
text or changes its font size. Rectangles retain the parent’s coordinate
space. In particular, pass a super::HudRegions strip directly and use a
zero-inset super::Viewport::responsive for its absolute screen rectangles.
Use each returned rectangle for both painting and super::Widget input.
use ferravex_play::ui::{Rect, UiState, Widget};
use ferravex_play::ui::flow::{layout, FlowItem, FlowOptions};
let items = [
FlowItem::fixed(44.), // Icon/action retains its authored width.
FlowItem { minimum: 100., preferred: 180., maximum: 300., grow: 1. },
FlowItem::fixed(64.),
];
let area = Rect { min: [8., 24.], size: [320., 96.] };
let mut rects = [area; 3];
let report = layout(area, &items, FlowOptions::default(), &mut rects)?;
assert_eq!((report.written, report.overflow, report.rows), (3, 0, 1));
assert_eq!(rects.map(|r| r.size[0]), [44., 196., 64.]);
let mut ui = UiState::with_capacity(3); // Reuse between frames.
ui.begin_frame();
for (index, &rect) in rects[..report.written].iter().enumerate() {
// Paint this same rect with a fixed-size label in the host.
ui.add(Widget { id: index as u64 + 1, rect, clip: Some(area),
enabled: true, focusable: true }).unwrap();
}
ui.end_frame();
assert_eq!(ui.hit_test([60., 30.]), Some(2));
assert_eq!(ui.focus_next(false), Some(1));Structs§
- Flow
Item - Horizontal extent policy. All fields must be finite and nonnegative, with
minimum <= preferred <= maximum. Zero-width items are allowed and inert unless they receive width; they still count as items and separate gaps. - Flow
Options - Row policy in the parent’s units. Defaults: height 44, gaps [8, 8], wrapping. There is no leading/trailing gap, row stretching, justification or font scale.
- Flow
Report - Only
output[..written]is current geometry. Submit that prefix to input and painting; rebuild input each frame so omitted widgets lose focus/capture.
Enums§
- Flow
Error - Errors leave the entire output unchanged. Ordinary insufficient space or a
short output buffer is instead reported by
FlowReport::overflow.
Constants§
- FLOW_
ITEM_ CAPACITY - Maximum input length. Layout uses fixed stack scratch and no heap allocation.
Functions§
- layout
- Lay out a stable prefix left-to-right, then top-to-bottom, without allocation.