Carousel走马灯
查看源码components/carousel.go水平轮播#
前后按钮只改变调用方持有的当前索引。
previous, next := tree.ID(page, "previous"), tree.ID(page, "next")
carousel := components.BeginCarousel(canvas, theme, bounds, 3, state.carousel).
Content(bounds.Width*3, float32(state.carousel)*bounds.Width).
Controls(previous, "Previous slide", next, "Next slide")
carousel.BeginContent()
// Paint each slide at carousel.ItemGeometry(i, offset, bounds.Width).Bounds.
carousel.EndContent()
if canvas.Clicked(previous) && state.carousel > 0 {
state.carousel--
} else if canvas.Clicked(next) && state.carousel < 2 {
state.carousel++
}垂直轮播#
相同几何模型切换为纵向内容轴。
previous, next := tree.ID(page, "previous"), tree.ID(page, "next")
carousel := components.BeginCarousel(canvas, theme, bounds, 3, state.carousel).
Content(bounds.Height*3, float32(state.carousel)*bounds.Height).
Controls(previous, "Previous slide", next, "Next slide").Vertical()
carousel.BeginContent()
// Slides lay out down the content axis; ItemGeometry maps each one.
carousel.EndContent()
if canvas.Clicked(previous) && state.carousel > 0 {
state.carousel--
} else if canvas.Clicked(next) && state.carousel < 2 {
state.carousel++
}安装
将组件源码复制到自己的项目,直接修改。
go run ./cmd/viva add --out ./components/local carousel源码组件用法#
此预览直接调用生产 Go 组件。稳定 ID、值与打开状态仍由应用持有;组件只负责绘制并声明交互语义。
- 标题旁的源码链接列出了全部选项与视觉决策。
- 请使用原生命令验证系统文本、焦点、无障碍与平台集成。
- 浏览器预览验证共享布局和场景行为,不代表原生性能。
验证边界#
示例覆盖当前 API 的代表性状态,但不表示每个桌面后端都已完成真机验证。
键盘操作
Tab 在控件间移动;Ctrl/⌘ K 搜索组件。进入预览后,键盘事件由 Go 运行时处理。