use ui::tree::{self, Direction, Move};
// self.rows: Vec<Row>, the rows visible now, flattened by the app
tree::tree().children(self.rows.iter().enumerate().map(|(index, row)| {
tree::tree_row(&theme, row, self.selected == Some(index), self.cursor == index)
.id(("row", index))
.child(self.labels[index].clone())
}))
// on tree::Expand:
match tree::step(&self.rows, self.cursor, Direction::Right) {
Some(Move::To(index)) => self.cursor = index,
Some(Move::Expand(index) | Move::Collapse(index)) => self.toggle(index),
None => {}
}- Call
tree::init(cx)once at startup. - The app flattens its tree and owns the expansion set;
steponly reports aMove. - Put
.key_context(tree::KEY_CONTEXT), focus tracking and handlers forSelectPrevious,SelectNext,CollapseandExpandon the element holding the rows. - Scrolling is the caller's, through
scroll.