numberinput

package
v1.0.31-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package numberinput provides a numeric field with − and + steppers, a range and a step.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NumberInput

type NumberInput struct {
	// Contextual gives it a context menu (Context).
	elements.Contextual
	// contains filtered or unexported fields
}

NumberInput is a stateful numeric field between − and + buttons. Create it once with New and lay it out every frame:

size := numberinput.New(12).Range(6, 96).OnChange(func(v float64) { setFontSize(v) })

Typing changes the value as soon as the text is a number in range; leaving the field or pressing Enter puts anything else back in range (or back to the value, for text that isn't a number). The buttons step the value, repeating while held; Up and Down do too, by ten steps with Shift. Commas are read as decimal points.

func New

func New(value float64, st ...styles.Styles) *NumberInput

New returns a NumberInput holding value, with no range, a step of 1 and no decimals. The styles argument is optional: Width (the whole control, default 140dp; -1 fills), and the field's styles otherwise (FontSize, Color, BorderColor...).

func (*NumberInput) Change

func (n *NumberInput) Change(v float64)

Change sets the value and calls OnChange when it changed, as a user edit would.

func (*NumberInput) Decimals

func (n *NumberInput) Decimals(d int) *NumberInput

Decimals sets how many decimals the value keeps and shows. It returns n for chaining.

func (*NumberInput) Field

func (n *NumberInput) Field() *input.Input

Field returns the text field, for focusing it (Focus, Blur) or adding handlers.

func (*NumberInput) Label

func (n *NumberInput) Label(label string) *NumberInput

Label sets the accessible name reported to automation. It returns n for chaining.

func (*NumberInput) Layout

func (n *NumberInput) Layout(gtx layout.Context) layout.Dimensions

Layout lays out the field between its − and + buttons.

func (*NumberInput) OnChange

func (n *NumberInput) OnChange(fn func(v float64)) *NumberInput

OnChange sets the handler called when the user changes the value. It returns n for chaining.

func (*NumberInput) Range

func (n *NumberInput) Range(min, max float64) *NumberInput

Range limits the value to [min, max]; math.Inf(-1) and math.Inf(1) leave a side open. It returns n for chaining.

func (*NumberInput) SetValue

func (n *NumberInput) SetValue(v float64)

SetValue sets the value, put in range and rounded to the decimals, without calling OnChange.

func (*NumberInput) Step

func (n *NumberInput) Step(step float64) *NumberInput

Step sets how much the buttons and arrow keys change the value. It returns n for chaining.

func (*NumberInput) Styles

func (n *NumberInput) Styles(st styles.Styles) *NumberInput

Styles replaces the styles (see New). It returns n for chaining.

func (*NumberInput) Value

func (n *NumberInput) Value() float64

Value returns the current value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL