pub struct KeyboardFocus<T: Copy + Eq, S: Copy + Eq> { /* private fields */ }Expand description
An allocation-free focus controller for one caller-selected modal scope.
The caller supplies a bounded, ordered slice of unique eligible target IDs on every operation. Disabled/hidden targets must be omitted. Changing scope or removing the current target clears focus before interpreting the command; activation never silently moves to another target. Use generation-qualified entity IDs, or clear/recreate the controller when a World is replaced.
This helper registers no systems and reads no keys. The application chooses Tab/Shift-Tab/arrow bindings and routes each accepted action exactly once. Equality is caller code. Validation costs O(n^2) comparisons, bounded by the configured target limit; navigation is O(n), storage is constant, no heap work.
Implementations§
Source§impl<T: Copy + Eq, S: Copy + Eq> KeyboardFocus<T, S>
impl<T: Copy + Eq, S: Copy + Eq> KeyboardFocus<T, S>
Sourcepub const fn new(max_targets: usize) -> Self
pub const fn new(max_targets: usize) -> Self
Creates an empty controller with an explicit eligible-target cap.
Sourcepub const fn focused(&self) -> Option<T>
pub const fn focused(&self) -> Option<T>
Returns focused identity; call synchronize after changing eligibility.
Sourcepub fn synchronize(
&mut self,
scope: S,
eligible: &[T],
) -> Result<(), FocusError>
pub fn synchronize( &mut self, scope: S, eligible: &[T], ) -> Result<(), FocusError>
Reconciles scope and eligibility without choosing or activating a new target.
Sourcepub fn set_focused(
&mut self,
scope: S,
eligible: &[T],
target: Option<T>,
) -> Result<(), FocusError>
pub fn set_focused( &mut self, scope: S, eligible: &[T], target: Option<T>, ) -> Result<(), FocusError>
Sets an eligible focus explicitly, for example after pointer selection. Invalid target/order/limits preserve both old scope and old focus.
Sourcepub fn process(
&mut self,
scope: S,
eligible: &[T],
command: FocusCommand,
) -> Result<FocusOutcome<T>, FocusError>
pub fn process( &mut self, scope: S, eligible: &[T], command: FocusCommand, ) -> Result<FocusOutcome<T>, FocusError>
Applies one caller-approved command after reconciling the active modal scope. Empty orders clear focus. Failed validation performs no mutation.
Trait Implementations§
Auto Trait Implementations§
impl<T, S> Freeze for KeyboardFocus<T, S>
impl<T, S> RefUnwindSafe for KeyboardFocus<T, S>
impl<T, S> Send for KeyboardFocus<T, S>
impl<T, S> Sync for KeyboardFocus<T, S>
impl<T, S> Unpin for KeyboardFocus<T, S>
impl<T, S> UnsafeUnpin for KeyboardFocus<T, S>
impl<T, S> UnwindSafe for KeyboardFocus<T, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.