Compare commits

..

No commits in common. "e4857da22d174d604a5b0d42ff0883262ce80617" and "43ec7a0311eb181c71f304bc7df60eaf4edeb006" have entirely different histories.

7 changed files with 34 additions and 54 deletions

View File

@ -89,23 +89,23 @@ func (this *Button) applyLayout () {
}
func (this *Button) handleKeyDown (key input.Key, numberPad bool) bool {
if !isClickingKey(key) { return false }
this.on.click.Broadcast()
if key != input.KeyEnter && key != input.Key(' ') { return false }
return true
}
func (this *Button) handleKeyUp (key input.Key, numberPad bool) bool {
if !isClickingKey(key) { return false }
if key != input.KeyEnter && key != input.Key(' ') { return false }
this.on.click.Broadcast()
return true
}
func (this *Button) handleButtonDown (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
return true
}
func (this *Button) handleButtonUp (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.on.click.Broadcast()
}

View File

@ -54,23 +54,23 @@ func (this *Checkbox) OnValueChange (callback func ()) event.Cookie {
}
func (this *Checkbox) handleKeyDown (key input.Key, numberPad bool) bool {
if !isClickingKey(key) { return false }
if key != input.KeyEnter && key != input.Key(' ') { return false }
this.Toggle()
return true
}
func (this *Checkbox) handleKeyUp (key input.Key, numberPad bool) bool {
if !isClickingKey(key) { return false}
if key != input.KeyEnter && key != input.Key(' ') { return false}
return true
}
func (this *Checkbox) handleButtonDown (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
return true
}
func (this *Checkbox) handleButtonUp (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.Toggle()
}

View File

@ -66,17 +66,6 @@ func (this *Dropdown) SetItems (items ...string) {
this.items = items
}
// Choose creates a menu that allows the user to pick a value.
func (this *Dropdown) Choose () {
if this.menu != nil {
this.menu.Close()
}
menu, err := NewAnchoredMenu(this, this.itemList()...)
if err != nil { return }
this.menu = menu
menu.SetVisible(true)
}
func (this *Dropdown) itemList () []tomo.Object {
items := make([]tomo.Object, len(this.items))
for index, value := range this.items {
@ -91,26 +80,36 @@ func (this *Dropdown) itemList () []tomo.Object {
return items
}
func (this *Dropdown) showMenu () {
if this.menu != nil {
this.menu.Close()
}
menu, err := NewAnchoredMenu(this, this.itemList()...)
if err != nil { return }
this.menu = menu
menu.SetVisible(true)
}
func (this *Dropdown) handleKeyDown (key input.Key, numberPad bool) bool {
if !isClickingKey(key) { return false }
this.Choose()
if key != input.KeyEnter && key != input.Key(' ') { return false }
return true
}
func (this *Dropdown) handleKeyUp (key input.Key, numberPad bool) bool {
if !isClickingKey(key) { return false }
if key != input.KeyEnter && key != input.Key(' ') { return false }
this.showMenu()
return true
}
func (this *Dropdown) handleButtonDown (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
return true
}
func (this *Dropdown) handleButtonUp (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.Choose()
this.showMenu()
}
return true
}

View File

@ -1,19 +0,0 @@
package objects
import "git.tebibyte.media/tomo/tomo/input"
func isClickingKey (key input.Key) bool {
return key == input.KeyEnter || key == input.Key(' ')
}
func isConfirmationKey (key input.Key) bool {
return key == input.KeyEnter
}
func isClickingButton (button input.Button) bool {
return button == input.ButtonLeft
}
func isMenuButton (button input.Button) bool {
return button == input.ButtonLeft
}

View File

@ -55,12 +55,12 @@ func (this *LabelCheckbox) OnValueChange (callback func ()) event.Cookie {
}
func (this *LabelCheckbox) handleButtonDown (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
return true
}
func (this *LabelCheckbox) handleButtonUp (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.checkbox.SetFocused(true)
this.checkbox.Toggle()

View File

@ -171,23 +171,23 @@ func (this *Swatch) userSetValue (value color.Color) {
}
func (this *Swatch) handleKeyDown (key input.Key, numberPad bool) bool {
if !isClickingKey(key) { return false }
this.Choose()
if key != input.KeyEnter && key != input.Key(' ') { return false }
return true
}
func (this *Swatch) handleKeyUp (key input.Key, numberPad bool) bool {
if !isClickingKey(key) { return false }
if key != input.KeyEnter && key != input.Key(' ') { return false }
this.Choose()
return true
}
func (this *Swatch) handleButtonDown (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
return true
}
func (this *Swatch) handleButtonUp (button input.Button) bool {
if !isClickingButton(button) { return false }
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.Choose()
}

View File

@ -87,7 +87,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
} ()
switch {
case isConfirmationKey(key):
case key == input.KeyEnter:
this.on.confirm.Broadcast()
return true
case key == input.KeyBackspace:
@ -114,7 +114,7 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
modifiers := this.Window().Modifiers()
switch {
case isConfirmationKey(key):
case key == input.KeyEnter:
return true
case key == input.KeyBackspace:
return true