Slider
单滑块或多滑块范围输入,指针与键盘交互由核心管理。
正在加载交互演示…
func SliderExample() *ui.Element {
volume, setVolume := ui.CreateSignal([]float64{40})
slider := ui.NewSlider(ui.SliderRootProps{Value: volume, Min: 0, Max: 100, Step: 1, OnValueChange: func(next []float64, _ *native.Event) {
setVolume(next)
}})
return slider.Root().Children(
slider.Label().Child("Volume"),
slider.Control().Width(240).Height(24).Children(
slider.Track().Child(slider.Indicator()),
slider.Thumb(),
),
slider.Value(),
)
}#导入
从 github.com/egoist/quickgui/go/ui 导入 ui。
import (
"github.com/egoist/quickgui/go/native"
"github.com/egoist/quickgui/go/ui"
)#用法
func SliderExample() *ui.Element {
volume, setVolume := ui.CreateSignal([]float64{40})
slider := ui.NewSlider(ui.SliderRootProps{Value: volume, Min: 0, Max: 100, Step: 1, OnValueChange: func(next []float64, _ *native.Event) {
setVolume(next)
}})
return slider.Root().Children(
slider.Label().Child("Volume"),
slider.Control().Width(240).Height(24).Children(
slider.Track().Child(slider.Indicator()),
slider.Thumb(),
),
slider.Value(),
)
}#结构
slider.Rootslider.Labelslider.Valueslider.Controlslider.Trackslider.Rangeslider.Indicatorslider.Thumb
#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
NewSlider
查看源码ui.NewSlider(props ...SliderRootProps) *SliderComponentNewSlider declares a Slider instance. Optional props provide initial settings.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)查看源码Styleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
any查看源码ChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildren查看源码Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
any查看源码Rolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
TabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64查看源码OnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)查看源码OnDoubleClickfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Valuefunc() []float64—
The current controlled value. Update application state from the change callback to accept a new value.
func() []float64查看源码DefaultValue[]float64—
Initial value for uncontrolled state. Use Value when the application should own subsequent changes.
[]float64查看源码OnValueChangefunc([]float64, *native.Event)—
Reports an accepted value change. Use the callback payload to update controlled state.
func([]float64, *native.Event)查看源码OnValueCommittedfunc([]float64, *native.Event)—
Callback for value committed. The signature below lists the event payload.
func([]float64, *native.Event)查看源码Minany—
Maxany—
Stepany—
LargeStepany—
MinStepsBetweenValuesany—
ThumbAlignmentstring—
Formatstring—
Orientationstring—
Slider.Disabled
查看源码slider.Disabled(value any) *SliderComponentPrevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
Slider.SetValue
查看源码slider.SetValue(value any) *SliderComponentConfigures set value for this part. The declared type and source define the accepted value.
Slider.DefaultValue
查看源码slider.DefaultValue(value []float64) *SliderComponentInitial value for uncontrolled state. Use Value when the application should own subsequent changes.
Slider.OnValueChange
查看源码slider.OnValueChange(value func([]float64, *native.Event)) *SliderComponentReports an accepted value change. Use the callback payload to update controlled state.
Slider.OnValueCommitted
查看源码slider.OnValueCommitted(value func([]float64, *native.Event)) *SliderComponentCallback for value committed. The signature below lists the event payload.
Slider.Min
查看源码slider.Min(value any) *SliderComponentLower bound of the accepted value.
Slider.Max
查看源码slider.Max(value any) *SliderComponentUpper bound of the accepted value.
Slider.Step
查看源码slider.Step(value any) *SliderComponentIncrement applied by pointer, keyboard, or step controls.
Slider.LargeStep
查看源码slider.LargeStep(value any) *SliderComponentLarger increment used by accelerated keyboard adjustment.
Slider.MinStepsBetweenValues
查看源码slider.MinStepsBetweenValues(value any) *SliderComponentMinimum separation between neighboring slider thumbs, measured in steps.
Slider.ThumbAlignment
查看源码slider.ThumbAlignment(value string) *SliderComponentWhether the slider thumb stays inside the track or aligns its center to the edge.
Slider.Format
查看源码slider.Format(value string) *SliderComponentFormatting configuration or callback for the displayed value.
Slider.Orientation
查看源码slider.Orientation(value string) *SliderComponentDirection used for layout and keyboard navigation.
Slider.Root
查看源码slider.Root() *ElementConfigures root for this part. The declared type and source define the accepted value.
Slider.Label
查看源码slider.Label(options ...PartProps) *ElementVisible native SwiftUI control label.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)查看源码Styleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
any查看源码ChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildren查看源码Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
any查看源码Rolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
TabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64查看源码OnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)查看源码OnDoubleClickfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Slider.Value
查看源码slider.Value(options ...PartProps) *ElementThe current controlled value. Update application state from the change callback to accept a new value.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)查看源码Styleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
any查看源码ChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildren查看源码Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
any查看源码Rolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
TabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64查看源码OnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)查看源码OnDoubleClickfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Slider.Control
查看源码slider.Control(options ...PartProps) *ElementConfigures control for this part. The declared type and source define the accepted value.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)查看源码Styleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
any查看源码ChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildren查看源码Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
any查看源码Rolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
TabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64查看源码OnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)查看源码OnDoubleClickfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Slider.Track
查看源码slider.Track(options ...PartProps) *ElementConfigures track for this part. The declared type and source define the accepted value.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)查看源码Styleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
any查看源码ChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildren查看源码Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
any查看源码Rolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
TabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64查看源码OnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)查看源码OnDoubleClickfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Slider.Range
查看源码slider.Range(options ...PartProps) *ElementConfigures range for this part. The declared type and source define the accepted value.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)查看源码Styleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
any查看源码ChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildren查看源码Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
any查看源码Rolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
TabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64查看源码OnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)查看源码OnDoubleClickfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Slider.Indicator
查看源码slider.Indicator(options ...PartProps) *ElementConfigures indicator for this part. The declared type and source define the accepted value.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)查看源码Styleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
any查看源码ChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildren查看源码Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
any查看源码Rolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
TabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64查看源码OnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)查看源码OnDoubleClickfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Slider.Thumb
查看源码slider.Thumb(options ...SliderThumbProps) *ElementConfigures thumb for this part. The declared type and source define the accepted value.
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)查看源码Styleany—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
any查看源码ChildrenPartChildren—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
PartChildren查看源码Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
any查看源码Rolestring—
FocusOnPointerany—
Groupany—
AriaLabelany—
TabIndex*float64—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
*float64查看源码OnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)查看源码OnDoubleClickfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
Index*int—
Element
查看源码part.Child(content).Style(style)Every part returns a fluent element. Strings, numbers, elements, and deferred child factories compose directly.
ChildChild(child any) *Element—
Child appends content and returns this element. Content can be an element, native node, scalar, accessor, or node-returning construction callback.
Child(child any) *Element查看源码ChildrenChildren(children ...any) *Element—
Children appends multiple children in order without replacing existing content. It also accepts []any, []*Element, and []*native.Node slices as arguments. Read the retained child nodes through element.Node.Children.
Children(children ...any) *Element查看源码StyleStyle(style StyleBuilder) *Element—
Style merges a reusable style. Scalar accessors retain independent native bindings.
Style(style StyleBuilder) *Element查看源码OnClickOnClick(handler func()) *Element—
RefRef(handler func(*native.Node)) *Element—
Ref exposes the native handle once at this point in the declaration chain.
Ref(handler func(*native.Node)) *Element查看源码