Table表格
查看源码components/table.go账单列表#
表头、三行数据、页脚与说明文字。
rows := tree.Sub(page, tree.Name("row"))
table := components.BeginTable(canvas, theme, bounds, columns)
table.Header([]string{"Item", "Status", "Amount"})
for index, cells := range bills {
table.Row(rows.At(index), cells[:], false)
}
table.Footer([]string{"Total", "3 items", "¥ 4,540"})
table.Caption("Click any data row to see its interactive feedback.")选择状态#
点击稳定行 ID 切换调用方持有的选择位。
rows := tree.Sub(page, tree.Name("row"))
table := components.BeginTable(canvas, theme, bounds, columns)
table.Header([]string{"Item", "Status", "Amount"})
for index, cells := range bills {
selected := flags&(1<<index) != 0
if table.RowAt(rows, index, cells[:], selected) {
flags ^= 1 << index
}
}
table.Footer([]string{"Total", "3 items", "¥ 4,540"})列对齐#
左、中、右三种列内文字对齐。
columns := []components.TableColumn{
{Width: 112, Alignment: components.TableAlignLeft},
{Width: 88, Alignment: components.TableAlignCenter},
{Alignment: components.TableAlignRight},
}
table := components.BeginTable(canvas, theme, bounds, columns)
table.Header([]string{"Item", "Status", "Amount"})
for _, cells := range bills {
table.Row(ui.ID{}, cells[:], false)
}
table.Caption("Item is left-aligned, status centered, amount right-aligned.")溢出与表头#
放不下的单元格以省略号结尾;FitTableHeadings 让定宽列至少放得下自己的表头。
columns := []components.TableColumn{{Width: 96}, {Width: 40}, {Alignment: components.TableAlignRight}}
headings := []string{"Item", "Status", "Amount"}
components.FitTableHeadings(canvas, theme, columns, headings)
table := components.BeginTable(canvas, theme, bounds, columns)
table.Header(headings)
for _, cells := range bills {
table.Row(ui.ID{}, cells[:], false)
}
table.Caption("Item is cut with an ellipsis; Status grew to hold its heading.")安装
将组件源码复制到自己的项目,直接修改。
go run ./cmd/viva add --out ./components/local table源码组件用法#
此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。
- 标题旁的源码链接列出了全部选项与视觉决策。
- 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
- 浏览器预览验证共享布局和场景行为,不代表原生性能。
验证边界#
示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。
键盘操作
Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。