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>
impl<Id> FocusRing<Id>
Sourcepub fn begin_frame(&mut self)
pub fn begin_frame(&mut self)
Source§impl<Id: Copy + PartialEq> FocusRing<Id>
impl<Id: Copy + PartialEq> FocusRing<Id>
Sourcepub fn is_focused(&self, id: Id) -> bool
pub fn is_focused(&self, id: Id) -> bool
true if id currently holds focus.
Sourcepub fn advance(&mut self)
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.
Sourcepub fn retreat(&mut self)
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.
Sourcepub fn handle_event(&mut self, event: &Event)
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).