Switch

切换开关或选择状态。

实时预览

正在加载预览…

参数配置

全部字段 17

ToggleOptions

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.Switch(c.Key("toggle"), t, &s.Value, nui.SwitchOptions{Label: "Enable notifications", Description: "Updates are saved locally in this example.", Color: nui.ColorDefault, Size: nui.SizeDefault, Disabled: false, Loading: false})
ui.Textf(c, "Enabled: %t", s.Value)

使用说明

切换开关查看 Enabled 的变化,再比较加载与禁用状态。示例只保存当前预览中的布尔值;需要保存到设置文件时,应在操作回调中执行。

API 参考

Switch

源码
func Switch(c *ui.Context, t Theme, value *bool, o SwitchOptions) ui.Element

SwitchOptions

源码
type SwitchOptions = ToggleOptions
字段类型说明
Labelstring

Go 零值: ""

控件标签或可访问名称。

Descriptionstring

Go 零值: ""

补充说明文字。

ErrorMessagestring

Go 零值: ""

显式提供的错误说明。

Disabledbool

Go 零值: false

禁用组件及其交互。

Invalidbool

Go 零值: false

使用无效输入的视觉状态。

ColorColor

Go 零值: ColorDefault

语义颜色;默认值继承主题或组件配色。

SizeSize

Go 零值: SizeDefault

组件尺寸;默认值继承主题或组件尺寸。

Loadingbool

Go 零值: false

显示加载状态;是否阻止操作由组件决定。

LoadingIcon*ui.SVG

Go 零值: nil

覆盖默认加载图标。

CheckedIcon*ui.SVG

Go 零值: nil

选中状态的图标。

UncheckedIcon*ui.SVG

Go 零值: nil

未选中状态的图标。

VariantChoiceVariant

Go 零值: zero value

组件外观样式,支持范围取决于组件。

IndicatorIndicatorPlacement

Go 零值: zero value

选择指示器的位置或隐藏策略。

Highlightbool

Go 零值: false

突出显示控件或选中项目。

OnChangefunc(bool)

Go 零值: nil

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

UIStyles

Go 零值: zero value

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

Stylefunc(Slot, ui.Element)

Go 零值: nil

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