Skip to main content

FocusManager

Struct FocusManager 

Source
pub struct FocusManager { /* private fields */ }
Expand description

Tracks and moves keyboard focus within a WidgetTree.

Implementations§

Source§

impl FocusManager

Source

pub fn new() -> Self

Create a manager with nothing focused and no active trap.

Source

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

The currently focused node, if any.

Source

pub fn trap(&self) -> Option<WidgetId>

The active focus-trap root, if any.

Source

pub fn focusable_set(&self, tree: &WidgetTree) -> Vec<WidgetId>

The ordered list of focusable nodes that focus may currently move between, honouring any active trap (only the trap’s focusable descendants — and the trap node itself if focusable — are included).

Source

pub fn focus(&mut self, tree: &WidgetTree, id: WidgetId) -> bool

Focus id if it is currently focusable (and inside the trap, if any). Returns true on success.

Source

pub fn blur(&mut self)

Clear focus.

Source

pub fn push_trap( &mut self, tree: &WidgetTree, trap: WidgetId, ) -> Option<WidgetId>

Activate a focus trap rooted at trap. If the current focus falls outside the trap, focus moves to the first focusable node within it. Returns the node focused after activation, if any.

Source

pub fn pop_trap(&mut self)

Release the active focus trap. Focus is left where it is.

Source

pub fn focus_next(&mut self, tree: &WidgetTree) -> Option<WidgetId>

Move focus to the next focusable node in tab order (wraps around). Returns the newly focused node, or None if nothing is focusable.

Source

pub fn focus_prev(&mut self, tree: &WidgetTree) -> Option<WidgetId>

Move focus to the previous focusable node in tab order (wraps around).

Source

pub fn autofocus( &mut self, tree: &WidgetTree, is_autofocus: impl Fn(WidgetId) -> bool, ) -> Option<WidgetId>

Focus the first node in tab order whose autofocus flag (as supplied by is_autofocus) is true. Returns the focused node, if one matched.

The tree node has no dedicated autofocus field, so the predicate lets callers decide (e.g. by inspecting a node’s label or an external map).

Source

pub fn reconcile(&mut self, tree: &WidgetTree) -> bool

Drop focus if the focused node is no longer present or no longer focusable (call after removing/reparenting nodes). Returns true if focus was cleared as a result.

Trait Implementations§

Source§

impl Clone for FocusManager

Source§

fn clone(&self) -> FocusManager

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FocusManager

Source§

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

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

impl Default for FocusManager

Source§

fn default() -> FocusManager

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> 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> 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.