Skip to main content

Module tree

Module tree 

Source
Expand description

A hierarchy whose open branches are caller-owned.

The tree reports the node that was activated and the state its disclosure should take next. It renders exactly the set the caller passed to Tree::expanded, so a host that refuses to open a branch leaves it shut.

A collapsed node renders none of its children, and publishes none of them either, so asserting that a child is absent means something.

§What a large hierarchy costs

What is on screen depends on what is open, so the tree first flattens the hierarchy to the rows a reader could see and then draws from that. With Tree::visible_rows it draws only the ones that fit, so a hierarchy with ten thousand disclosed rows lays out a viewport’s worth. Without it the tree sizes itself to its content and every disclosed row is laid out.

Flattening still walks the whole hierarchy each frame, because the caller hands the tree the nodes rather than a way to ask for one. That is data, not elements: a TreeNode holds two strings, an element holds a layout.

The tree’s semantic node carries the number of disclosed rows in value, which is what keeps three different absences apart: a node under a shut branch is not disclosed, a disclosed node outside the viewport is counted but not published, and a node that is not in the data at all is neither.

A bounded tree can draw a node whose parent has scrolled off the top. The node still reports the parent it has, because that is what is true of it, so a walk down from the tree’s own node will not reach it and a test that wants it should name it. Its level says how deep it sits either way.

Structs§

Tree
A disclosure hierarchy.
TreeNode
One node, identified by business identity rather than by its place in the hierarchy, so moving a branch does not rename what hangs under it.