Collapsible

按需展开或收起内容。

实时预览

正在加载预览…

参数配置

全部字段 7

CollapsibleOptions

Styles · 0

Go 代码

Go
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
nui.Collapsible(c.Key("collapsible"), t, &s.Open, nui.CollapsibleOptions{Label: "Advanced settings", Disabled: false, KeepMounted: false}, func(t nui.Theme) { ui.Text(c, "The hidden section is now expanded.") })

使用说明

点击标题展开或收起内容,比较 Disabled 与 KeepMounted。打开状态独立持久保存;保留挂载与保留业务数据是两件事,业务数据仍应由应用持有。

API 参考

Collapsible

源码
func Collapsible(c *ui.Context, t Theme, open *bool, o CollapsibleOptions, content func(Theme)) ui.Element

CollapsibleOptions

源码
type CollapsibleOptions struct {
	Label                 string
	Icon                  *ui.SVG
	Disabled, KeepMounted bool
	OnChange              func(bool)
	Decoration
}
字段类型说明
Labelstring

Go 零值: ""

控件标签或可访问名称。

Icon*ui.SVG

Go 零值: nil

组件使用的 SVG 图标。

Disabledbool

Go 零值: false

禁用组件及其交互。

KeepMountedbool

Go 零值: false

隐藏时保留内容及其控件状态。

OnChangefunc(bool)

Go 零值: nil

值发生变化时通知应用的回调。

UIStyles

Go 零值: zero value

以部件名称为键覆盖外观和间距。

Stylefunc(Slot, ui.Element)

Go 零值: nil

同步配置当前构建的部件;不要保留 Element。