Struct CheckTreeState

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

Source

pub fn get_checked_things(&self) -> Vec<RecordId>

Get the checked things from the tree state

Source

pub fn get_selected_thing(&self) -> Option<RecordId>

Get the selected thing from the tree state

Source

pub fn handle_mouse_event( &mut self, event: MouseEvent, area: Rect, ) -> Option<Action>

Handle mouse events interacting with the tree

Assumes that the given area only includes the CheckTree

§Returns

an action if the mouse event requires it

Source§

impl<Identifier> CheckTreeState<Identifier>
where Identifier: Clone + PartialEq + Eq + Hash,

Source

pub const fn get_offset(&self) -> usize

Source

pub const fn opened(&self) -> &HashSet<Vec<Identifier>>

Source

pub fn selected(&self) -> &[Identifier]

Refers to the current cursor selection.

Source

pub const fn checked(&self) -> &HashSet<Vec<Identifier>>

Refers to the current checked items.

Source

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.

Source

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:

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn toggle(&mut self, identifier: Vec<Identifier>) -> bool

Toggles a tree node open/close state. When it is currently open, then close is called. Otherwise open.

Returns true when a node is opened / closed. As toggle always changes something, this only returns false when an empty identifier is given.

TODO: This should return false when it was a leaf node.

Source

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.

Source

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.

Source

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.

Source

pub fn reset(&mut self) -> bool

Closes all open nodes, and uncheck all checked nodes.

Returns true when any node was closed or unchecked.

Source

pub fn select_first(&mut self) -> bool

Select the first node.

Returns true when the selection changed.

Source

pub fn select_last(&mut self) -> bool

Select the last node.

Returns true when the selection changed.

Source

pub fn select_relative<F>(&mut self, change_function: F) -> bool
where F: FnOnce(Option<usize>) -> usize,

Move the current selection with the direction/amount by the given function.

Returns true when the selection changed.

For more examples take a look into the source code of key_up or key_down. They are implemented with this method.

Source

pub fn rendered_at(&self, position: Position) -> Option<&[Identifier]>

Get the identifier that was rendered for the given position on last render.

Source

pub const fn scroll_selected_into_view(&mut self)

Ensure the selected CheckTreeItem is in view on next render

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> CheckTreeState<Identifier>

Returns a copy 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<Identifier: Debug> Debug for CheckTreeState<Identifier>

Source§

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

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

impl<Identifier: Default> Default for CheckTreeState<Identifier>

Source§

fn default() -> CheckTreeState<Identifier>

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

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> 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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more