Struct UiState

Source
pub struct UiState { /* private fields */ }

Implementations§

Source§

impl UiState

Source

pub fn with_capacity(limit: usize) -> UiState

Fixed widget budget; rebuilding a frame never grows this buffer.

Source

pub fn new() -> UiState

Source

pub fn begin_frame(&mut self)

Rebuild widgets in back-to-front paint order; IDs preserve focus/capture.

Source

pub fn add(&mut self, widget: Widget) -> Result<(), UiError>

Source

pub fn end_frame(&mut self)

Call after layout, before delivering input, to discard removed/disabled IDs.

Source

pub fn capacity(&self) -> usize

Source

pub fn focused(&self) -> Option<u64>

Source

pub fn captured(&self) -> Option<u64>

Source

pub fn hit_test(&self, point: [f32; 2]) -> Option<u64>

Source

pub fn pointer_down(&mut self, point: [f32; 2]) -> Option<u64>

Source

pub fn pointer_up(&mut self, point: [f32; 2]) -> Option<u64>

Click activates only when both press and release belong to the same widget.

Source

pub fn cancel_pointer(&mut self)

Source

pub fn focus_next(&mut self, reverse: bool) -> Option<u64>

Source

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));
Source

pub fn activate_focused(&self) -> Option<u64>

Trait Implementations§

Source§

impl Default for UiState

Source§

fn default() -> UiState

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.