NumberInput
Edits a number within bounds, with a stepper and optional drag scrubbing.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
)
type dimensions struct {
quantity, width, opacity float64
}
func (d *dimensions) View(c *ui.Context) {
ui.Column(c).Width(240).Gap(12).Children(func() {
components.NumberInput(c, &d.quantity, 1, 99, 1).Label("Quantity").FillWidth()
// A leading text drags the value: press on "W" and move sideways.
components.NumberInput(c, &d.width, 0, 4096, 1, components.NumberInputOptions{
LeadingText: "W",
}).Label("Width").FillWidth()
components.NumberInput(c, &d.opacity, 0, 1, 0.05, components.NumberInputOptions{
HideStepper: true,
}).Label("Opacity").FillWidth()
})
}Valid text updates the value as it is typed; partial or invalid text is kept while editing and restored on Enter or when focus leaves. The arrow keys and stepper buttons add or subtract step, clamped to the bounds.
LeadingText or LeadingIcon adds a handle that changes the value as it is dragged sideways, as design tools do. HideStepper removes the buttons.
API
NumberInput
func NumberInput(c *ui.Context, value *float64, lo, hi, step float64, options ...NumberInputOptions) *NumberInputControlNumberInput creates a numeric text field with optional prefix scrubbing and an optional vertical stepper. Bounds and value must be finite, hi >= lo, and step finite and positive. Valid in-range text updates value immediately without snapping to step. Partial or invalid text is retained while editing and restored on Enter or focus loss. Up/Down and the buttons add/subtract step and clamp to the bounds. Application changes replace even a focused draft. Disable a parent to disable the control. Key a parent for stable identity; construction resolves interaction state.
pkg.go.devNumberInputOptions
NumberInputControl
NumberInputControl exposes layout on Element and editing on the text field. Keep this handle to query Changed after applying Element layout methods.
Prop
Type
Methods
func (n *NumberInputControl) AutoFocus() *NumberInputControlAutoFocus focuses the editable text field.
func (n *NumberInputControl) Changed() boolChanged reports an input-driven value change, not initial clamping.
func (n *NumberInputControl) Label(label string) *NumberInputControlLabel names the text field and any optional drag handle and step buttons.