pub struct TreeState<Identifier> { /* private fields */ }
Expand description

Keeps the state of what is currently selected and what was opened in a Tree.

The generic argument Identifier is used to keep the state like the currently selected or opened TreeItems in the TreeState. For more information see TreeItem.

§Example

type Identifier = usize;

let mut state = TreeState::<Identifier>::default();

Implementations§

source§

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

source

pub const fn get_offset(&self) -> usize

source

pub fn get_all_opened(&self) -> Vec<Vec<Identifier>>

source

pub fn flatten<'a>( &self, items: &'a [Item<'a, Identifier>] ) -> Vec<Flattened<'a, Identifier>>

Get a flat list of all visible (= below open) TreeItems with this TreeState.

source

pub fn selected(&self) -> Vec<Identifier>

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:

state.select(Vec::new());
source

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

Open a tree node. Returns true if the node was closed and has been opened. Returns false if the node was already open.

source

pub fn close(&mut self, identifier: &[Identifier]) -> bool

Close a tree node. Returns true if the node was open and has been closed. Returns false if the node was already closed.

source

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

Toggles a tree node. If the node is in opened then it calls close. Otherwise it calls open.

source

pub fn toggle_selected(&mut self)

Toggles the currently selected tree node. See also toggle

source

pub fn close_all(&mut self)

source

pub fn select_first(&mut self, items: &[Item<'_, Identifier>]) -> bool

Select the first node.

Returns true when the selection changed.

source

pub fn select_last(&mut self, items: &[Item<'_, Identifier>]) -> bool

Select the last visible node.

Returns true when the selection changed.

source

pub fn select_visible_index( &mut self, items: &[Item<'_, Identifier>], new_index: usize ) -> bool

Select the node visible on the given index.

Returns true when the selection changed.

This can be useful for mouse clicks.

source

pub fn select_visible_relative<F>( &mut self, items: &[Item<'_, Identifier>], 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.

§Example
// Move the selection one down
state.select_visible_relative(&items, |current| {
    current.map_or(0, |current| current.saturating_add(1))
});

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 scroll_selected_into_view(&mut self)

Ensure the selected TreeItem is visible on next render

source

pub fn scroll_up(&mut self, lines: usize)

Scroll the specified amount of lines up

source

pub fn scroll_down(&mut self, lines: usize)

Scroll the specified amount of lines down

source

pub fn key_up(&mut self, items: &[Item<'_, Identifier>])

Handles the up arrow key. Moves up in the current depth or to its parent.

source

pub fn key_down(&mut self, items: &[Item<'_, Identifier>])

Handles the down arrow key. Moves down in the current depth or into a child node.

source

pub fn key_left(&mut self)

Handles the left arrow key. Closes the currently selected or moves to its parent.

source

pub fn key_right(&mut self)

Handles the right arrow key. Opens the currently selected.

Trait Implementations§

source§

impl<Identifier: Clone> Clone for State<Identifier>

source§

fn clone(&self) -> State<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 State<Identifier>

source§

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

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

impl<Identifier: Default> Default for State<Identifier>

source§

fn default() -> State<Identifier>

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

Auto Trait Implementations§

§

impl<Identifier> RefUnwindSafe for State<Identifier>
where Identifier: RefUnwindSafe,

§

impl<Identifier> Send for State<Identifier>
where Identifier: Send,

§

impl<Identifier> Sync for State<Identifier>
where Identifier: Sync,

§

impl<Identifier> Unpin for State<Identifier>
where Identifier: Unpin,

§

impl<Identifier> UnwindSafe for State<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> 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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.