Update code for layouts, objects

This commit is contained in:
2024-07-21 11:48:28 -04:00
parent 9077015db6
commit 6ca6771fc6
26 changed files with 447 additions and 389 deletions

View File

@@ -28,7 +28,7 @@ func NewNumberInput (value float64) *NumberInput {
increment: NewButton(""),
decrement: NewButton(""),
}
box.SetRole(tomo.R("objects", "NumberInput", ""))
box.SetRole(tomo.R("objects", "NumberInput"))
box.Add(box.input)
box.Add(box.decrement)
box.Add(box.increment)
@@ -38,10 +38,8 @@ func NewNumberInput (value float64) *NumberInput {
box.SetValue(value)
box.CaptureScroll(true)
box.CaptureKeyboard(true)
box.OnScroll(box.handleScroll)
box.OnKeyUp(box.handleKeyUp)
box.OnKeyDown(box.handleKeyDown)
box.input.OnConfirm(box.handleConfirm)
box.input.OnValueChange(box.on.valueChange.Broadcast)
@@ -78,19 +76,28 @@ func (this *NumberInput) shift (by int) {
this.on.valueChange.Broadcast()
}
func (this *NumberInput) handleKeyDown (key input.Key, numpad bool) {
func (this *NumberInput) handleKeyDown (catch func (), key input.Key, numpad bool) {
switch key {
case input.KeyUp: this.shift(1)
case input.KeyDown: this.shift(-1)
default: this.input.handleKeyDown(key, numpad)
case input.KeyUp:
this.shift(1)
catch()
case input.KeyDown:
this.shift(-1)
catch()
}
}
func (this *NumberInput) handleScroll (x, y float64) {
func (this *NumberInput) handleKeyUp (catch func (), key input.Key, numpad bool) {
switch key {
case input.KeyUp: catch()
case input.KeyDown: catch()
}
}
func (this *NumberInput) handleScroll (catch func (), x, y float64) {
if x == 0 {
catch()
this.shift(-int(math.Round(y)))
} else {
this.input.handleScroll(x, y)
}
}