Add shortcut attributes ConfirmRune and BackRune

This commit is contained in:
Trevor Slocum 2024-01-21 16:18:31 -08:00
parent d2c44cc232
commit b8e1658b3f
4 changed files with 20 additions and 7 deletions

10
game.go
View File

@ -239,7 +239,15 @@ func Update() error {
runeBuffer = ebiten.AppendInputChars(runeBuffer[:0])
for _, r := range runeBuffer {
_, err := focusedWidget.HandleKeyboard(-1, r)
var err error
switch r {
case Bindings.ConfirmRune:
_, err = focusedWidget.HandleKeyboard(ebiten.KeyEnter, 0)
case Bindings.BackRune:
_, err = focusedWidget.HandleKeyboard(ebiten.KeyBackspace, 0)
default:
_, err = focusedWidget.HandleKeyboard(-1, r)
}
if err != nil {
return fmt.Errorf("failed to handle widget keyboard input: %s", err)
}

4
go.mod
View File

@ -9,10 +9,10 @@ require (
)
require (
github.com/ebitengine/purego v0.5.1 // indirect
github.com/ebitengine/purego v0.5.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/jezek/xgb v1.1.1 // indirect
golang.org/x/exp/shiny v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/exp/shiny v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/mobile v0.0.0-20240112133503-c713f31d574b // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect

8
go.sum
View File

@ -1,5 +1,5 @@
github.com/ebitengine/purego v0.5.1 h1:hNunhThpOf1vzKl49v6YxIsXLhl92vbBEv1/2Ez3ZrY=
github.com/ebitengine/purego v0.5.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/ebitengine/purego v0.5.2 h1:r2MQEtkGzZ4LRtFZVAg5bjYKnUbxxloaeuGxH0t7qfs=
github.com/ebitengine/purego v0.5.2/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/hajimehoshi/bitmapfont/v3 v3.0.0 h1:r2+6gYK38nfztS/et50gHAswb9hXgxXECYgE8Nczmi4=
@ -10,8 +10,8 @@ github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFl
github.com/llgcode/draw2d v0.0.0-20231212091825-f55e0c776b44 h1:1ad70i0s40IpMtRm2ST+Nvr03X7mlHWtdALYkFNrlxk=
github.com/llgcode/draw2d v0.0.0-20231212091825-f55e0c776b44/go.mod h1:muweRyJCZ1mZSMiCgYbAicfnwZFoeHpNr6A6QBu+rBg=
github.com/llgcode/ps v0.0.0-20210114104736-f4b0c5d1e02e h1:ZAvbj5hI/G/EbAYAcj4yCXUNiFKefEhH0qfImDDD0/8=
golang.org/x/exp/shiny v0.0.0-20240112132812-db7319d0e0e3 h1:NezsOJwoBjJ5AXH5QQCdxe+WsqLw+f/t8eo1Tacfhqs=
golang.org/x/exp/shiny v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:3F+MieQB7dRYLTmnncoFbb1crS5lfQoTfDgQy6K4N0o=
golang.org/x/exp/shiny v0.0.0-20240119083558-1b970713d09a h1:NZ9mAQhIcCceDZKqQX3JJVIz7nn3QLDuC+nXedsViBM=
golang.org/x/exp/shiny v0.0.0-20240119083558-1b970713d09a/go.mod h1:3F+MieQB7dRYLTmnncoFbb1crS5lfQoTfDgQy6K4N0o=
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/mobile v0.0.0-20240112133503-c713f31d574b h1:kfWLZgb8iUBHdE9WydD5V5dHIS/F6HjlBZNyJfn2bs4=

View File

@ -7,6 +7,11 @@ type Shortcuts struct {
ConfirmKeyboard []ebiten.Key
ConfirmMouse []ebiten.MouseButton
ConfirmGamepad []ebiten.GamepadButton
// A sentinel rune value may be set for the confirm and back actions.
// This allows working around on-screen keyboard issues on Android.
ConfirmRune rune
BackRune rune
}
// Bindings is the current keyboard shortcut configuration.