NumberInput no longer embeds tomo.ContainerBox

This commit is contained in:
Sasha Koshka 2024-08-24 20:19:01 -04:00
parent b784596b4d
commit 02fed8ce48

View File

@ -3,14 +3,17 @@ package objects
import "math"
import "strconv"
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/event"
import "git.tebibyte.media/tomo/objects/layouts"
var _ tomo.Object = new(NumberInput)
// NumberInput is an editable text box which accepts only numbers, and has
// controls to increment and decrement its value.
type NumberInput struct {
tomo.ContainerBox
box tomo.ContainerBox
input *TextInput
increment *Button
decrement *Button
@ -22,30 +25,52 @@ type NumberInput struct {
// NewNumberInput creates a new number input with the specified value.
func NewNumberInput (value float64) *NumberInput {
box := &NumberInput {
ContainerBox: tomo.NewContainerBox(),
input: NewTextInput(""),
increment: NewButton(""),
decrement: NewButton(""),
numberInput := &NumberInput {
box: tomo.NewContainerBox(),
input: NewTextInput(""),
increment: NewButton(""),
decrement: NewButton(""),
}
box.SetRole(tomo.R("objects", "NumberInput"))
box.Add(box.input)
box.Add(box.decrement)
box.Add(box.increment)
box.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
box.increment.SetIcon(tomo.IconValueIncrement)
box.decrement.SetIcon(tomo.IconValueDecrement)
numberInput.box.SetRole(tomo.R("objects", "NumberInput"))
numberInput.box.Add(numberInput.input)
numberInput.box.Add(numberInput.decrement)
numberInput.box.Add(numberInput.increment)
numberInput.box.SetAttr(tomo.ALayout(layouts.Row { true, false, false }))
numberInput.increment.SetIcon(tomo.IconValueIncrement)
numberInput.decrement.SetIcon(tomo.IconValueDecrement)
box.SetValue(value)
numberInput.SetValue(value)
box.OnScroll(box.handleScroll)
box.OnKeyDown(box.handleKeyDown)
box.OnKeyUp(box.handleKeyUp)
box.input.OnConfirm(box.handleConfirm)
box.input.OnValueChange(box.on.valueChange.Broadcast)
box.increment.OnClick(func () { box.shift(1) })
box.decrement.OnClick(func () { box.shift(-1) })
return box
numberInput.box.OnScroll(numberInput.handleScroll)
numberInput.box.OnKeyDown(numberInput.handleKeyDown)
numberInput.box.OnKeyUp(numberInput.handleKeyUp)
numberInput.input.OnConfirm(numberInput.handleConfirm)
numberInput.input.OnValueChange(numberInput.on.valueChange.Broadcast)
numberInput.increment.OnClick(func () { numberInput.shift( 1) })
numberInput.decrement.OnClick(func () { numberInput.shift(-1) })
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.