Generic tree-view widget. Renders a collapsible hierarchy as a flat list of rows, one per visible node.
The widget is structure-agnostic: apps describe their own tree by implementing Tree.Children (or supplying a function), label nodes via a render callback, and own the expanded / selected state. The widget walks the structure each frame and produces the visible row list — no internal state, no in-place mutation.
Indentation. Each level adds two cells of left padding so ancestor relationships are visually obvious. Override with indentWidth.
Markers. Internal nodes (those with children) get a + (collapsed, "click to open") or - (expanded, "click to collapse") glyph, three columns wide ([+] / [-]). Leaves get four spaces of leading padding. The unicode flag is kept for backwards compatibility but no longer changes the glyph since + / - are already ASCII.
Selection. The row at selectedIndex (an index into the visible row list) is highlighted in the theme's primary slot, bolded.
Identity. Apps decide what an "expanded" node is via Tree.Children.id (a stable key) and a Set[Id] of expanded ids. Re-using the same id across frames is what keeps state stable as the tree changes shape.
Map a click (col, row) to a HitResult over the rendered row list.
Map a click (col, row) to a HitResult over the rendered row list.
The chevron region is the column span occupied by the [+] / [-] glyph (skipped for leaves since they have no toggle). Apps pre-compute rows = Tree.visibleRows(...) once per frame and pass it in alongside the same at / indentWidth they used to render.
Returns None for clicks outside any rendered row.
Value parameters
at
Top-left of the first row (mirrors the rendering call).
col
Click column (1-based, absolute).
indentWidth
Cells per depth level (mirrors the rendering call).
labelLength
Maximum label width for the click target. Pass Int.MaxValue if rows can be any length.
Walk the tree honouring the expanded set; produce the flat row list the widget renders. Public so apps can pre-compute it (e.g. for click-to-row mapping outside the widget itself).
Walk the tree honouring the expanded set; produce the flat row list the widget renders. Public so apps can pre-compute it (e.g. for click-to-row mapping outside the widget itself).