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

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 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 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 widget(&mut self, widget: &dyn HasFocus) -> &mut Self

Add a widget by calling its build function. The build function of the HasFocus trait can use builder to define its focus requirements.

The widget is added to all open containers.

Source

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

Add a widget by calling its build function. The build function of the HasFocus trait can use builder to define its focus requirements.

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.

The widget is added to all open containers.

Source

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

Add a bunch of widget.

The widget is added to all open containers.

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 Self

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

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. Must be matched with the equivalent end.

Attention

If container_flag is None a dummy flag will be created and returned. Use the returned value when calling end.

Panic

Panics if the same container-flag is added twice.

Source

pub fn build(self) -> Focus

Build the final Focus.

If the old Focus has been set with new(), all widgets that are no longer part of the focus will be cleared().

Trait Implementations§

Source§

impl Debug for FocusBuilder

Source§

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

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.