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
impl Focus
sourcepub fn new_list(list: &[&dyn HasFocusFlag]) -> Self
pub fn new_list(list: &[&dyn HasFocusFlag]) -> Self
Construct a new focus list.
sourcepub fn new_container(container: ContainerFlag, area: Rect) -> Self
pub fn new_container(container: ContainerFlag, area: Rect) -> Self
Construct a new focus list for a container widget.
The focus-flag for the container accumulates all the flags. If any widget has focus, the container has the focus too. Focus-gained and focus-lost are only set if the focus leaves the container.
The container widget itself interacts with the mouse too. If no single widget is hit with the mouse, but the area of the container is, the first widget gets the focus.
See examples/focus_recursive and examples/focus_recursive2
sourcepub fn new_container_list(
container: ContainerFlag,
area: Rect,
list: &[&dyn HasFocusFlag],
) -> Self
pub fn new_container_list( container: ContainerFlag, area: Rect, list: &[&dyn HasFocusFlag], ) -> Self
Construct a new focus list for a container widget.
The focus-flag for the container accumulates all the flags. If any widget has focus, the container has the focus too. Focus-gained and focus-lost are only set if the focus leaves the container.
The container widget itself interacts with the mouse too. If no single widget is hit with the mouse, but the area of the container is, the first widget gets the focus.
See examples/focus_recursive and examples/focus_recursive2
sourcepub fn container_flag(&self) -> Option<ContainerFlag>
pub fn container_flag(&self) -> Option<ContainerFlag>
Container-flag for this Focus.
sourcepub fn container_area(&self) -> Rect
pub fn container_area(&self) -> Rect
Container-area for this Focus.
sourcepub fn add_container(&mut self, container: &dyn HasFocus)
pub fn add_container(&mut self, container: &dyn HasFocus)
Add a container widget.
sourcepub fn remove_container(&mut self, container: &dyn HasFocus)
pub fn remove_container(&mut self, container: &dyn HasFocus)
Remove a container widget.
sourcepub fn update_container(&mut self, container: &dyn HasFocus)
pub fn update_container(&mut self, container: &dyn HasFocus)
Update the composition of the container.
sourcepub fn replace_container(
&mut self,
container: &dyn HasFocus,
new: &dyn HasFocus,
)
pub fn replace_container( &mut self, container: &dyn HasFocus, new: &dyn HasFocus, )
sourcepub fn add(&mut self, f: &dyn HasFocusFlag)
pub fn add(&mut self, f: &dyn HasFocusFlag)
Add a single widget.
sourcepub fn insert_before(&mut self, f: &dyn HasFocusFlag, before: &dyn HasFocusFlag)
pub fn insert_before(&mut self, f: &dyn HasFocusFlag, before: &dyn HasFocusFlag)
Add a single widget.
sourcepub fn insert_after(&mut self, f: &dyn HasFocusFlag, after: &dyn HasFocusFlag)
pub fn insert_after(&mut self, f: &dyn HasFocusFlag, after: &dyn HasFocusFlag)
Add a single widget.
sourcepub fn remove(&mut self, f: &dyn HasFocusFlag)
pub fn remove(&mut self, f: &dyn HasFocusFlag)
Remove a single widget
sourcepub fn update(&mut self, f: &dyn HasFocusFlag)
pub fn update(&mut self, f: &dyn HasFocusFlag)
Update the flags of a widget.
sourcepub fn replace(&mut self, f: &dyn HasFocusFlag, new: &dyn HasFocusFlag)
pub fn replace(&mut self, f: &dyn HasFocusFlag, new: &dyn HasFocusFlag)
Replace a single widget.
sourcepub fn add_all(&mut self, list: &[&dyn HasFocusFlag])
pub fn add_all(&mut self, list: &[&dyn HasFocusFlag])
Append a list of widgets.
sourcepub fn add_flag(&mut self, flag: FocusFlag, area: Rect)
pub fn add_flag(&mut self, flag: FocusFlag, area: Rect)
Add a single widget. This doesn’t add any z_areas and assumes navigable is true.
sourcepub fn add_focus(&mut self, container: Focus)
pub fn add_focus(&mut self, container: Focus)
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 sub-accumulators. All sub-sub-accumulators are appended too.
sourcepub fn enable_log(&self)
pub fn enable_log(&self)
Writes a log for each operation.
sourcepub fn disable_log(&self)
pub fn disable_log(&self)
Writes a log for each operation.
sourcepub fn focus_no_lost(&self, widget_state: &dyn HasFocusFlag)
pub fn focus_no_lost(&self, widget_state: &dyn HasFocusFlag)
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.
sourcepub fn focus(&self, widget_state: &dyn HasFocusFlag)
pub fn focus(&self, widget_state: &dyn HasFocusFlag)
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.
sourcepub fn focus_flag_no_lost(&self, flag: FocusFlag)
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.
sourcepub fn focus_flag(&self, flag: FocusFlag)
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.
sourcepub fn focused(&self) -> Option<FocusFlag>
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.
sourcepub fn focused_name(&self) -> Option<String>
pub fn focused_name(&self) -> Option<String>
Returns the debug name of the focused widget.
This is mainly for debugging purposes.
Returns the navigation flag for the focused widget.
sourcepub fn lost_focus(&self) -> Option<FocusFlag>
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.
sourcepub fn gained_focus(&self) -> Option<FocusFlag>
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.
sourcepub fn reset_lost_gained(&self)
pub fn reset_lost_gained(&self)
Reset lost + gained flags.
This is done automatically in HandleEvent::handle() for every event.
sourcepub fn focus_idx(&self, idx: usize)
pub fn focus_idx(&self, idx: usize)
Change the focus.
Sets the focus, gained and lost flags. If this ends up with the same widget as before gained and lost flags are not set.
sourcepub fn first(&self)
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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