Components / data
TreeGrid builder
A product-neutral, caller-owned virtualized treegrid adapter.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::data::TreeGrid;
Reviewed in tree-grid.
Construct
new(ident: impl Into<Ident>, visible_row_count: usize, render_row: impl Fn(usize, &mut Window, &mut App) -> TreeGridRow + 'static) -> Self
Options
Chain onto the value.
column(column: GridColumn) -> Self
columns(columns: impl IntoIterator<Item = GridColumn>) -> Self
selected(id: impl Into<SharedString>) -> Self
visible_rows(rows: usize) -> Self
row_height(height: f32) -> Self
lines(lines: GridLines) -> Self
loading(loading: bool) -> Self
failure(detail: impl Into<SharedString>) -> Self
empty(state: EmptyState) -> Self
unavailable(title: impl Into<SharedString>) -> Self
on_select(handler: impl Fn(SharedString, &mut Window, &mut App) + 'static) -> Self
on_expand(handler: impl Fn(SharedString, bool, &mut Window, &mut App) + 'static) -> Self
Example · tree-grid
fn tree_grid(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
// Whether a branch is open is structure, and the disclosure already says
// it. What belongs in a state column is what is true of the record — the
// same vocabulary, in the same pills, that `table` and `data-grid` use.
let rows = [
(
"workspace",
"Workspace",
1,
true,
true,
None,
"Ready",
Tone::Success,
),
(
"src",
"src",
2,
true,
true,
Some("workspace"),
"Ready",
Tone::Success,
),
(
"components",
"components",
3,
false,
false,
Some("src"),
"Stale",
Tone::Warning,
),
(
"lib",
"lib.rs",
3,
false,
false,
Some("src"),
"Ready",
Tone::Success,
),
(
"docs",
"docs",
2,
true,
false,
Some("workspace"),
"Refused",
Tone::Danger,
),
];
let owners = ["Platform", "Runtime", "UI systems", "Runtime", "Docs"];
let modified = ["12:42", "12:31", "11:58", "11:44", "Yesterday"];
stack(&theme)
.w(px(720.0))
.child(
TreeGrid::new("scene.tree-grid.files", rows.len(), move |index, _, _| {
let (id, name, level, branch, expanded, parent, state, tone) = rows[index];
let mut row = TreeGridRow::new(id, level)
.text(name)
.cell("name", Cell::new(name).text(name).published(true))
.cell("kind", if branch { "Folder" } else { "File" })
.cell(
"state",
Cell::new(Badge::new(state).tone(tone))
.text(state)
.published(true),
)
.cell("owner", owners[index])
.cell("modified", modified[index]);
if branch {
row = row.branch(expanded);
}
if let Some(parent) = parent {
row = row.parent(parent);
}
row
})
.columns([
GridColumn::new("name", "Name").fixed(300.0).pinned(true),
GridColumn::new("kind", "Kind").fixed(160.0),
GridColumn::new("state", "State").fixed(180.0),
GridColumn::new("owner", "Owner").fixed(200.0),
GridColumn::new("modified", "Modified").fixed(180.0),
])
.selected("components")
.visible_rows(5)
.on_select(|_, _, _| {})
.on_expand(|_, _, _, _| {}),
)
.child(
crate::foundation::text(
&theme,
TypeScale::Caption,
SharedString::from(
"Scroll right for Owner and Modified; the hierarchy remains pinned.",
),
)
.text_tone(&theme, TextTone::Muted),
)
.into_any_element()
}