InputNumber

输入数值并用按钮逐步调整。

实时预览

正在加载预览…

参数配置

全部字段 28

InputNumberOptions

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.InputNumber(c.Key("number"), t, &s.Value, &s.Number, nui.InputNumberOptions{InputOptions: nui.InputOptions{Label: "Project name", Placeholder: "Type something…", Color: nui.ColorDefault, Size: nui.SizeDefault, Variant: nui.VariantDefault, Disabled: false, ReadOnly: false, Loading: false}, Orientation: nui.Horizontal, Min: nui.Set(0.0), Max: nui.Set(100.0), Step: 1})

使用说明

输入数值或使用增减按钮,再调整 Step 与按钮方向。示例固定 0–100 范围,同时保存数值与 InputNumberState,让编辑中的草稿能跨重建保留。

API 参考

InputNumber

源码
func InputNumber(c *ui.Context, t Theme, value *Optional[float64], s *NumberState, o InputNumberOptions) ui.Element

InputNumberOptions

源码
type InputNumberOptions struct {
	InputOptions
	// Horizontal (the default) places minus/plus around centered text.
	// Vertical stacks up/down chevrons at the trailing edge.
	Orientation   Orientation
	Min, Max      Optional[float64]
	Step          float64
	OnValueChange func(Optional[float64])
}
字段类型说明
Labelstring

Go 零值: ""

控件标签或可访问名称。

Placeholderstring

Go 零值: ""

没有输入或选择时的占位文字。

ErrorMessagestring

Go 零值: ""

显式提供的错误说明。

Disabledbool

Go 零值: false

禁用组件及其交互。

ReadOnlybool

Go 零值: false

允许读取和选择内容,但禁止编辑。

Invalidbool

Go 零值: false

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

Passwordbool

Go 零值: false

遮蔽输入内容。

Clearablebool

Go 零值: false

显示清空操作或允许清除当前值。

ClearLabelstring

Go 零值: ""

清空操作的可访问名称。

ColorColor

Go 零值: ColorDefault

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

VariantVariant

Go 零值: VariantDefault

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

SizeSize

Go 零值: SizeDefault

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

Leading*ui.SVG

Go 零值: nil

内容前方的 SVG 图标。

Trailing*ui.SVG

Go 零值: nil

内容后方的 SVG 图标。

Loadingbool

Go 零值: false

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

LoadingIcon*ui.SVG

Go 零值: nil

覆盖默认加载图标。

Highlightbool

Go 零值: false

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

MaxLengthint

Go 零值: 0

输入长度上限,原生文本以 UTF-16 单元计数;零表示不限。

OnChangefunc(string)

Go 零值: nil

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

OnSubmitfunc(string)

Go 零值: nil

提交表单或输入时通知应用的回调。

OnClearfunc()

Go 零值: nil

清空值时通知应用的回调。

UIStyles

Go 零值: zero value

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

Stylefunc(root, editor, leading, trailing ui.Element)

Go 零值: nil

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

OrientationOrientation

Go 零值: zero value

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

MinOptional[float64]

Go 零值: unset

下界;Optional 可明确指定零。

MaxOptional[float64]

Go 零值: unset

上界或数量上限,具体含义依组件而定。

Stepfloat64

Go 零值: 0

每次调整的步长。

OnValueChangefunc(Optional[float64])

Go 零值: nil

解析后的值变化时通知应用的回调。