pub struct FocusManager<T: Clone + Eq + Hash = usize> { /* private fields */ }Expand description
Focus manager for Tab navigation.
Manages a list of focusable elements and tracks which one currently has focus. Elements are navigated in registration order.
§Type Parameters
T- The type used to identify focusable elements. Must implementClone,Eq, andHash. Commonly an enum or integer type.
Implementations§
Source§impl<T: Clone + Eq + Hash> FocusManager<T>
impl<T: Clone + Eq + Hash> FocusManager<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new focus manager with pre-allocated capacity.
Sourcepub fn register(&mut self, element: T)
pub fn register(&mut self, element: T)
Register a focusable element.
Elements are added to the end of the navigation order. Duplicate elements are ignored.
The first registered element is automatically focused.
Sourcepub fn register_all(&mut self, elements: impl IntoIterator<Item = T>)
pub fn register_all(&mut self, elements: impl IntoIterator<Item = T>)
Register multiple elements at once.
Sourcepub fn current(&self) -> Option<&T>
pub fn current(&self) -> Option<&T>
Get the currently focused element.
Returns None if no elements are registered.
Sourcepub fn current_index(&self) -> Option<usize>
pub fn current_index(&self) -> Option<usize>
Get the current focus index.
Sourcepub fn is_focused(&self, element: &T) -> bool
pub fn is_focused(&self, element: &T) -> bool
Check if an element is currently focused.
Sourcepub fn next(&mut self)
pub fn next(&mut self)
Move focus to the next element.
Wraps around to the first element after the last.
Sourcepub fn prev(&mut self)
pub fn prev(&mut self)
Move focus to the previous element.
Wraps around to the last element before the first.
Sourcepub fn set(&mut self, element: T)
pub fn set(&mut self, element: T)
Set focus to a specific element.
If the element is not registered, focus is unchanged.
Trait Implementations§
Source§impl<T: Clone + Clone + Eq + Hash> Clone for FocusManager<T>
impl<T: Clone + Clone + Eq + Hash> Clone for FocusManager<T>
Source§fn clone(&self) -> FocusManager<T>
fn clone(&self) -> FocusManager<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T> Freeze for FocusManager<T>
impl<T> RefUnwindSafe for FocusManager<T>where
T: RefUnwindSafe,
impl<T> Send for FocusManager<T>where
T: Send,
impl<T> Sync for FocusManager<T>where
T: Sync,
impl<T> Unpin for FocusManager<T>where
T: Unpin,
impl<T> UnwindSafe for FocusManager<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more