Skip to main content

FocusRing

Struct FocusRing 

Source
pub struct FocusRing<Id> { /* private fields */ }
Expand description

Which id currently holds keyboard focus, plus Tab/Shift+Tab cycling through the ids registered as focusable.

Like HitTester, registrations are per-frame and draw-ordered, but advance/retreat always walk last frame’s finalized order: this frame’s registrations aren’t complete until the draw pass finishes. current itself, unlike the order, persists across frames like any other piece of app state, until focus moves or is cleared.

If the currently focused id isn’t in the order being cycled (e.g. it scrolled out of a list, or its widget wasn’t drawn this frame), the next advance/retreat treats that the same as nothing being focused, landing on the first/last registered id rather than getting stuck.

Implementations§

Source§

impl<Id> FocusRing<Id>

Source

pub const fn new() -> Self

Nothing focused, nothing registered.

Source

pub fn begin_frame(&mut self)

Finalize this frame’s register calls into the order advance/retreat will walk during the frame that’s about to start, and clear the registration list for fresh calls. Call once per frame, before drawing.

Source

pub fn clear(&mut self)

Drop focus entirely.

Source§

impl<Id: Copy + PartialEq> FocusRing<Id>

Source

pub fn register(&mut self, id: Id)

Register id as focusable this frame.

Source

pub const fn focused(&self) -> Option<Id>

The currently focused id, if any.

Source

pub fn is_focused(&self, id: Id) -> bool

true if id currently holds focus.

Source

pub const fn request(&mut self, id: Id)

Explicitly focus id, e.g. in response to a click.

Source

pub fn advance(&mut self)

Move focus to the next id in last frame’s registration order, wrapping past the end. Focuses the first registered id if nothing was focused; a no-op if nothing was registered.

Source

pub fn retreat(&mut self)

Move focus to the previous id in last frame’s registration order, wrapping past the start. Focuses the last registered id if nothing was focused; a no-op if nothing was registered.

Source

pub fn handle_event(&mut self, event: &Event)

Default Tab/Shift+Tab handling: advance on Tab, retreat on BackTab (shift+tab). Called automatically by Interaction::handle_event; call it yourself if you’re using FocusRing standalone, or skip it entirely and drive advance/retreat from something else (a gamepad shoulder button, say) if Tab needs to mean something different in your app (inserting a literal tab into a text field, for instance).

Trait Implementations§

Source§

impl<Id: Clone> Clone for FocusRing<Id>

Source§

fn clone(&self) -> FocusRing<Id>

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<Id: Debug> Debug for FocusRing<Id>

Source§

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

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

impl<Id> Default for FocusRing<Id>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<Id> Freeze for FocusRing<Id>
where Id: Freeze,

§

impl<Id> RefUnwindSafe for FocusRing<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for FocusRing<Id>
where Id: Send,

§

impl<Id> Sync for FocusRing<Id>
where Id: Sync,

§

impl<Id> Unpin for FocusRing<Id>
where Id: Unpin,

§

impl<Id> UnsafeUnpin for FocusRing<Id>
where Id: UnsafeUnpin,

§

impl<Id> UnwindSafe for FocusRing<Id>
where Id: 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> 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.