Skip to main content

Module tree

Module tree 

Source
Expand description

Tree view — nested rows with disclosure, indent guides and arrow keys.

bezel cannot walk your tree. It has no idea what a node is, and a trait or a callback to find out would be a data model this library does not want to own — so the app flattens its own tree into the rows that are visible right now, which it has to do anyway to render them.

That is not a compromise, because a depth-annotated flat list is a complete navigation model. Everything a tree does falls out of Row with no parent pointers and no tree walk: down and up are neighbouring indices, a first child is simply the next row, and a parent is the nearest row above with a smaller depth. step is that, and nothing else.

ui::tree::init(cx);   // once, at startup

// Each frame: flatten what is open, paint it, and let `step` answer the keys.
let rows = self.flatten();                       // Vec<(Row, label)>
tree().children(rows.iter().enumerate().map(|(index, (row, label))| {
    tree_row(&theme, row, self.selected == Some(index), self.cursor == index)
        .id(("row", index))
        .child(label.clone())
}))

Expansion stays with the app because it is app data — a file tree’s open folders often outlive the window — so step reports an intent, and the app applies it to the set it owns.

Structs§

Collapse
Expand
Row
One visible row: how deep it sits, and whether it is a branch.
SelectNext
SelectPrevious

Enums§

Direction
Move
What a keypress meant. An intent rather than a mutation: only the app can expand a row, because only the app knows what is under it.

Constants§

INDENT
How far one level of nesting indents.
KEY_CONTEXT
The key context a tree claims.

Functions§

init
Bind the arrows. Call once, alongside crate::input::init.
parent_of
The row index hangs under: the nearest row above it with a smaller depth.
step
What an arrow key means at cursor, or None when it means nothing.
tree
The container. Rows go in it; scrolling is the caller’s, via crate::scroll.
tree_row
One row: its guides, its chevron, and then whatever the caller puts in it.