主机目录#
分组 disclosure 与叶子内容使用独立稳定 ID。
hosts := components.BeginTree(canvas, theme, bounds).RowHeight(rowHeight)
group := components.TreeItem{
ID: tree.ID(page, "group"), DisclosureID: tree.ID(page, "disclosure"),
Label: "Production", Branch: true, Expanded: expanded,
}
hosts.Item(group)
if canvas.Clicked(group.DisclosureID) { expanded = !expanded }
if expanded {
hosts.Item(components.TreeItem{ID: tree.ID(page, "gateway"), Label: "Gateway", Depth: 1})
hosts.Item(components.TreeItem{ID: tree.ID(page, "database"), Label: "Database", Depth: 1})
hosts.Item(components.TreeItem{ID: tree.ID(page, "worker"), Label: "Worker", Depth: 1})
}选择状态#
点击主机行切换调用方持有的当前项。
hosts := components.BeginTree(canvas, theme, bounds)
hosts.Item(components.TreeItem{
ID: tree.ID(page, "group"), DisclosureID: tree.ID(page, "disclosure"),
Label: "Production", Branch: true, Expanded: true,
})
for index, name := range [...]string{"Gateway", "Database", "Worker"} {
id := tree.ID(page, name)
hosts.Item(components.TreeItem{
ID: id, Label: name, Depth: 1, Selected: selected == index,
})
if canvas.Clicked(id) { selected = index }
}禁用分支#
保留层级和语义,但分组与叶子均不可交互。
hosts := components.BeginTree(canvas, theme, bounds)
hosts.Item(components.TreeItem{
ID: tree.ID(page, "group"), DisclosureID: tree.ID(page, "disclosure"),
Label: "Production", Branch: true, Expanded: true, Disabled: true,
})
for _, name := range [...]string{"Gateway", "Database", "Worker"} {
hosts.Item(components.TreeItem{
ID: tree.ID(page, name), Label: name, Depth: 1, Disabled: true,
})
}安装
将组件源码复制到自己的项目,直接修改。
go run ./cmd/viva add --out ./components/local tree源码组件用法#
此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。
- 标题旁的源码链接列出了全部选项与视觉决策。
- 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
- 浏览器预览验证共享布局和场景行为,不代表原生性能。
验证边界#
示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。
键盘操作
Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。