Sender 对话输入框
AI 对话组件。公开入口:Sender。
在线演示
本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。
Sender 对话输入框 · 在线体验真实 Go 组件
在独立页面打开 ↗示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.Sender
go
func Sender(c *Context, val *string) *SenderWSender adds a chat input bound to *val. Read Submitted each frame and clear *val after sending:
s := ui.Sender(c, &draft).Loading(busy).Commands(cmds)
if s.Submitted() { send(draft); draft = "" }
if s.Stopped() { cancel() }
返回 *SenderW,可链式调用的方法见 SenderW 方法。
SenderW 方法
ui.SenderW:SenderW is the chat input: an auto-growing multi-line editor where Enter sends and Shift+Enter inserts a line break, with an attachment strip, @ / command suggestions, a toolbar and a send / stop button.
| 方法 | 说明 | 签名 |
|---|---|---|
A11yLabel | A11yLabel sets the accessible name of the editor (default: placeholder). | A11yLabel(s string) *SenderW |
AttachButton | AttachButton shows a paperclip button in the toolbar (see AttachClicked; the application opens its file dialog). | AttachButton() *SenderW |
AttachClicked | AttachClicked reports a click on the attach button. | AttachClicked() bool |
Attachments | Attachments shows *files as removable chips above the editor; a click on a chip's remove button deletes it from the slice (see Removed). | Attachments(files *[]ChatAttachment) *SenderW |
AutoSize | AutoSize sets the visible rows the editor grows between (default 1..8). | AutoSize(minRows, maxRows int) *SenderW |
Changed | Changed reports an edit of the text this frame. | Changed() bool |
Commands | Commands suggests opts after '/' (shown as "/value label"). | Commands(opts []Option) *SenderW |
Disabled | Disabled disables the whole input. | Disabled(on bool) *SenderW |
Header | Header adds content at the top of the input (quoted message, context chips). | Header(fn func()) *SenderW |
ID | ID returns the editor's ID (focus it with c.SetFocus). | ID() ID |
Layout | Layout applies layout options to the outer frame. | Layout(opts ...layout.Option) *SenderW |
Loading | Loading shows the stop button instead of the send button; Enter does not send and Escape (or the button) reports Stopped. | Loading(on bool) *SenderW |
MaxLength | MaxLength limits the number of characters. | MaxLength(n int) *SenderW |
Mentions | Mentions suggests opts after '@' (filtered by what follows it). | Mentions(opts []Option) *SenderW |
Picked | Picked returns the suggestion inserted this frame and its prefix. | Picked() (prefix string, o Option, ok bool) |
Placeholder | Placeholder replaces the default placeholder. | Placeholder(s string) *SenderW |
Removed | Removed returns the index of the attachment removed this frame. | Removed() (int, bool) |
Stopped | Stopped reports a click on the stop button (or Escape) while loading. | Stopped() bool |
Submitted | Submitted reports Enter or a click on the send button with something to send (text or attachments). | Submitted() bool |
Suggest | Suggest opens a suggestion list when prefix is typed at the start of the text or after a space; src returns the options for the text typed after it so far. | Suggest(prefix string, src func(query string) []Option) *SenderW |
Toolbar | Toolbar adds controls to the start of the bottom row (model select, mode switch …); the send button stays at the end. | Toolbar(fn func()) *SenderW |
相关链接
本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。