Listbox

在可见列表中选择项目。

实时预览

正在加载预览…

参数配置

全部字段 16

ListboxItems

列表项 · 3
ListboxItem
ListboxItem
ListboxItem

ListboxOptions

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.Listbox(c.Key("list"), t, &s.Values, &s.List, []nui.ListboxItem{{ID: "go", Label: "Go", Description: "Native applications"}, {ID: "rust", Label: "Rust", Description: "Systems programming"}, {ID: "typescript", Label: "TypeScript", Description: "Web applications"}}, nui.ListboxOptions{Label: "Languages", Multiple: false, Disabled: false, Height: 220})

使用说明

直接在列表中选择语言,multiple 控制单选与多选。ListboxState 管理交互,所选 ID 列表保存业务选择;展示标签不应代替稳定 ID。

API 参考

Listbox

源码
func Listbox(c *ui.Context, t Theme, selected *[]string, s *ListboxState, items []ListboxItem, o ListboxOptions) ui.Element

ListboxOptions

源码
type ListboxOptions struct {
	// Build draws non-interactive row content synchronously; Label still supplies semantics.
	Build              func(*ui.Context, Theme, ListboxItem)
	Label, EmptyText   string
	Multiple, Disabled bool
	Height             float32
	Orientation        Optional[Orientation] // Defaults to Vertical.
	ItemWidth          float32               // Horizontal item width, default 160 DIP.
	Loop               bool
	HighlightOnHover   Optional[bool]
	SelectionBehavior  SelectionBehavior
	OnChange           func([]string)
	OnSelect           func(string) // Activation, including selecting an unchanged value.
	Decoration
	// contains filtered or unexported fields
}
字段类型说明
Buildfunc(*ui.Context, Theme, ListboxItem)

Go 零值: nil

同步构建当前项目的视觉内容。

Labelstring

Go 零值: ""

控件标签或可访问名称。

EmptyTextstring

Go 零值: ""

没有可显示数据时的文案。

Multiplebool

Go 零值: false

允许选择多个项目。

Disabledbool

Go 零值: false

禁用组件及其交互。

Heightfloat32

Go 零值: 0

高度,单位为 DIP。

OrientationOptional[Orientation]

Go 零值: unset

水平或垂直方向;未设置时使用组件默认方向。

ItemWidthfloat32

Go 零值: 0

横向列表项的宽度。

Loopbool

Go 零值: false

键盘导航到边界时循环。

HighlightOnHoverOptional[bool]

Go 零值: unset

悬停时高亮列表项。

SelectionBehaviorSelectionBehavior

Go 零值: zero value

控制列表选择的切换或替换策略。

OnChangefunc([]string)

Go 零值: nil

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

OnSelectfunc(string)

Go 零值: nil

激活或选择项目时通知应用的回调。

UIStyles

Go 零值: zero value

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

Stylefunc(Slot, ui.Element)

Go 零值: nil

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