Components / data
Tree builder
A disclosure hierarchy.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::data::Tree;
Also drawn by deferred-drop reading-direction, which arranges components rather than reviewing them.
Construct
new(ident: impl Into<Ident>) -> Self
Options
Chain onto the value.
node(node: TreeNode) -> Self
nodes(nodes: impl IntoIterator<Item = TreeNode>) -> Self
expanded(ids: impl IntoIterator<Item = SharedString>) -> Self
expanded_ids<S: AsRef<str>>(ids: &[S]) -> Self
selected(id: impl Into<SharedString>) -> Self
visible_rows(rows: usize) -> Self
on_toggle(handler: impl Fn(SharedString, bool, &mut Window, &mut App) + 'static) -> Self
on_select(handler: impl Fn(SharedString, &mut Window, &mut App) + 'static) -> Self
reorderable(reorderable: bool) -> Self
accepts(predicate: impl Fn(&DragItem, &DropPosition) -> bool + 'static) -> Self
deferred_acceptance(controller: dnd::DeferredDrop, revision: u64) -> Self
on_move(handler: impl Fn(&DropIntent, &mut Window, &mut App) + 'static) -> Self
loading(loading: bool) -> Self
failure(failure: impl Into<SharedString>) -> Self
empty(empty: EmptyState) -> Self
Example · tree
fn tree(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
stack(&theme)
.w(px(360.0))
.child(
Tree::new("scene.tree.workspace")
.selected("tokens")
.nodes([
TreeNode::new("workspace", "workspace")
.icon(Icon::Folder)
.children([
TreeNode::new("crates", "crates")
.icon(Icon::Folder)
.children([
TreeNode::new("kit", "gpui-kit").icon(Icon::Document),
TreeNode::new("tokens", "gpui-kit-tokens").icon(Icon::Document),
]),
TreeNode::new("docs", "docs")
.icon(Icon::Folder)
.children([TreeNode::new("components", "components.md")
.icon(Icon::Document)]),
]),
TreeNode::new("target", "target")
.icon(Icon::Archive)
.disabled(true)
.children([TreeNode::new("debug", "debug").icon(Icon::Folder)]),
TreeNode::new("remote", "remote")
.icon(Icon::Folder)
.branch(BranchState::Loading),
// A branch the host declined to list and one whose listing
// failed are two different facts, and a reader deciding
// whether to retry needs to know which one they are
// looking at.
TreeNode::new("vault", "vault").icon(Icon::Folder).branch(
BranchState::Unavailable(
"This workspace is not permitted to read it.".into(),
),
),
TreeNode::new("archive", "archive")
.icon(Icon::Folder)
.branch(BranchState::Failed("The listing timed out.".into())),
])
.expanded_ids(&["workspace", "crates", "remote", "vault", "archive"])
.on_toggle(|_, _, _, _| {})
.on_select(|_, _, _| {}),
)
.into_any_element()
}
Source: crates/gpui-kit/src/data/tree.rs