Skip to main content

Tree

Struct Tree 

Source
pub struct Tree<T> { /* private fields */ }
Expand description

A hierarchical tree widget with expandable/collapsible nodes.

Displays a forest of TreeNodes as an indented list. Supports keyboard navigation, expand/collapse, and optional lazy loading.

Implementations§

Source§

impl<T> Tree<T>

Source

pub fn new(roots: Vec<TreeNode<T>>) -> Self

Create a new tree with the given root nodes.

Source

pub fn with_render_fn<F>(self, f: F) -> Self
where F: Fn(&T, usize, bool, bool) -> Vec<Segment> + 'static,

Set a custom render function for nodes.

Parameters: (data, depth, expanded, is_leaf) -> Segments

Source

pub fn with_node_style(self, style: Style) -> Self

Set the style for unselected nodes.

Source

pub fn with_selected_style(self, style: Style) -> Self

Set the style for the selected node.

Source

pub fn with_border(self, border: BorderStyle) -> Self

Set the border style.

Source

pub fn with_lazy_load<F>(self, f: F) -> Self
where F: Fn(&T) -> Vec<TreeNode<T>> + 'static,

Set a lazy load function for deferred child loading.

Source

pub fn roots(&self) -> &[TreeNode<T>]

Get a reference to the root nodes.

Source

pub fn selected(&self) -> usize

Get the selected visible node index.

Source

pub fn scroll_offset(&self) -> usize

Get the scroll offset.

Source

pub fn toggle_selected(&mut self)

Toggle expand/collapse at the selected node.

Source

pub fn expand_selected(&mut self)

Expand the selected node (load children lazily if needed).

Source

pub fn collapse_selected(&mut self)

Collapse the selected node.

Source

pub fn selected_node(&self) -> Option<&TreeNode<T>>

Get a reference to the data of the selected visible node.

Source

pub fn visible_count(&self) -> usize

Get the total number of visible nodes.

Trait Implementations§

Source§

impl<T> InteractiveWidget for Tree<T>

Source§

fn handle_event(&mut self, event: &Event) -> EventResult

Handle an input event. Returns whether the event was consumed.
Source§

impl<T> Widget for Tree<T>

Source§

fn render(&self, area: Rect, buf: &mut ScreenBuffer)

Render this widget into the given area of the buffer.

Auto Trait Implementations§

§

impl<T> Freeze for Tree<T>

§

impl<T> !RefUnwindSafe for Tree<T>

§

impl<T> !Send for Tree<T>

§

impl<T> !Sync for Tree<T>

§

impl<T> Unpin for Tree<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Tree<T>

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.