Skip to main content

Module tree

Module tree 

Source
Expand description

Foldable tree widget — a hierarchical, scrollable, focusable list.

Like crate::list, the widget itself is stateless about your data: the caller owns the tree and its expand/collapse state, flattens the visible nodes into a Vec<TreeRow> each frame (skipping children of collapsed branches), and passes that slice in. TreeState only tracks selection and scroll offset over those visible rows.

┌─ Targets ──────────────────────────────────────────────────┐
│ ▾ services/api/Makefile                                     │
│     build    Build the api                                  │
│   ▶ run      Run locally                          PORT       │
│ ▸ web/build.mk                              (collapsed)      │
└─────────────────────────────────────────────────────────────┘

§Usage

// 1. Flatten your tree to visible rows (respecting collapsed branches):
let rows: Vec<TreeRow> = visible_nodes.iter().map(|n| {
    if n.is_branch {
        TreeRow::branch(n.depth, n.label.clone(), n.expanded)
    } else {
        TreeRow::leaf(n.depth, n.label.clone())
    }
}).collect();

// 2. Render, and map state.selected back to your node on Enter.
render_tree(f, area, "Targets", None, &rows, &mut tree_state, focused, &theme);

Structs§

TreeRow
One visible row of a tree.
TreeState
Selection + scroll state for a render_tree widget, over the slice of currently-visible rows.

Functions§

render_tree
Render a scrollable, focusable tree of rows inside area.