pub struct Focus<'a> { /* private fields */ }Expand description
Keeps track of the focus.
It works by adding a FocusFlag to the State of a widget. Focus is constructed with a list of references to these flags and switches the focus that way. Each widget stays separate otherwise and can pull its focus state from this struct.
use rat_focus::Focus;
let f = Focus::new(&[
&widget1,
&widget2
]).handle(evt, FocusKeys);The result f indicates whether the focus has changed.
Implementations§
source§impl<'a> Focus<'a>
impl<'a> Focus<'a>
sourcepub fn new(list: &[&'a dyn HasFocusFlag]) -> Self
pub fn new(list: &[&'a dyn HasFocusFlag]) -> Self
Construct a new focus list.
sourcepub fn new_accu(
accu: &'a dyn HasFocusFlag,
list: &[&'a dyn HasFocusFlag]
) -> Self
pub fn new_accu( accu: &'a dyn HasFocusFlag, list: &[&'a dyn HasFocusFlag] ) -> Self
Construct a new focus list with an accumulator.
The accumulator has its focus set if any of the contained flags has the focus.
If you have a Focus you can append the Focus of a subcomponent with append. In that case the accumulator of the subcomponent gets its lost+gained flags set too, if you switch the focus between different subcomponents.
See examples/focus_recursive and examples/focus_recursive2
sourcepub fn append(self, focus: Focus<'a>) -> Self
pub fn append(self, focus: Focus<'a>) -> Self
Add a sub-focus cycle.
All its widgets are appended to this list. If the sub-cycle has an accumulator it’s added to the accumulators. All sub-accumulators are appended too.
sourcepub fn init(&self)
pub fn init(&self)
Set the initial state for all widgets. This ensures that there is only one focused widget. The first widget in the list gets the focus.
sourcepub fn focus_widget_no_lost(&self, state: &'a dyn HasFocusFlag)
pub fn focus_widget_no_lost(&self, state: &'a dyn HasFocusFlag)
Sets the focus to the widget.
Sets focus and gained but not lost. This can be used to prevent validation of the field.
sourcepub fn focus_widget(&self, state: &'a dyn HasFocusFlag)
pub fn focus_widget(&self, state: &'a dyn HasFocusFlag)
Sets the focus to the widget with tag.
Sets the focus, gained and lost flags. If this ends up with the same widget as before focus, gained and lost flag are all set.
sourcepub fn focus_no_lost(&self, flag: &FocusFlag)
pub fn focus_no_lost(&self, flag: &FocusFlag)
Sets the focus to the widget.
Sets focus and gained but not lost. This can be used to prevent validation of the field.
sourcepub fn focus(&self, flag: &FocusFlag)
pub fn focus(&self, flag: &FocusFlag)
Sets the focus to the widget with tag.
Sets the focus, gained and lost flags. If this ends up with the same widget as before focus, gained and lost flag are all set.
sourcepub fn reset_lost_gained(&self)
pub fn reset_lost_gained(&self)
Reset lost + gained flags.
This is done automatically in HandleEvent::handle() for every event.
sourcepub fn focus_idx(&self, idx: usize)
pub fn focus_idx(&self, idx: usize)
Change the focus.
Sets the focus, gained and lost flags.
If the field at idx has the focus all three are set.
Trait Implementations§
source§impl<'a> IntoIterator for Focus<'a>
impl<'a> IntoIterator for Focus<'a>
Auto Trait Implementations§
impl<'a> Freeze for Focus<'a>
impl<'a> !RefUnwindSafe for Focus<'a>
impl<'a> !Send for Focus<'a>
impl<'a> !Sync for Focus<'a>
impl<'a> Unpin for Focus<'a>
impl<'a> !UnwindSafe for Focus<'a>
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> 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