Skip to content

BubbleList 消息流 ​

AI 对话组件。公开入口:BubbleList。

在线演示 ​

本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。

BubbleList 消息流 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

BubbleList 消息流

gallery 演示 BubbleList 的具名 Render 函数,源码 page_chat.go#L145。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

ui.BubbleList ​

go
func BubbleList(c *Context, n int, key func(i int) string, item func(i int), opts ...layout.Option) *BubbleListW

BubbleList 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.

方法说明签名
A11yLabelA11yLabel sets the accessible name (default Locale.Chat.Messages).A11yLabel(s string) *BubbleListW
FollowingFollowing reports whether the list sticks to the bottom.Following() bool
GapGap sets the space between messages (default 8; the action row under a message reserves its own space).Gap(px float32) *BubbleListW
IDID returns the scroll container's ID.ID() ID
NoAutoScrollNoAutoScroll stops following new content at the bottom.NoAutoScroll() *BubbleListW
OverscanOverscan sets how far beyond the viewport messages are built, in px (default 600).Overscan(px float32) *BubbleListW
PaddingPadding sets the space around the messages (default 16).Padding(px float32) *BubbleListW
RangeRange returns the half-open range of messages built this frame.Range() (first, end int)
ScrollToBottomScrollToBottom jumps to the end and resumes following new content.ScrollToBottom() *BubbleListW
TopReachedTopReached 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)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。

以 MIT 许可发布