FocusBuilder

Struct FocusBuilder 

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

Builder for the Focus.

Implementations§

Source§

impl FocusBuilder

Source

pub fn new(last: Option<Focus>) -> FocusBuilder

Create a new FocusBuilder.

This can take the previous Focus and ensures that widgets that are no longer part of the focus list have their focus-flag cleared.

It will also recycle the storage of the old Focus.

Source

pub fn log_build_for(container: &dyn HasFocus) -> Focus

The same as build_for but with logs enabled.

Source

pub fn build_for(container: &dyn HasFocus) -> Focus

Shortcut for building the focus for a container that implements HasFocus.

This creates a fresh Focus.

See

Use rebuild_for if you want to ensure that widgets that are no longer in the widget structure have their focus flag reset properly. If you don’t have some logic to conditionally add widgets to the focus, this function is probably fine.

Source

pub fn log_rebuild_for(container: &dyn HasFocus, old: Option<Focus>) -> Focus

The same as rebuild_for but with logs enabled.

Source

pub fn rebuild_for(container: &dyn HasFocus, old: Option<Focus>) -> Focus

Shortcut function for building the focus for a container that implements HasFocus

This takes the old Focus and reuses most of its allocations. It also ensures that any widgets no longer in the widget structure have their focus-flags reset.

Source

pub fn enable_log(&self)

Do some logging of the build.

Source

pub fn disable_log(&self)

Do some logging of the build.

Source

pub fn enable_panic(&self)

Enable insta-panic for certain failures.

Source

pub fn disable_panic(&self)

Disable insta-panic for certain failures.

Source

pub fn widget(&mut self, widget: &dyn HasFocus) -> &mut FocusBuilder

Add a widget by calling its build function.

Source

pub fn widget_navigate( &mut self, widget: &dyn HasFocus, navigation: Navigation, ) -> &mut FocusBuilder

Add a widget by calling its build function.

This tries to override the default navigation for the given widget. This will fail if the widget is a container. It may also fail for other reasons. Depends on the widget.

Enable log to check.

Source

pub fn widgets<const N: usize>( &mut self, widgets: [&dyn HasFocus; N], ) -> &mut FocusBuilder

Add a bunch of widgets.

Source

pub fn start(&mut self, container: &dyn HasFocus) -> FocusFlag

Start a container widget. Must be matched with the equivalent end. Uses focus(), area() and z_area() of the given container. navigable() is currently not used, just leave it at the default.

Attention

Use the returned value when calling end.

Panic

Panics if the same container-flag is added twice.

Source

pub fn end(&mut self, tag: FocusFlag)

End a container widget.

Source

pub fn leaf_widget(&mut self, widget: &dyn HasFocus) -> &mut FocusBuilder

Directly add the given widget’s flags. Doesn’t call build() instead it uses focus(), etc. and appends a single widget.

This is intended to be used when implementing HasFocus::build() for a widget.

In all other situations it’s better to use widget().

Panic

Panics if the same focus-flag is added twice.

Source

pub fn widget_with_flags( &mut self, focus: FocusFlag, area: Rect, area_z: u16, navigable: Navigation, )

Manually add a widgets flags.

This is intended to be used when implementing HasFocus::build() for a widget.

In all other situations it’s better to use widget().

Panic

Panics if the same focus-flag is added twice. Except it is allowable to add the flag a second time with Navigation::Mouse or Navigation::None

Source

pub fn start_with_flags( &mut self, container_flag: FocusFlag, area: Rect, area_z: u16, ) -> FocusFlag

Start a container widget.

Returns the FocusFlag of the container. This flag must be used to close the container with end.

Panic

Panics if the same container-flag is added twice.

Source

pub fn build(self) -> Focus

Build the Focus.

If the previous Focus is known, this will also reset the FocusFlag for any widget no longer part of the Focus.

Trait Implementations§

Source§

impl Debug for FocusBuilder

Source§

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

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

impl Default for FocusBuilder

Source§

fn default() -> FocusBuilder

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

Auto Trait Implementations§

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

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.