Compare commits
No commits in common. "a0fe7bc00f70c5f1c4c66875824307361930eb33" and "4d790f72648377f809b2c701d26c72c354736418" have entirely different histories.
a0fe7bc00f
...
4d790f7264
11
input.go
11
input.go
@ -13,7 +13,6 @@ type TextInput struct {
|
|||||||
text []rune
|
text []rune
|
||||||
on struct {
|
on struct {
|
||||||
enter event.FuncBroadcaster
|
enter event.FuncBroadcaster
|
||||||
edit event.FuncBroadcaster
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,11 +47,6 @@ func (this *TextInput) OnEnter (callback func ()) event.Cookie {
|
|||||||
return this.on.enter.Connect(callback)
|
return this.on.enter.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnEdit specifies a function to be called when the user edits the input text.
|
|
||||||
func (this *TextInput) OnEdit (callback func ()) event.Cookie {
|
|
||||||
return this.on.edit.Connect(callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
|
func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
|
||||||
dot := this.Dot()
|
dot := this.Dot()
|
||||||
modifiers := this.Modifiers()
|
modifiers := this.Modifiers()
|
||||||
@ -99,10 +93,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.Select(dot)
|
this.Select(dot)
|
||||||
if changed {
|
if changed { this.SetText(string(this.text)) }
|
||||||
this.SetText(string(this.text))
|
|
||||||
this.on.edit.Broadcast()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *TextInput) handleScroll (x, y float64) {
|
func (this *TextInput) handleScroll (x, y float64) {
|
||||||
|
100
numberinput.go
100
numberinput.go
@ -1,100 +0,0 @@
|
|||||||
package objects
|
|
||||||
|
|
||||||
import "math"
|
|
||||||
import "strconv"
|
|
||||||
import "git.tebibyte.media/tomo/tomo"
|
|
||||||
import "git.tebibyte.media/tomo/tomo/theme"
|
|
||||||
import "git.tebibyte.media/tomo/tomo/input"
|
|
||||||
import "git.tebibyte.media/tomo/tomo/event"
|
|
||||||
import "git.tebibyte.media/tomo/objects/layouts"
|
|
||||||
|
|
||||||
// NumberInput is an editable text box which accepts only numbers, and has
|
|
||||||
// controls to increment and decrement its value.
|
|
||||||
type NumberInput struct {
|
|
||||||
tomo.ContainerBox
|
|
||||||
input *TextInput
|
|
||||||
increment *Button
|
|
||||||
decrement *Button
|
|
||||||
on struct {
|
|
||||||
enter event.FuncBroadcaster
|
|
||||||
edit event.FuncBroadcaster
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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(""),
|
|
||||||
}
|
|
||||||
theme.Apply(box, theme.R("objects", "NumberInput", ""))
|
|
||||||
box.Add(box.input)
|
|
||||||
box.Add(box.increment)
|
|
||||||
box.Add(box.decrement)
|
|
||||||
box.SetLayout(layouts.NewGrid([]bool { true, false, false }, []bool { true }))
|
|
||||||
box.increment.SetIcon(theme.IconActionIncrement)
|
|
||||||
box.decrement.SetIcon(theme.IconActionDecrement)
|
|
||||||
|
|
||||||
box.SetValue(value)
|
|
||||||
|
|
||||||
box.CaptureScroll(true)
|
|
||||||
box.CaptureKeyboard(true)
|
|
||||||
|
|
||||||
box.OnScroll(box.handleScroll)
|
|
||||||
box.OnKeyDown(box.handleKeyDown)
|
|
||||||
box.input.OnEnter(box.handleEnter)
|
|
||||||
box.input.OnEdit(box.on.edit.Broadcast)
|
|
||||||
box.increment.OnClick(func () { box.shift(1) })
|
|
||||||
box.decrement.OnClick(func () { box.shift(-1) })
|
|
||||||
return box
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetValue sets the value of the input.
|
|
||||||
func (this *NumberInput) SetValue (value float64) {
|
|
||||||
this.input.SetText(strconv.FormatFloat(value, 'g', -1, 64))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value returns the value of the input.
|
|
||||||
func (this *NumberInput) Value () float64 {
|
|
||||||
value, _ := strconv.ParseFloat(this.input.Text(), 64)
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
// OnEnter specifies a function to be called when the user presses enter within
|
|
||||||
// the text input.
|
|
||||||
func (this *NumberInput) OnEnter (callback func ()) event.Cookie {
|
|
||||||
return this.on.enter.Connect(callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
// OnEdit specifies a function to be called when the user edits the input value.
|
|
||||||
func (this *NumberInput) OnEdit (callback func ()) event.Cookie {
|
|
||||||
return this.on.edit.Connect(callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *NumberInput) shift (by int) {
|
|
||||||
this.SetValue(this.Value() + float64(by))
|
|
||||||
this.on.edit.Broadcast()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *NumberInput) handleKeyDown (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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *NumberInput) handleScroll (x, y float64) {
|
|
||||||
if x == 0 {
|
|
||||||
this.shift(-int(math.Round(y)))
|
|
||||||
} else {
|
|
||||||
this.input.handleScroll(x, y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *NumberInput) handleEnter () {
|
|
||||||
this.SetValue(this.Value())
|
|
||||||
this.on.enter.Broadcast()
|
|
||||||
}
|
|
16
slider.go
16
slider.go
@ -15,7 +15,7 @@ type Slider struct {
|
|||||||
dragOffset image.Point
|
dragOffset image.Point
|
||||||
|
|
||||||
on struct {
|
on struct {
|
||||||
slide event.FuncBroadcaster
|
valueChange event.FuncBroadcaster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +71,7 @@ func (this *Slider) SetValue (value float64) {
|
|||||||
if value == this.layout.value { return }
|
if value == this.layout.value { return }
|
||||||
this.layout.value = value
|
this.layout.value = value
|
||||||
this.SetLayout(this.layout)
|
this.SetLayout(this.layout)
|
||||||
|
this.on.valueChange.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value returns the value of the slider between 0 and 1.
|
// Value returns the value of the slider between 0 and 1.
|
||||||
@ -78,10 +79,10 @@ func (this *Slider) Value () float64 {
|
|||||||
return this.layout.value
|
return this.layout.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnValueChange specifies a function to be called when the user moves the
|
// OnValueChange specifies a function to be called when the slider's value
|
||||||
// slider.
|
// changes.
|
||||||
func (this *Slider) OnSlide (callback func ()) event.Cookie {
|
func (this *Slider) OnValueChange (callback func ()) event.Cookie {
|
||||||
return this.on.slide.Connect(callback)
|
return this.on.valueChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
func (this *Slider) handleKeyDown (key input.Key, numpad bool) {
|
||||||
@ -138,18 +139,14 @@ func (this *Slider) handleMouseDown (button input.Button) {
|
|||||||
case input.ButtonMiddle:
|
case input.ButtonMiddle:
|
||||||
if above {
|
if above {
|
||||||
this.SetValue(0)
|
this.SetValue(0)
|
||||||
this.on.slide.Broadcast()
|
|
||||||
} else {
|
} else {
|
||||||
this.SetValue(1)
|
this.SetValue(1)
|
||||||
this.on.slide.Broadcast()
|
|
||||||
}
|
}
|
||||||
case input.ButtonRight:
|
case input.ButtonRight:
|
||||||
if above {
|
if above {
|
||||||
this.SetValue(this.Value() - 0.05)
|
this.SetValue(this.Value() - 0.05)
|
||||||
this.on.slide.Broadcast()
|
|
||||||
} else {
|
} else {
|
||||||
this.SetValue(this.Value() + 0.05)
|
this.SetValue(this.Value() + 0.05)
|
||||||
this.on.slide.Broadcast()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +176,6 @@ func (this *Slider) drag () {
|
|||||||
float64(pointer.X) /
|
float64(pointer.X) /
|
||||||
float64(gutter.Dx() - handle.Dx()))
|
float64(gutter.Dx() - handle.Dx()))
|
||||||
}
|
}
|
||||||
this.on.slide.Broadcast()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Slider) fallbackDragOffset () image.Point {
|
func (this *Slider) fallbackDragOffset () image.Point {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user