mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Compare commits
7 Commits
3e170c6b5a
...
1af300b98c
Author | SHA1 | Date | |
---|---|---|---|
|
1af300b98c | ||
|
dc8dfae3bf | ||
|
ffb77757f0 | ||
|
60f0a03749 | ||
|
22339c2510 | ||
|
96e0fd7a50 | ||
|
546c47878d |
@ -47,7 +47,7 @@ var (
|
||||
flagAutoRestore = flag.Bool("autorestore", false, "restore the window automatically")
|
||||
flagInitFocused = flag.Bool("initfocused", true, "whether the window is focused on start")
|
||||
flagMinWindowSize = flag.String("minwindowsize", "", "minimum window size (e.g., 100x200)")
|
||||
flagMaxWindowSize = flag.String("maxwindowsize", "", "maximium window size (e.g., 1920x1080)")
|
||||
flagMaxWindowSize = flag.String("maxwindowsize", "", "maximum window size (e.g., 1920x1080)")
|
||||
flagGraphicsLibrary = flag.String("graphicslibrary", "", "graphics library (e.g. opengl)")
|
||||
flagRunnableOnUnfocused = flag.Bool("runnableonunfocused", true, "whether the app is runnable even on unfocused")
|
||||
)
|
||||
|
@ -106,7 +106,7 @@ func (f *Field) HandleInput(x, y int) (handled bool, err error) {
|
||||
f.ch, f.end = Start(x, y)
|
||||
// Start returns nil for non-supported envrionments.
|
||||
if f.ch == nil {
|
||||
return true, nil
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,10 @@ func (t *textInput) init() {
|
||||
e.Call("preventDefault")
|
||||
}
|
||||
if e.Get("code").String() == "Enter" || e.Get("key").String() == "Enter" {
|
||||
// Ignore Enter key to avoid ebiten.IsKeyPressed(ebiten.KeyEnter) unexpectedly becomes true, especially for iOS Safari.
|
||||
// Ignore Enter key to avoid ebiten.IsKeyPressed(ebiten.KeyEnter) unexpectedly becomes true.
|
||||
e.Call("preventDefault")
|
||||
ui.Get().UpdateInputFromEvent(e)
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}
|
||||
if !e.Get("isComposing").Bool() {
|
||||
@ -96,6 +99,11 @@ func (t *textInput) init() {
|
||||
}))
|
||||
t.textareaElement.Call("addEventListener", "input", js.FuncOf(func(this js.Value, args []js.Value) any {
|
||||
e := args[0]
|
||||
// On iOS Safari, `isComposing` can be undefined.
|
||||
if e.Get("isComposing").IsUndefined() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}
|
||||
if e.Get("isComposing").Bool() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
@ -109,8 +117,12 @@ func (t *textInput) init() {
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}
|
||||
// Though `isComposing` is false, send the text as being not committed for text completion on mobile browsers.
|
||||
t.trySend(false)
|
||||
// Though `isComposing` is false, send the text as being not committed for text completion with a virtual keyboard.
|
||||
if ui.IsVirtualKeyboard() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}))
|
||||
t.textareaElement.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) any {
|
||||
@ -172,7 +184,13 @@ func (t *textInput) Start(x, y int) (chan State, func()) {
|
||||
s := newSession()
|
||||
t.session = s
|
||||
}
|
||||
return t.session.ch, t.session.end
|
||||
return t.session.ch, func() {
|
||||
if t.session != nil {
|
||||
t.session.end()
|
||||
// Reset the session explictly, or a new session cannot be created above.
|
||||
t.session = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if t.session != nil {
|
||||
@ -193,6 +211,10 @@ func (t *textInput) trySend(committed bool) {
|
||||
}
|
||||
|
||||
textareaValue := t.textareaElement.Get("value").String()
|
||||
if textareaValue == "" {
|
||||
return
|
||||
}
|
||||
|
||||
start := t.textareaElement.Get("selectionStart").Int()
|
||||
end := t.textareaElement.Get("selectionEnd").Int()
|
||||
startInBytes := convertUTF16CountToByteCount(textareaValue, start)
|
||||
|
12
go.mod
12
go.mod
@ -9,20 +9,20 @@ require (
|
||||
github.com/ebitengine/purego v0.8.0-alpha.2
|
||||
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f
|
||||
github.com/go-text/typesetting v0.1.1
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4
|
||||
github.com/jakecoffman/cp v1.2.1
|
||||
github.com/jezek/xgb v1.1.1
|
||||
github.com/jfreymuth/oggvorbis v1.0.5
|
||||
github.com/kisielk/errcheck v1.7.0
|
||||
golang.org/x/image v0.16.0
|
||||
golang.org/x/image v0.17.0
|
||||
golang.org/x/sync v0.7.0
|
||||
golang.org/x/sys v0.20.0
|
||||
golang.org/x/text v0.15.0
|
||||
golang.org/x/tools v0.21.0
|
||||
golang.org/x/sys v0.21.0
|
||||
golang.org/x/text v0.16.0
|
||||
golang.org/x/tools v0.22.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/jfreymuth/vorbis v1.0.2 // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/mod v0.18.0 // indirect
|
||||
)
|
||||
|
24
go.sum
24
go.sum
@ -11,8 +11,8 @@ github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRR
|
||||
github.com/go-text/typesetting v0.1.1 h1:bGAesCuo85nXnEN5LmFMVGAGpGkCPtHrZLi//qD7EJo=
|
||||
github.com/go-text/typesetting v0.1.1/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20231211103740-d9332ae51f04 h1:zBx+p/W2aQYtNuyZNcTfinWvXBQwYtDfme051PR/lAY=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1 h1:GLoMNCbvXOd39tFkqk9w/MI0xSLJaDzEOOl8mT1ILtI=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.1/go.mod h1:VVaVK/4HpV1MHWswCl5miFOuLoRVyIplB3qEJxZK2OA=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2 h1:3x/UYntkuEcDN8kjSohmR+ddDSFEB8Bsvm/QFug+teA=
|
||||
github.com/hajimehoshi/bitmapfont/v3 v3.2.0-alpha.2/go.mod h1:VVaVK/4HpV1MHWswCl5miFOuLoRVyIplB3qEJxZK2OA=
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4 h1:NUP7pBYH8OguP4diaTZ9wJbUbk3tC0KlfzsEpWmYj68=
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4/go.mod h1:fRtZraRFcWb0pu7ok0LqyFhCUrPeMsGRSVop0eemFmo=
|
||||
github.com/hajimehoshi/oto/v2 v2.3.1/go.mod h1:seWLbgHH7AyUMYKfKYT9pg7PhUu9/SisyJvNTT+ASQo=
|
||||
@ -31,12 +31,12 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
||||
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
|
||||
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
|
||||
golang.org/x/image v0.17.0 h1:nTRVVdajgB8zCMZVsViyzhnMKPwYeroEERRC64JuLco=
|
||||
golang.org/x/image v0.17.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
|
||||
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
@ -54,8 +54,8 @@ golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
@ -64,12 +64,12 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
|
||||
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
|
||||
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
@ -16,6 +16,7 @@ package ui
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strings"
|
||||
"syscall/js"
|
||||
"unicode"
|
||||
)
|
||||
@ -64,6 +65,11 @@ var codeToMouseButton = map[int]MouseButton{
|
||||
|
||||
func eventToKeys(e js.Value) (key0, key1 Key, fromKeyProperty bool) {
|
||||
id := jsCodeToID(e.Get("code"))
|
||||
|
||||
// On mobile browsers, treat enter key as if this is from a `key` property.
|
||||
if IsVirtualKeyboard() && id == KeyEnter {
|
||||
return KeyEnter, -1, true
|
||||
}
|
||||
if id >= 0 {
|
||||
return id, -1, false
|
||||
}
|
||||
@ -426,3 +432,15 @@ func (i *InputState) resetForBlur() {
|
||||
}
|
||||
i.Touches = i.Touches[:0]
|
||||
}
|
||||
|
||||
func IsVirtualKeyboard() bool {
|
||||
// Detect a virtual keyboard by the user agent.
|
||||
// Note that this is not a correct way to detect a virtual keyboard.
|
||||
// In the future, we should use the `navigator.virtualKeyboard` API.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/virtualKeyboard
|
||||
ua := js.Global().Get("navigator").Get("userAgent").String()
|
||||
if strings.Contains(ua, "Android") || strings.Contains(ua, "iPhone") || strings.Contains(ua, "iPad") || strings.Contains(ua, "iPod") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user