Bubble 对话气泡
AI 对话组件。公开入口:Bubble。
在线演示
本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。
Bubble 对话气泡 · 在线体验真实 Go 组件
在独立页面打开 ↗示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.Bubble
go
func Bubble(c *Context, role ChatRole, content string) *BubbleWBubble adds a chat message of role with content (Markdown for the assistant, plain text for the user; see Markdown/Plain).
ui.Bubble(c, ui.ChatAssistant, reply).Typing(streaming).Actions(ui.BubbleCopy | ui.BubbleRetry)
返回 *BubbleW,可链式调用的方法见 BubbleW 方法。
BubbleW 方法
ui.BubbleW:BubbleW is one chat message: avatar, optional name, content and actions.
| 方法 | 说明 | 签名 |
|---|---|---|
Actions | Actions shows the built-in action buttons under the bubble. | Actions(a BubbleAction) *BubbleW |
ActionsAlways | ActionsAlways keeps the action buttons visible (the last answer). | ActionsAlways() *BubbleW |
Avatar | Avatar replaces the default avatar with custom content. | Avatar(fn func()) *BubbleW |
AvatarIcon | AvatarIcon sets the icon of the default avatar. | AvatarIcon(ic *icon.Icon) *BubbleW |
AvatarText | AvatarText shows initials in the default avatar. | AvatarText(s string) *BubbleW |
ClickedLink | ClickedLink returns the URL of a Markdown link clicked this frame. | ClickedLink() string |
Copied | Copied reports that the copy action put the content on the clipboard this frame. | Copied() bool |
Edited | Edited returns the new text when an in-place edit was saved this frame. | Edited() (string, bool) |
Editing | Editing reports whether the in-place editor is open. | Editing() bool |
Extra | Extra adds content under the bubble (tool cards, thought chains, attachments, custom actions). | Extra(fn func()) *BubbleW |
ID | ID returns the message row's ID. | ID() ID |
Layout | Layout applies layout options to the message row. | Layout(opts ...layout.Option) *BubbleW |
Loading | Loading shows animated dots while the content is still empty. | Loading(on bool) *BubbleW |
Markdown | Markdown renders the content as Markdown (default for the assistant). | Markdown() *BubbleW |
Meta | Meta shows a footer text after the actions (time, model, tokens). | Meta(s string) *BubbleW |
Name | Name shows the author's name above the bubble (also its accessible name). | Name(s string) *BubbleW |
NoAvatar | NoAvatar hides the avatar column. | NoAvatar() *BubbleW |
Plain | Plain renders the content as plain text keeping line breaks (default for the user and system). | Plain() *BubbleW |
Retried | Retried reports a click on the retry action. | Retried() bool |
Typing | Typing marks the content as still streaming: it is revealed at TypingSpeed (catching up quickly when far behind) with a caret at the end. | Typing(on bool) *BubbleW |
TypingSpeed | TypingSpeed sets the reveal speed in characters per second (default 60). | TypingSpeed(cps float32) *BubbleW |
Variant | Variant sets the look (default BubbleAuto). | Variant(v BubbleVariant) *BubbleW |
相关链接
本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。