pub struct UiState { /* private fields */ }Implementations§
Source§impl UiState
impl UiState
Sourcepub fn with_capacity(limit: usize) -> UiState
pub fn with_capacity(limit: usize) -> UiState
Fixed widget budget; rebuilding a frame never grows this buffer.
pub fn new() -> UiState
Sourcepub fn begin_frame(&mut self)
pub fn begin_frame(&mut self)
Rebuild widgets in back-to-front paint order; IDs preserve focus/capture.
pub fn add(&mut self, widget: Widget) -> Result<(), UiError>
Sourcepub fn end_frame(&mut self)
pub fn end_frame(&mut self)
Call after layout, before delivering input, to discard removed/disabled IDs.
pub fn capacity(&self) -> usize
pub fn focused(&self) -> Option<u64>
pub fn captured(&self) -> Option<u64>
pub fn hit_test(&self, point: [f32; 2]) -> Option<u64>
pub fn pointer_down(&mut self, point: [f32; 2]) -> Option<u64>
Sourcepub fn pointer_up(&mut self, point: [f32; 2]) -> Option<u64>
pub fn pointer_up(&mut self, point: [f32; 2]) -> Option<u64>
Click activates only when both press and release belong to the same widget.
pub fn cancel_pointer(&mut self)
pub fn focus_next(&mut self, reverse: bool) -> Option<u64>
Sourcepub fn focus_direction(
&mut self,
direction: FocusDirection,
wrap: FocusWrap,
) -> Option<u64>
pub fn focus_direction( &mut self, direction: FocusDirection, wrap: FocusWrap, ) -> Option<u64>
Move focus spatially and return the resulting focused ID, even if unchanged. Only enabled, focusable widgets with nonempty clipped geometry participate. As with tab focus, paint occlusion does not remove a widget from navigation.
A candidate’s clipped center must lie strictly ahead of the current center.
Candidates whose perpendicular intervals overlap the current rectangle
rank first (the same row for left/right, column for up/down), followed by
squared center distance, then the lowest WidgetId. Touching intervals
do not overlap. Equal centers are not directional neighbors. Geometry is
widened to f64 before arithmetic, including distance calculations.
FocusWrap applies only when no candidate lies ahead. If the focused ID
is absent or no longer eligible, select the first eligible widget in tab
order without taking another step; return None if none is eligible.
Call after layout and Self::end_frame, as with other input methods.
This does not activate widgets, reorder tab/paint order, or change pointer
capture. It scans the bounded widget buffer without allocating.
use ferravex_play::ui::{FocusDirection, FocusWrap, Rect, UiState, Widget};
let mut ui = UiState::with_capacity(2);
ui.begin_frame();
for (id, x) in [(1, 0.), (2, 80.)] {
ui.add(Widget {
id, rect: Rect { min: [x, 0.], size: [60., 30.] },
clip: None, enabled: true, focusable: true,
})?;
}
ui.end_frame();
assert_eq!(ui.focus_direction(FocusDirection::Right, FocusWrap::Clamp), Some(1));
assert_eq!(ui.focus_direction(FocusDirection::Right, FocusWrap::Clamp), Some(2));
assert_eq!(ui.focus_direction(FocusDirection::Right, FocusWrap::Clamp), Some(2));
assert_eq!(ui.focus_direction(FocusDirection::Right, FocusWrap::Wrap), Some(1));
assert_eq!(ui.activate_focused(), Some(1));