Update code for objects

This commit is contained in:
2024-07-25 12:58:38 -04:00
parent 25a59d888c
commit 85fbe9c996
17 changed files with 247 additions and 163 deletions

View File

@@ -30,7 +30,9 @@ func NewSwatch (value color.Color) *Swatch {
swatch.SetDrawer(swatch)
swatch.SetValue(value)
swatch.OnButtonDown(swatch.handleButtonDown)
swatch.OnButtonUp(swatch.handleButtonUp)
swatch.OnKeyDown(swatch.handleKeyDown)
swatch.OnKeyUp(swatch.handleKeyUp)
swatch.SetFocusable(true)
return swatch
@@ -155,14 +157,26 @@ func (this *Swatch) userSetValue (value color.Color) {
this.on.valueChange.Broadcast()
}
func (this *Swatch) handleKeyUp (catch func (), key input.Key, numberPad bool) {
if key != input.KeyEnter && key != input.Key(' ') { return }
this.Choose()
func (this *Swatch) handleKeyDown (key input.Key, numberPad bool) bool {
if key != input.KeyEnter && key != input.Key(' ') { return false }
return true
}
func (this *Swatch) handleButtonUp (catch func (), button input.Button) {
if button != input.ButtonLeft { return }
func (this *Swatch) handleKeyUp (key input.Key, numberPad bool) bool {
if key != input.KeyEnter && key != input.Key(' ') { return false }
this.Choose()
return true
}
func (this *Swatch) handleButtonDown (button input.Button) bool {
if button != input.ButtonLeft { return false }
return true
}
func (this *Swatch) handleButtonUp (button input.Button) bool {
if button != input.ButtonLeft { return false }
if this.Window().MousePosition().In(this.Bounds()) {
this.Choose()
}
return true
}