rat_focus

Struct Focus

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

Focus deals with all focus-related issues.

It must be constructed at least after each render(), as it holds copies of the widget-areas for mouse-handling.

In practice, construct it, when you first need it.

Implementations§

Source§

impl Focus

Source

pub fn remove_container(&mut self, container: &dyn FocusContainer)

Dynamic change of the widget structure of a container widget.

This is only necessary if your widget structure changes during event-handling, and you need a programmatic focus-change for the new structure.

This resets the focus-flags of the removed container.

Source

pub fn update_container(&mut self, container: &dyn FocusContainer)

Dynamic change of the widget structure of a container.

This is only necessary if your widget structure changes during event-handling, and you need a programmatic focus-change for the new structure.

If the widget that currently has the focus is still part of the widget structure it keeps the focus. The focus-flags for all widgets that are no longer part of the widget structure are reset.

Source

pub fn replace_container( &mut self, container: &dyn FocusContainer, new: &dyn FocusContainer, )

Dynamic change of the widget structure of a container.

This is only necessary if your widget structure changes during event-handling, and you need a programmatic focus-change.

This removes the widgets of one container and inserts the widgets of the other one in place.

If the widget that currently has the focus is still part of the widget structure it keeps the focus. The focus-flags for all widgets that are no longer part of the widget structure are reset.

Source

pub fn enable_log(&self)

Writes a log for each operation.

Source

pub fn disable_log(&self)

Writes a log for each operation.

Source

pub fn focus_no_lost(&self, widget_state: &dyn HasFocus)

Sets the focus to the widget.

Sets the focus, but doesn’t set lost or gained. This can be used to prevent validation of the field.

Source

pub fn focus(&self, widget_state: &dyn HasFocus)

Sets the focus to the given widget.

Sets the focus, gained and lost flags.

If this ends up with the same widget as before gained and lost flags are not set.

Source

pub fn expel_focus(&self, widget_state: &dyn HasFocus)

Expels the focus from the given widget regardless of the current state.

Source

pub fn focus_container(&self, container: &dyn FocusContainer)

Sets the focus to the given container.

This sets the focus to the first widget that can be found for this container.

Source

pub fn expel_focus_container(&self, container: &dyn FocusContainer)

Expels the focus from the given container regardless of the current state.

Source

pub fn focus_flag_no_lost(&self, flag: FocusFlag)

Sets the focus to the widget with the given flag.

Sets focus and gained but not lost. This can be used to prevent validation of the field.

Source

pub fn focus_flag(&self, flag: FocusFlag)

Sets the focus to the widget with the given flag.

Sets the focus, gained and lost flags.

If this ends up with the same widget as before gained and lost flags are not set.

Source

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

Returns the focused widget as FocusFlag.

This is mainly for debugging purposes. For control-flow crate::match_focus or crate::on_gained or crate::on_lost will be nicer.

Source

pub fn focused_name(&self) -> Option<String>

Returns the debug name of the focused widget.

This is mainly for debugging purposes.

Source

pub fn navigation(&self) -> Option<Navigation>

Returns the navigation flag for the focused widget.

Source

pub fn lost_focus(&self) -> Option<FocusFlag>

Returns the widget that lost the focus as FocusFlag.

This is mainly for debugging purposes. For control-flow crate::match_focus or crate::on_gained or crate::on_lost will be nicer.

Source

pub fn gained_focus(&self) -> Option<FocusFlag>

Returns the widget that gained the focus as FocusFlag.

This is mainly for debugging purposes. For control-flow crate::match_focus or crate::on_gained or crate::on_lost will be nicer.

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_at(&self, col: u16, row: u16) -> bool

Change to focus to the given position.

Source

pub fn first(&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.

Source

pub fn first_container(&self, container: &dyn FocusContainer)

Focus the first widget of a given container.

The first navigable widget in the container gets the focus.

Source

pub fn none(&self)

Clear the focus for all widgets.

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 Clone for Focus

Source§

fn clone(&self) -> Focus

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Focus

Source§

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

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

impl HandleEvent<Event, MouseOnly, Outcome> for Focus

Source§

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

Handle an event. Read more
Source§

impl HandleEvent<Event, Regular, Outcome> for Focus

Source§

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

Handle an event. Read more

Auto Trait Implementations§

§

impl !Freeze for Focus

§

impl !RefUnwindSafe for Focus

§

impl !Send for Focus

§

impl !Sync for Focus

§

impl Unpin for Focus

§

impl !UnwindSafe for Focus

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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.