Focus

Struct Focus 

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

Focus deals with all focus-related issues.

Use FocusBuilder to construct the current Focus.

This is usually quick enough to do it for each event. It has to be rebuilt if any area has changed, so rebuilding it after a render() is fine.

Implementations§

Source§

impl Focus

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 enable_panic(&self)

Enable insta-panic if any function is called with a widget that is not part of the Focus.

Source

pub fn disable_panic(&self)

Disable insta-panic.

Source

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

Sets the focus to the given widget.

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

This will ignore the Navigation flag of the currently focused widget.

You can also use a container-widget for this. It will set the focus to the first navigable widget of the container.

Source

pub fn by_widget_id(&self, widget_id: usize)

Sets the focus to the widget by its widget-id.

This can be useful if you want to store references to widgets in some extra subsystem and can’t use a clone of the FocusFlag for that.

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

This will ignore the Navigation flag of the currently focused widget.

You can also use a container-widget for this. It will set the focus to the first widget of the container.

Source

pub fn first(&self)

Set the focus to the first navigable widget.

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

This will ignore the Navigation flag of the currently focused widget.

Source

pub fn first_in(&self, container: &dyn HasFocus)

👎Deprecated since 1.1.2: use focus() instead
Source

pub fn none(&self)

Clear the focus for all widgets.

This will reset the focus, gained and lost flags for all widgets.

Source

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

This widget will have the focus, but it is not yet part of the focus cycle. And the focus cycle can’t be properly rebuilt at this point.

If the widget is part of the focus this will do nothing.

If the widget is a container, it will just set the container-flag. If you want to set a future widget and its container, call future() for the widget first, then the container.

Source

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

Change to focus to the widget at the given position.

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

If the current widget has a Navigation::Lock, this will do nothing.

Source

pub fn next(&self) -> bool

Focus the next widget in the cycle.

This function will use the Navigation of the current widget and only focus the next widget if it is Leave, ReachLeaveBack or Regular.

If no field has the focus the first navigable one gets it. Sets the focus, gained and lost flags. If this ends up with the same widget as before focus, gained and lost flag are not set.

Source

pub fn prev(&self) -> bool

Focus the previous widget in the cycle.

This function will use the Navigation of the current widget and only focus the next widget if it is Leave, ReachLeaveFront or Regular.

If no field has the focus the first navigable one gets it. Sets the focus, gained and lost flags. If this ends up with the same widget as before focus, gained and lost flag are not set.

Source

pub fn next_force(&self) -> bool

Focus the next widget in the cycle.

Applies some extra force to this action and allows leaving widgets that have Navigation Reach and ReachLeaveFront in addition to the regular Leave, ReachLeaveBack or Regular.

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

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

Source

pub fn prev_force(&self) -> bool

Focus the previous widget in the cycle.

Applies some extra force to this action and allows leaving widgets that have Navigation Reach and ReachLeaveBack in addition to the regular Leave, ReachLeaveFront or Regular.

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

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

Source

pub fn is_valid_widget(&self, widget_state: &dyn HasFocus) -> bool

Is this widget part of this focus-cycle?

Source

pub fn is_valid_container(&self, widget_state: &dyn HasFocus) -> bool

Is this a container that is part of this focus-cycle?

Source

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

Returns the focused widget as FocusFlag.

For control-flow crate::match_focus or crate::on_gained or crate::on_lost will be nicer.

Source

pub fn focused_widget_id(&self) -> Option<usize>

Returns the focused widget as widget-id.

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.

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.

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.

For control-flow crate::match_focus or crate::on_gained or crate::on_lost will be nicer.

Source

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

Sets the focus to the given widget, but doesn’t set lost and gained. This can be used to prevent any side effects that use the gained/lost state.

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

This will ignore the Navigation flag of the currently focused widget.

You can also use a container-widget for this. It will set the focus to the first widget of the container.

Source

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

This expels the focus from the given widget/container.

This is sometimes useful to set the focus to somewhere else. This is especially useful when used for a container-widget that will be hidden. Ensures there is still some widget with focus afterward.

It will try to set the focus to the next widget or the next widget following the container. If this ends up within the given container it will set the focus to none.

This function doesn’t use the Navigation of the current widget.

Source

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

Dynamic change of the widget structure for 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 HasFocus)

Dynamic change of the widget structure for 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 HasFocus, new: &dyn HasFocus, )

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 reset_lost_gained(&self)

Reset lost + gained flags.

This is done automatically during event-handling. Lost+Gained flags will only be set while handling the original event that made the focus-change. The next event, whatever it is, will reset these flags.

Source

pub fn clone_destruct( &self, ) -> (Vec<FocusFlag>, Vec<bool>, Vec<(Rect, u16)>, Vec<Navigation>, Vec<(FocusFlag, (Rect, u16), Range<usize>)>)

Debug destructuring.

Trait Implementations§

Source§

impl Clone for Focus

Source§

fn clone(&self) -> Focus

Returns a duplicate 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<(), Error>

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

impl Default for Focus

Source§

fn default() -> Focus

Returns the “default value” for a type. 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<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default.
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, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
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, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
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, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
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> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
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, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. 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.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.