pub struct TreeRow<K, T> {
pub key: K,
pub item: T,
pub depth: usize,
pub has_children: Option<bool>,
}Expand description
One row the app hands to a TreeDataSlice, in document (pre-)order.
depth is the indent level (0 = a root). The engine derives each row’s
parent, children, and structural depth from the depth sequence: a row’s
parent is the nearest preceding row with a strictly smaller depth. The row
stream must be well-formed pre-order (a parent precedes its subtree) — the
shape any indent-stored outline already has.
Fields§
§key: KThe row’s stable domain identity (entity id, tagged key, …). Must be stable across reloads for expand-state and divergence to survive.
item: TThe row’s display payload.
depth: usizeIndent level; 0 is a root.
has_children: Option<bool>Declares that this row has children the source has not emitted.
Unset (None) is the ordinary case and the historical behaviour: whether a
row has children is derived structurally, from whether any row in the stream
names it as parent. That is right for a source that always hands over the
whole tree, which is what most of them do.
It is a deadlock for a source that wants to materialise a branch only when it
is opened. Such a source emits no children until the row is expanded, so the
row is derived childless, so no chevron is drawn, so there is nothing to
click, so it is never expanded. StandardTreeItem::on_toggle exists to hang
exactly that kind of load off, and without this the callback can never fire.
Set it to Some(true) to promise children that are not there yet: the row
draws its chevron, the toggle reaches the app, and the app re-sources with the
branch filled in. Some(false) promises the opposite — a leaf, even if the
stream happens to contain rows beneath it.
⚠ It is a promise, not a projection. A row that claims children and then produces none on expand opens onto nothing, and the tree cannot detect that for you.
Implementations§
Source§impl<K, T> TreeRow<K, T>
impl<K, T> TreeRow<K, T>
Sourcepub fn new(key: K, item: T, depth: usize) -> Self
pub fn new(key: K, item: T, depth: usize) -> Self
Convenience constructor, leaving has_children to be derived from the
stream — see the field, and with_children for the
case where it cannot be.
Sourcepub fn with_children(self, has_children: bool) -> Self
pub fn with_children(self, has_children: bool) -> Self
Declare whether this row has children, rather than letting the stream say.
For a source that materialises a branch on expand. See
has_children for why a lazy source cannot work
without it.