Documentation
¶
Overview ¶
Package numberinput provides a numeric field with − and + steppers, a range and a step.
Index ¶
- type NumberInput
- func (n *NumberInput) Change(v float64)
- func (n *NumberInput) Decimals(d int) *NumberInput
- func (n *NumberInput) Field() *input.Input
- func (n *NumberInput) Label(label string) *NumberInput
- func (n *NumberInput) Layout(gtx layout.Context) layout.Dimensions
- func (n *NumberInput) OnChange(fn func(v float64)) *NumberInput
- func (n *NumberInput) Range(min, max float64) *NumberInput
- func (n *NumberInput) SetValue(v float64)
- func (n *NumberInput) Step(step float64) *NumberInput
- func (n *NumberInput) Styles(st styles.Styles) *NumberInput
- func (n *NumberInput) Value() float64
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.