Skip to main content

Module tree_view

Module tree_view 

Source
Expand description

TreeView — a virtualized, expandable/collapsible hierarchical list widget.

Displays a TreeModel<T> as an indented tree. Internally each view owns a TreeSlice for independent expand state, so two TreeViews on the same model can be open at different depths simultaneously. Only rows in the visible viewport + a small buffer have live widgets — rows outside the buffer are dormant, matching ListView’s virtualization model. An external TreeDataSource is also accepted via TreeView::from_source when the data lives outside a TreeModel.

Row heights come in three modes: uniform (item_height, default fast path), exact per-flat-index callback (item_height_fn), and auto-measured (auto_item_height — height-for-width per row, scroll-anchored).

§Example

let _w = TreeView::new(tree_model, |item, entry, _selected| {
    let indent = entry.depth as f32 * 20.0;
    Box::new(HStack::new()
        .child(Padding::new(0.0, 0.0, 0.0, indent))
        .child(TextWidget::new(lit!(&item.title))))
})
.item_height(28.0);

Structs§

TreeRowContext
Per-row context passed to a 4-arg TreeView delegate. Carries a reference to the slice handle and the row’s NodeId so the delegate can wire chevron toggles and other tree-aware behavior without manually cloning state outside the closure.
TreeView