NumberInput no longer embeds tomo.ContainerBox
This commit is contained in:
parent
b784596b4d
commit
02fed8ce48
@ -3,14 +3,17 @@ package objects
|
|||||||
import "math"
|
import "math"
|
||||||
import "strconv"
|
import "strconv"
|
||||||
import "git.tebibyte.media/tomo/tomo"
|
import "git.tebibyte.media/tomo/tomo"
|
||||||
|
import "git.tebibyte.media/tomo/tomo/text"
|
||||||
import "git.tebibyte.media/tomo/tomo/input"
|
import "git.tebibyte.media/tomo/tomo/input"
|
||||||
import "git.tebibyte.media/tomo/tomo/event"
|
import "git.tebibyte.media/tomo/tomo/event"
|
||||||
import "git.tebibyte.media/tomo/objects/layouts"
|
import "git.tebibyte.media/tomo/objects/layouts"
|
||||||
|
|
||||||
|
var _ tomo.Object = new(NumberInput)
|
||||||
|
|
||||||
// NumberInput is an editable text box which accepts only numbers, and has
|
// NumberInput is an editable text box which accepts only numbers, and has
|
||||||
// controls to increment and decrement its value.
|
// controls to increment and decrement its value.
|
||||||
type NumberInput struct {
|
type NumberInput struct {
|
||||||
tomo.ContainerBox
|
box tomo.ContainerBox
|
||||||
input *TextInput
|
input *TextInput
|
||||||
increment *Button
|
increment *Button
|
||||||
decrement *Button
|
decrement *Button
|
||||||
@ -22,30 +25,52 @@ type NumberInput struct {
|
|||||||
|
|
||||||
// NewNumberInput creates a new number input with the specified value.
|
// NewNumberInput creates a new number input with the specified value.
|
||||||
func NewNumberInput (value float64) *NumberInput {
|
func NewNumberInput (value float64) *NumberInput {
|
||||||
box := &NumberInput {
|
numberInput := &NumberInput {
|
||||||
ContainerBox: tomo.NewContainerBox(),
|
box: tomo.NewContainerBox(),
|
||||||
input: NewTextInput(""),
|
input: NewTextInput(""),
|
||||||
increment: NewButton(""),
|
increment: NewButton(""),
|
||||||
decrement: NewButton(""),
|
decrement: NewButton(""),
|
||||||
}
|
}
|
||||||
box.SetRole(tomo.R("objects", "NumberInput"))
|
numberInput.box.SetRole(tomo.R("objects", "NumberInput"))
|
||||||
box.Add(box.input)
|
numberInput.box.Add(numberInput.input)
|
||||||
box.Add(box.decrement)
|
numberInput.box.Add(numberInput.decrement)
|
||||||
box.Add(box.increment)
|
numberInput.box.Add(numberInput.increment)
|
||||||
box.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
|
numberInput.box.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
|
||||||
box.increment.SetIcon(tomo.IconValueIncrement)
|
numberInput.increment.SetIcon(tomo.IconValueIncrement)
|
||||||
box.decrement.SetIcon(tomo.IconValueDecrement)
|
numberInput.decrement.SetIcon(tomo.IconValueDecrement)
|
||||||
|
|
||||||
box.SetValue(value)
|
numberInput.SetValue(value)
|
||||||
|
|
||||||
box.OnScroll(box.handleScroll)
|
numberInput.box.OnScroll(numberInput.handleScroll)
|
||||||
box.OnKeyDown(box.handleKeyDown)
|
numberInput.box.OnKeyDown(numberInput.handleKeyDown)
|
||||||
box.OnKeyUp(box.handleKeyUp)
|
numberInput.box.OnKeyUp(numberInput.handleKeyUp)
|
||||||
box.input.OnConfirm(box.handleConfirm)
|
numberInput.input.OnConfirm(numberInput.handleConfirm)
|
||||||
box.input.OnValueChange(box.on.valueChange.Broadcast)
|
numberInput.input.OnValueChange(numberInput.on.valueChange.Broadcast)
|
||||||
box.increment.OnClick(func () { box.shift(1) })
|
numberInput.increment.OnClick(func () { numberInput.shift( 1) })
|
||||||
box.decrement.OnClick(func () { box.shift(-1) })
|
numberInput.decrement.OnClick(func () { numberInput.shift(-1) })
|
||||||
return box
|
return numberInput
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetBox returns the underlying box.
|
||||||
|
func (this *NumberInput) GetBox () tomo.Box {
|
||||||
|
return this.box
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFocused sets whether or not this number input has keyboard focus. If set
|
||||||
|
// to true, this method will steal focus away from whichever object currently
|
||||||
|
// has focus.
|
||||||
|
func (this *NumberInput) SetFocused (focused bool) {
|
||||||
|
this.input.SetFocused(focused)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select sets the text cursor or selection.
|
||||||
|
func (this *NumberInput) Select (dot text.Dot) {
|
||||||
|
this.input.Select(dot)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dot returns the text cursor or selection.
|
||||||
|
func (this *NumberInput) Dot () text.Dot {
|
||||||
|
return this.input.Dot()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value returns the value of the input.
|
// Value returns the value of the input.
|
||||||
|
Loading…
Reference in New Issue
Block a user