Skip to main content

Tree

Struct Tree 

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

Tree widget for rendering hierarchical data.

Implementations§

Source§

impl Tree

Source

pub fn new(root: TreeNode) -> Self

Create a tree widget with the given root node.

Source

pub fn with_show_root(self, show: bool) -> Self

Set whether to show the root node.

Source

pub fn with_guides(self, guides: TreeGuides) -> Self

Set the guide character style.

Source

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

Set the style for guide characters.

Source

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

Set the style for node labels.

Source

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

Set the style for the root label.

Source

pub fn with_persistence_id(self, id: impl Into<String>) -> Self

Set a persistence ID for state saving.

Source

pub fn persistence_id(&self) -> Option<&str>

Get the persistence ID, if set.

Source

pub fn hit_id(self, id: HitId) -> Self

Set a hit ID for mouse interaction.

Source

pub fn root(&self) -> &TreeNode

Get a reference to the root node.

Source

pub fn root_mut(&mut self) -> &mut TreeNode

Get a mutable reference to the root node.

Source§

impl Tree

Source

pub fn undo_id(&self) -> UndoWidgetId

Get the undo widget ID for this tree.

Source

pub fn handle_mouse( &mut self, event: &MouseEvent, hit: Option<(HitId, HitRegion, u64)>, expected_id: HitId, ) -> MouseResult

Handle a mouse event for this tree.

§Hit data convention

The hit data (u64) encodes the flattened visible row index. When the tree renders with a hit_id, each visible row registers HitRegion::Content with data = visible_row_index as u64.

Clicking a parent node (one with children) toggles its expanded state and returns Activated. Clicking a leaf returns Selected.

§Arguments
  • event — the mouse event from the terminal
  • hit — result of frame.hit_test(event.x, event.y), if available
  • expected_id — the HitId this tree was rendered with
Source

pub fn node_at_visible_index_mut( &mut self, target: usize, ) -> Option<&mut TreeNode>

Get a mutable reference to the node at the given visible (flattened) index.

The traversal order matches render_node(): if show_root is true the root is row 0; otherwise children of the root are the top-level rows. Only expanded nodes’ children are visited.

Trait Implementations§

Source§

impl Clone for Tree

Source§

fn clone(&self) -> Tree

Returns a duplicate 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 Debug for Tree

Source§

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

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

impl Stateful for Tree

Source§

type State = TreePersistState

The state type that gets persisted. Read more
Source§

fn state_key(&self) -> StateKey

Unique key identifying this widget instance. Read more
Source§

fn save_state(&self) -> TreePersistState

Extract current state for persistence. Read more
Source§

fn restore_state(&mut self, state: TreePersistState)

Restore state from persistence. Read more
Source§

fn state_version() -> u32

State schema version for forward-compatible migrations. Read more
Source§

impl TreeUndoExt for Tree

Source§

fn is_node_expanded(&self, path: &[usize]) -> bool

Check if a node is expanded.
Source§

fn expand_node(&mut self, path: &[usize])

Expand a node.
Source§

fn collapse_node(&mut self, path: &[usize])

Collapse a node.
Source§

impl UndoSupport for Tree

Source§

fn undo_widget_id(&self) -> UndoWidgetId

Get the widget’s unique ID for undo tracking.
Source§

fn create_snapshot(&self) -> Box<dyn Any + Send>

Create a snapshot of the current state for undo purposes. Read more
Source§

fn restore_snapshot(&mut self, snapshot: &dyn Any) -> bool

Restore state from a snapshot. Read more
Source§

impl Widget for Tree

Source§

fn render(&self, area: Rect, frame: &mut Frame<'_>)

Render the widget into the frame at the given area. Read more
Source§

fn is_essential(&self) -> bool

Whether this widget is essential and should always render. Read more

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl RefUnwindSafe for Tree

§

impl Send for Tree

§

impl Sync for Tree

§

impl Unpin for Tree

§

impl UnsafeUnpin for Tree

§

impl UnwindSafe for Tree

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