Skip to main content

FocusManager

Struct FocusManager 

Source
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 implement Clone, Eq, and Hash. Commonly an enum or integer type.

Implementations§

Source§

impl<T: Clone + Eq + Hash> FocusManager<T>

Source

pub fn new() -> Self

Create a new empty focus manager.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new focus manager with pre-allocated capacity.

Source

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.

Source

pub fn register_all(&mut self, elements: impl IntoIterator<Item = T>)

Register multiple elements at once.

Source

pub fn clear(&mut self)

Clear all registered elements and reset focus.

Source

pub fn current(&self) -> Option<&T>

Get the currently focused element.

Returns None if no elements are registered.

Source

pub fn current_index(&self) -> Option<usize>

Get the current focus index.

Source

pub fn is_focused(&self, element: &T) -> bool

Check if an element is currently focused.

Source

pub fn next(&mut self)

Move focus to the next element.

Wraps around to the first element after the last.

Source

pub fn prev(&mut self)

Move focus to the previous element.

Wraps around to the last element before the first.

Source

pub fn set(&mut self, element: T)

Set focus to a specific element.

If the element is not registered, focus is unchanged.

Source

pub fn set_index(&mut self, index: usize)

Set focus by index.

If the index is out of bounds, focus is unchanged.

Source

pub fn first(&mut self)

Focus the first element.

Source

pub fn last(&mut self)

Focus the last element.

Source

pub fn unfocus(&mut self)

Remove focus (no element focused).

Source

pub fn has_focus(&self) -> bool

Check if any element has focus.

Source

pub fn len(&self) -> usize

Get the number of registered elements.

Source

pub fn is_empty(&self) -> bool

Check if no elements are registered.

Source

pub fn elements(&self) -> &[T]

Get all registered elements.

Source

pub fn remove(&mut self, element: &T) -> bool

Remove an element from the focus manager.

If the removed element was focused, focus moves to the next element (or previous if it was the last).

Trait Implementations§

Source§

impl<T: Clone + Clone + Eq + Hash> Clone for FocusManager<T>

Source§

fn clone(&self) -> FocusManager<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Clone + Eq + Hash> Debug for FocusManager<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone + Eq + Hash> Default for FocusManager<T>

Source§

fn default() -> Self

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

Auto 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.