Skip to main content

TreeNav

Struct TreeNav 

Source
pub struct TreeNav { /* private fields */ }
Expand description

Tree navigation with collapsible sections

Handles navigation logic for hierarchical tree structures where parent nodes can be collapsed to hide their children.

§Example

let mut nav = TreeNav::new();
nav.add_item(TreeItem::new(0).collapsible());  // Section
nav.add_item(TreeItem::new(1).with_parent(0)); // Child
nav.add_item(TreeItem::new(2).with_parent(0)); // Child

nav.next();  // Move to next visible item
nav.toggle_collapse();  // Collapse/expand current item

Implementations§

Source§

impl TreeNav

Source

pub fn new() -> Self

Create a new empty tree navigation

Source

pub fn add_item(&mut self, item: TreeItem)

Add an item to the tree

Source

pub fn clear(&mut self)

Clear all items

Source

pub fn selected(&self) -> usize

Get current selection

Source

pub fn selected_row(&self) -> usize

Get current row within selected item

Source

pub fn is_collapsed(&self, id: usize) -> bool

Check if an item is collapsed

Source

pub fn is_visible(&self, id: usize) -> bool

Check if an item is visible (not hidden by collapsed parent)

Source

pub fn visible_items(&self) -> Vec<&TreeItem>

Get visible items

Source

pub fn next(&mut self)

Move to next visible item

Source

pub fn prev(&mut self)

Move to previous visible item

Source

pub fn next_item(&mut self)

Move to next item (skip rows within item)

Source

pub fn prev_item(&mut self)

Move to previous item (skip rows within item)

Source

pub fn toggle_collapse(&mut self)

Toggle collapse state of current item

Source

pub fn collapse(&mut self)

Collapse current item

Source

pub fn expand(&mut self)

Expand current item

Source

pub fn collapse_all(&mut self)

Collapse all collapsible items

Source

pub fn expand_all(&mut self)

Expand all items

Source

pub fn select(&mut self, id: usize)

Set selection by id

Source

pub fn first(&mut self)

Go to first visible item

Source

pub fn last(&mut self)

Go to last visible item

Source

pub fn get_prefix(&self, id: usize) -> (String, bool)

Get tree prefix for an item

Automatically calculates the correct prefix based on item’s position in the tree hierarchy.

§Arguments
  • id - Item id to get prefix for
§Returns

Tuple of (prefix_string, is_last)

Source

pub fn is_last_sibling(&self, id: usize) -> bool

Check if item is the last visible sibling at its level

Source

pub fn render_items(&self) -> Vec<(&TreeItem, String, bool)>

Get all visible items with their prefixes for rendering

Returns Vec of (item_ref, prefix_string, is_selected)

Trait Implementations§

Source§

impl Default for TreeNav

Source§

fn default() -> Self

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