Skip to content

Component Tree

MeowLynxSea edited this page Jun 13, 2026 · 8 revisions

Tree

A tree view. Carries the TreeData model and the current expanded / selected ids. Children are tree_item(...) rows; the renderer draws the connector lines and indent guides.

Import

use yororen_ui::headless::tree::tree;
use yororen_ui::headless::tree::TreeData;
use yororen_ui::headless::tree::node_id;

Minimal example

use yororen_ui::headless::tree::{tree, TreeData, node_id};
use yororen_ui::headless::tree_item::tree_item;

let data = {
    let mut d = TreeData::new();
    let root = node_id("root");
    let docs = node_id("docs");
    let readme = node_id("readme");
    d.add(root.clone(), docs.clone(), "docs");
    d.add(docs.clone(), readme.clone(), "README.md");
    d
};

tree("files", cx)
    .data(data)
    .expanded(node_id("docs"))
    .selected(node_id("readme"))
    .render(cx)

Props

Method Purpose
data(d) The TreeData model.
expanded(id) The currently expanded node id. Pass an id you got from node_id("…").
selected(id) The currently selected node id.

The body of the tree is built by nested tree_item(...) calls as children of the rendered tree.

Notes

  • Factory takes (id, _cx).
  • No state entity — the parent view owns the expanded / selected ids.
  • node_id(s) is a helper that interns a &str (or String) into a TreeNodeId. It is cheap to call repeatedly.
  • .render(cx) returns Stateful<Div>.

See also

TreeItem, ListItem, VirtualRow

Clone this wiki locally