Struct rat_focus::Focus

source ·
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>

source

pub fn new(list: &[&'a dyn HasFocusFlag]) -> Self

Construct a new focus list.

source

pub fn new_accu( accu: &'a dyn HasFocusFlag, list: &[&'a dyn HasFocusFlag] ) -> Self

Construct a new focus list with an accumulator.

The accumulator might be useful if you create compound widgets. Then you can have the focus state for each contained widget, and an overall state for the compound.

If your compound widget contains compound widgets itself, you let each of the components create their own Focus and add everything together with append.

source

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.

source

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.

source

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.

source

pub fn reset_lost_gained(&self)

Reset lost + gained flags. This is done automatically in HandleEvent::handle() for every event.

source

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.

source

pub fn focus_at(&self, col: u16, row: u16) -> bool

Change to focus to the given position.

source

pub fn next(&self) -> bool

Focus the next widget in the cycle.

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.

If no field has the focus the first one gets it.

source

pub fn prev(&self) -> bool

Focus the previous widget in the cycle.

Sets the focus and lost flags. If this ends up with the same widget as before it returns true and sets the focus, gained and lost flag.

If no field has the focus the first one gets it.

Trait Implementations§

source§

impl<'a> Debug for Focus<'a>

source§

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

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

impl<'a> Default for Focus<'a>

source§

fn default() -> Focus<'a>

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

impl<'a> HandleEvent<Event, FocusKeys, Outcome> for Focus<'a>

source§

fn handle(&mut self, event: &Event, _keymap: FocusKeys) -> Outcome

Handle an event. Read more
source§

impl<'a> HandleEvent<Event, MouseOnly, Outcome> for Focus<'a>

source§

fn handle(&mut self, event: &Event, _keymap: MouseOnly) -> Outcome

Handle an event. Read more
source§

impl<'a> IntoIterator for Focus<'a>

§

type Item = (&'a FocusFlag, Rect)

The type of the elements being iterated over.
§

type IntoIter = Zip<IntoIter<&'a FocusFlag>, IntoIter<Rect>>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.