BubbleList 消息流
AI 对话组件。公开入口:BubbleList。
在线演示
本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。
示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.BubbleList
func BubbleList(c *Context, n int, key func(i int) string, item func(i int), opts ...layout.Option) *BubbleListWBubbleList adds a message list of n items; key(i) must be a stable, unique key of message i (heights and widget state are kept by key) and item(i) builds it (usually a Bubble). Give the list a bounded height (Grow inside a sized parent, or layout.H).
ui.BubbleList(c, len(msgs), func(i int) string { return msgs[i].ID }, func(i int) {
ui.Bubble(c, msgs[i].Role, msgs[i].Text)
}, layout.Grow(1))
返回 *BubbleListW,可链式调用的方法见 BubbleListW 方法。
BubbleListW 方法
ui.BubbleListW:BubbleListW is a scrolling message stream that only builds the messages near the viewport (heights are measured and cached by key), keeps the bottom in view while new content streams in, and stops following when the user scrolls up, showing a "back to bottom" button instead.
| 方法 | 说明 | 签名 |
|---|---|---|
A11yLabel | A11yLabel sets the accessible name (default Locale.Chat.Messages). | A11yLabel(s string) *BubbleListW |
Following | Following reports whether the list sticks to the bottom. | Following() bool |
Gap | Gap sets the space between messages (default 8; the action row under a message reserves its own space). | Gap(px float32) *BubbleListW |
ID | ID returns the scroll container's ID. | ID() ID |
NoAutoScroll | NoAutoScroll stops following new content at the bottom. | NoAutoScroll() *BubbleListW |
Overscan | Overscan sets how far beyond the viewport messages are built, in px (default 600). | Overscan(px float32) *BubbleListW |
Padding | Padding sets the space around the messages (default 16). | Padding(px float32) *BubbleListW |
Range | Range returns the half-open range of messages built this frame. | Range() (first, end int) |
ScrollToBottom | ScrollToBottom jumps to the end and resumes following new content. | ScrollToBottom() *BubbleListW |
TopReached | TopReached reports the frame the user scrolled to the very top (load earlier messages then; the view keeps its place when they are prepended). | TopReached() bool |
相关链接
本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。