pub struct CheckTreeState<Identifier> { /* private fields */ }Expand description
Keeps the state of what is currently selected and what was opened in a CheckTree
Implementations§
Source§impl CheckTreeState<String>
impl CheckTreeState<String>
Sourcepub fn get_checked_things(&self) -> Vec<RecordId>
pub fn get_checked_things(&self) -> Vec<RecordId>
Get the checked things from the tree state
Sourcepub fn get_selected_thing(&self) -> Option<RecordId>
pub fn get_selected_thing(&self) -> Option<RecordId>
Get the selected thing from the tree state
Sourcepub fn handle_mouse_event(
&mut self,
event: MouseEvent,
area: Rect,
swap_ctrl_click_behavior: bool,
) -> Option<Action>
pub fn handle_mouse_event( &mut self, event: MouseEvent, area: Rect, swap_ctrl_click_behavior: bool, ) -> Option<Action>
Handle mouse events interacting with the tree
Assumes that the given area only includes the CheckTree
§Arguments
event - the mouse event to handle
area - the area of the tree in the terminal
swap_ctrl_click_behavior - whether to swap the behavior of ctrl+click and click:
- if
true, ctrl+click will toggle the check state of the item, and click will open the item - if
false(default), ctrl+click will open the item, and click will toggle the check state of the item
§Returns
an action if the mouse event requires it
Source§impl<Identifier> CheckTreeState<Identifier>
impl<Identifier> CheckTreeState<Identifier>
pub const fn get_offset(&self) -> usize
pub const fn opened(&self) -> &HashSet<Vec<Identifier>>
Sourcepub fn selected(&self) -> &[Identifier]
pub fn selected(&self) -> &[Identifier]
Refers to the current cursor selection.
Sourcepub fn flatten<'text>(
&self,
items: &'text [CheckTreeItem<'text, Identifier>],
) -> Vec<Flattened<'text, Identifier>>
pub fn flatten<'text>( &self, items: &'text [CheckTreeItem<'text, Identifier>], ) -> Vec<Flattened<'text, Identifier>>
Get a flat list of all currently viewable (including by scrolling) CheckTreeItems with this CheckTreeState.
Sourcepub fn select(&mut self, identifier: Vec<Identifier>) -> bool
pub fn select(&mut self, identifier: Vec<Identifier>) -> bool
Selects the given identifier.
Returns true when the selection changed.
Clear the selection by passing an empty identifier vector:
Sourcepub fn open(&mut self, identifier: Vec<Identifier>) -> bool
pub fn open(&mut self, identifier: Vec<Identifier>) -> bool
Open a tree node.
Returns true when it was closed and has been opened.
Returns false when it was already open.
TODO: This should return false when it was a leaf node.
Sourcepub fn close(&mut self, identifier: &[Identifier]) -> bool
pub fn close(&mut self, identifier: &[Identifier]) -> bool
Close a tree node.
Returns true when it was open and has been closed.
Returns false when it was already closed.
TODO: This should return false when it was a leaf node.
Sourcepub fn check(&mut self, identifier: Vec<Identifier>) -> bool
pub fn check(&mut self, identifier: Vec<Identifier>) -> bool
Check a tree node
Returns true when it was unchecked and has been checked.
Returns false when it was already checked.
TODO: This should return false when it was not a leaf node.
Sourcepub fn uncheck(&mut self, identifier: &[Identifier]) -> bool
pub fn uncheck(&mut self, identifier: &[Identifier]) -> bool
Uncheck a tree node
Returns true when it was checked and has been unchecked.
Returns false when it was already unchecked.
TODO: This should return false when it was not a leaf node.
Sourcepub fn toggle_selected(&mut self) -> bool
pub fn toggle_selected(&mut self) -> bool
Toggles the currently selected tree node open/close state.
See also toggle
Returns true when a node is opened / closed.
As toggle always changes something, this only returns false when nothing is selected.
TODO: This should return false when it was a leaf node.
Sourcepub fn toggle_check(&mut self, identifier: Vec<Identifier>) -> bool
pub fn toggle_check(&mut self, identifier: Vec<Identifier>) -> bool
Toggles a tree node checked/unchecked state.
When it is currently checked, then uncheck is called. Otherwise check.
Returns true when a node is checked / unchecked.
As toggle always changes something, this only returns false when an empty identifier is given.
TODO: This should return false when it was not a leaf node.
Sourcepub fn toggle_check_selected(&mut self) -> bool
pub fn toggle_check_selected(&mut self) -> bool
Toggles the currently selected tree node checked/unchecked state.
See also toggle_check
Returns true when a node is checked / unchecked.
As toggle always changes something, this only returns false when nothing is selected.
TODO: This should return false when it was not a leaf node.
Sourcepub fn reset(&mut self) -> bool
pub fn reset(&mut self) -> bool
Closes all open nodes, and uncheck all checked nodes.
Returns true when any node was closed or unchecked.
Sourcepub fn select_first(&mut self) -> bool
pub fn select_first(&mut self) -> bool
Select the first node.
Returns true when the selection changed.
Sourcepub fn select_last(&mut self) -> bool
pub fn select_last(&mut self) -> bool
Select the last node.
Returns true when the selection changed.
Sourcepub fn select_relative<F>(&mut self, change_function: F) -> bool
pub fn select_relative<F>(&mut self, change_function: F) -> bool
Sourcepub fn rendered_at(&self, position: Position) -> Option<&[Identifier]>
pub fn rendered_at(&self, position: Position) -> Option<&[Identifier]>
Get the identifier that was rendered for the given position on last render.
Sourcepub const fn scroll_selected_into_view(&mut self)
pub const fn scroll_selected_into_view(&mut self)
Ensure the selected CheckTreeItem is in view on next render
Sourcepub const fn scroll_up(&mut self, lines: usize) -> bool
pub const fn scroll_up(&mut self, lines: usize) -> bool
Scroll the specified amount of lines up
Returns true when the scroll position changed.
Returns false when the scrolling has reached the top.
Sourcepub fn scroll_down(&mut self, lines: usize) -> bool
pub fn scroll_down(&mut self, lines: usize) -> bool
Scroll the specified amount of lines down
Returns true when the scroll position changed.
Returns false when the scrolling has reached the last CheckTreeItem.
Sourcepub fn key_up(&mut self) -> bool
pub fn key_up(&mut self) -> bool
Handles the up arrow key. Moves up in the current depth or to its parent.
Returns true when the selection changed.
Sourcepub fn key_down(&mut self) -> bool
pub fn key_down(&mut self) -> bool
Handles the down arrow key. Moves down in the current depth or into a child node.
Returns true when the selection changed.
Sourcepub fn key_left(&mut self) -> bool
pub fn key_left(&mut self) -> bool
Handles the left arrow key. Closes the currently selected or moves to its parent.
Returns true when the selection or the open state changed.
Sourcepub fn key_right(&mut self) -> bool
pub fn key_right(&mut self) -> bool
Handles the right arrow key. Opens the currently selected.
Returns true when it was closed and has been opened.
Returns false when it was already open or nothing being selected.
Sourcepub fn key_space(&mut self) -> bool
pub fn key_space(&mut self) -> bool
Handles the space key. Toggles the whether the current item is selected
Returns true when the selection changed.
Sourcepub fn mouse_click(&mut self, position: Position) -> bool
pub fn mouse_click(&mut self, position: Position) -> bool
Handles a mouse click. Selects the item at the given position. If the item is a leaf, it checks it. It the item is a branch, it toggles it open/closed.
Returns true when the selection or the open state changed.
Returns false when nothing was rendered at the given position (nothing was clicked).
Trait Implementations§
Source§impl<Identifier: Clone> Clone for CheckTreeState<Identifier>
impl<Identifier: Clone> Clone for CheckTreeState<Identifier>
Source§fn clone(&self) -> CheckTreeState<Identifier>
fn clone(&self) -> CheckTreeState<Identifier>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Identifier: Debug> Debug for CheckTreeState<Identifier>
impl<Identifier: Debug> Debug for CheckTreeState<Identifier>
Source§impl<Identifier: Default> Default for CheckTreeState<Identifier>
impl<Identifier: Default> Default for CheckTreeState<Identifier>
Source§fn default() -> CheckTreeState<Identifier>
fn default() -> CheckTreeState<Identifier>
Auto Trait Implementations§
impl<Identifier> Freeze for CheckTreeState<Identifier>
impl<Identifier> RefUnwindSafe for CheckTreeState<Identifier>where
Identifier: RefUnwindSafe,
impl<Identifier> Send for CheckTreeState<Identifier>where
Identifier: Send,
impl<Identifier> Sync for CheckTreeState<Identifier>where
Identifier: Sync,
impl<Identifier> Unpin for CheckTreeState<Identifier>where
Identifier: Unpin,
impl<Identifier> UnwindSafe for CheckTreeState<Identifier>where
Identifier: UnwindSafe,
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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request