Allow sending raw keyboard events to widgets
This commit is contained in:
parent
2e69eb4fe1
commit
f36fbb8087
6 changed files with 19 additions and 3 deletions
6
box.go
6
box.go
|
@ -3,6 +3,8 @@ package etk
|
|||
import (
|
||||
"image"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type Box struct {
|
||||
|
@ -41,6 +43,10 @@ func (b *Box) Focus() bool {
|
|||
return b.focus
|
||||
}
|
||||
|
||||
func (b *Box) HandleKeyboardEvent(key ebiten.Key, r rune) (handled bool, err error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (b *Box) Children() []Widget {
|
||||
b.Lock()
|
||||
defer b.Unlock()
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module code.rocket9labs.com/tslocum/etk
|
|||
go 1.18
|
||||
|
||||
require (
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231021230727-3fa5b72a505d
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231022192419-8bc4edaf3b20
|
||||
github.com/hajimehoshi/ebiten/v2 v2.6.2
|
||||
golang.org/x/image v0.13.0
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
|||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231021230727-3fa5b72a505d h1:YawBCDIsfoAE7JGhHiUC4FVw99W9I3/AnubzfOG5nAQ=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231021230727-3fa5b72a505d/go.mod h1:xszLyTZtpyjCVaGmznizLSAlnvraPOSoanlzUBeqGco=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231022192419-8bc4edaf3b20 h1:cnTDOm9qgrfSLlvg3linckRIoTzxIVazaVROIYib5n8=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.4-0.20231022192419-8bc4edaf3b20/go.mod h1:xszLyTZtpyjCVaGmznizLSAlnvraPOSoanlzUBeqGco=
|
||||
github.com/ebitengine/purego v0.5.0 h1:JrMGKfRIAM4/QVKaesIIT7m/UVjTj5GYhRSQYwfVdpo=
|
||||
github.com/ebitengine/purego v0.5.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.0.0 h1:r2+6gYK38nfztS/et50gHAswb9hXgxXECYgE8Nczmi4=
|
||||
|
|
5
input.go
5
input.go
|
@ -80,6 +80,11 @@ func (i *Input) HandleKeyboard() (handled bool, err error) {
|
|||
return true, err
|
||||
}
|
||||
|
||||
func (i *Input) HandleKeyboardEvent(key ebiten.Key, r rune) (handled bool, err error) {
|
||||
i.Field.HandleKeyboardEvent(key, r)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (i *Input) Draw(screen *ebiten.Image) error {
|
||||
// Draw label.
|
||||
i.Field.Draw(screen)
|
||||
|
|
4
text.go
4
text.go
|
@ -66,6 +66,10 @@ func (t *Text) HandleKeyboard() (handled bool, err error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
func (f *Text) HandleKeyboardEvent(key ebiten.Key, r rune) (handled bool, err error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (t *Text) Draw(screen *ebiten.Image) error {
|
||||
// Draw label.
|
||||
t.TextField.Draw(screen)
|
||||
|
|
|
@ -12,6 +12,7 @@ type Widget interface {
|
|||
SetFocus(focus bool)
|
||||
HandleMouse(cursor image.Point, pressed bool, clicked bool) (handled bool, err error)
|
||||
HandleKeyboard() (handled bool, err error)
|
||||
HandleKeyboardEvent(ebiten.Key, rune) (handled bool, err error)
|
||||
Draw(screen *ebiten.Image) error
|
||||
Children() []Widget
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue