mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
ui/app,ui/key: move TextInputState from key to internal package
Clients have no need for the TextInputState type. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -9,11 +9,13 @@ import (
|
|||||||
"gioui.org/ui/key"
|
"gioui.org/ui/key"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TextInputState uint8
|
||||||
|
|
||||||
type keyQueue struct {
|
type keyQueue struct {
|
||||||
focus input.Key
|
focus input.Key
|
||||||
handlers map[input.Key]*keyHandler
|
handlers map[input.Key]*keyHandler
|
||||||
reader ui.OpsReader
|
reader ui.OpsReader
|
||||||
state key.TextInputState
|
state TextInputState
|
||||||
}
|
}
|
||||||
|
|
||||||
type keyHandler struct {
|
type keyHandler struct {
|
||||||
@@ -29,9 +31,15 @@ const (
|
|||||||
priNewFocus
|
priNewFocus
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TextInputKeep TextInputState = iota
|
||||||
|
TextInputClose
|
||||||
|
TextInputOpen
|
||||||
|
)
|
||||||
|
|
||||||
// InputState returns the last text input state as
|
// InputState returns the last text input state as
|
||||||
// determined in Frame.
|
// determined in Frame.
|
||||||
func (q *keyQueue) InputState() key.TextInputState {
|
func (q *keyQueue) InputState() TextInputState {
|
||||||
return q.state
|
return q.state
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +61,6 @@ func (q *keyQueue) Frame(root *ui.Ops, events *handlerEvents) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changed := focus != nil && focus != q.focus
|
|
||||||
if focus != q.focus {
|
if focus != q.focus {
|
||||||
if q.focus != nil {
|
if q.focus != nil {
|
||||||
events.Add(q.focus, key.FocusEvent{Focus: false})
|
events.Add(q.focus, key.FocusEvent{Focus: false})
|
||||||
@@ -67,13 +74,11 @@ func (q *keyQueue) Frame(root *ui.Ops, events *handlerEvents) {
|
|||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case pri == priNewFocus:
|
case pri == priNewFocus:
|
||||||
q.state = key.TextInputOpen
|
q.state = TextInputOpen
|
||||||
case hide:
|
case hide:
|
||||||
q.state = key.TextInputClose
|
q.state = TextInputClose
|
||||||
case changed:
|
|
||||||
q.state = key.TextInputFocus
|
|
||||||
default:
|
default:
|
||||||
q.state = key.TextInputKeep
|
q.state = TextInputKeep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func (q *Router) Add(e input.Event) bool {
|
|||||||
return q.handlers.Updated()
|
return q.handlers.Updated()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Router) InputState() key.TextInputState {
|
func (q *Router) TextInputState() TextInputState {
|
||||||
return q.kqueue.InputState()
|
return q.kqueue.InputState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -393,20 +393,17 @@ func onTouchEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, action, pointer
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setTextInput(s key.TextInputState) {
|
func (w *window) showTextInput(show bool) {
|
||||||
if w.view == 0 {
|
if w.view == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch s {
|
runInJVM(func(env *C.JNIEnv) {
|
||||||
case key.TextInputOpen:
|
if show {
|
||||||
runInJVM(func(env *C.JNIEnv) {
|
|
||||||
C.gio_jni_CallVoidMethod(env, w.view, w.mshowTextInput)
|
C.gio_jni_CallVoidMethod(env, w.view, w.mshowTextInput)
|
||||||
})
|
} else {
|
||||||
case key.TextInputClose:
|
|
||||||
runInJVM(func(env *C.JNIEnv) {
|
|
||||||
C.gio_jni_CallVoidMethod(env, w.view, w.mhideTextInput)
|
C.gio_jni_CallVoidMethod(env, w.view, w.mhideTextInput)
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Main() {
|
func Main() {
|
||||||
|
|||||||
+3
-4
@@ -235,14 +235,13 @@ func (w *window) isVisible() bool {
|
|||||||
return w.visible.Load().(bool)
|
return w.visible.Load().(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setTextInput(s key.TextInputState) {
|
func (w *window) showTextInput(show bool) {
|
||||||
if w.view == 0 {
|
if w.view == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch s {
|
if show {
|
||||||
case key.TextInputOpen:
|
|
||||||
C.gio_showTextInput(w.view)
|
C.gio_showTextInput(w.view)
|
||||||
case key.TextInputClose:
|
} else {
|
||||||
C.gio_hideTextInput(w.view)
|
C.gio_hideTextInput(w.view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -317,11 +317,10 @@ func (w *window) setAnimating(anim bool) {
|
|||||||
w.animating = anim
|
w.animating = anim
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setTextInput(s key.TextInputState) {
|
func (w *window) showTextInput(show bool) {
|
||||||
switch s {
|
if show {
|
||||||
case key.TextInputOpen:
|
|
||||||
w.focus()
|
w.focus()
|
||||||
case key.TextInputClose:
|
} else {
|
||||||
w.blur()
|
w.blur()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ func (w *window) contextView() C.CFTypeRef {
|
|||||||
return w.view
|
return w.view
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setTextInput(s key.TextInputState) {}
|
func (w *window) showTextInput(show bool) {}
|
||||||
|
|
||||||
func (w *window) setAnimating(anim bool) {
|
func (w *window) setAnimating(anim bool) {
|
||||||
var animb C.BOOL
|
var animb C.BOOL
|
||||||
|
|||||||
@@ -1087,7 +1087,7 @@ func (w *window) nativeWindow(visID int) (unsafe.Pointer, int, int) {
|
|||||||
return unsafe.Pointer(w.surf), width * scale, height * scale
|
return unsafe.Pointer(w.surf), width * scale, height * scale
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setTextInput(s key.TextInputState) {}
|
func (w *window) showTextInput(show bool) {}
|
||||||
|
|
||||||
// detectFontScale reports current font scale, or 1.0
|
// detectFontScale reports current font scale, or 1.0
|
||||||
// if it fails.
|
// if it fails.
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ func (w *window) destroy() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) setTextInput(s key.TextInputState) {}
|
func (w *window) showTextInput(show bool) {}
|
||||||
|
|
||||||
func (w *window) display() uintptr {
|
func (w *window) display() uintptr {
|
||||||
return uintptr(w.hdc)
|
return uintptr(w.hdc)
|
||||||
|
|||||||
+12
-16
@@ -12,7 +12,6 @@ import (
|
|||||||
"gioui.org/ui/app/internal/gpu"
|
"gioui.org/ui/app/internal/gpu"
|
||||||
iinput "gioui.org/ui/app/internal/input"
|
iinput "gioui.org/ui/app/internal/input"
|
||||||
"gioui.org/ui/input"
|
"gioui.org/ui/input"
|
||||||
"gioui.org/ui/key"
|
|
||||||
"gioui.org/ui/system"
|
"gioui.org/ui/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,11 +22,10 @@ type WindowOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Window struct {
|
type Window struct {
|
||||||
driver *window
|
driver *window
|
||||||
lastFrame time.Time
|
lastFrame time.Time
|
||||||
drawStart time.Time
|
drawStart time.Time
|
||||||
gpu *gpu.GPU
|
gpu *gpu.GPU
|
||||||
inputState key.TextInputState
|
|
||||||
|
|
||||||
out chan Event
|
out chan Event
|
||||||
in chan Event
|
in chan Event
|
||||||
@@ -63,8 +61,8 @@ var _ interface {
|
|||||||
// setAnimating sets the animation flag. When the window is animating,
|
// setAnimating sets the animation flag. When the window is animating,
|
||||||
// DrawEvents are delivered as fast as the display can handle them.
|
// DrawEvents are delivered as fast as the display can handle them.
|
||||||
setAnimating(anim bool)
|
setAnimating(anim bool)
|
||||||
// setTextInput updates the virtual keyboard state.
|
// showTextInput updates the virtual keyboard state.
|
||||||
setTextInput(s key.TextInputState)
|
showTextInput(show bool)
|
||||||
} = (*window)(nil)
|
} = (*window)(nil)
|
||||||
|
|
||||||
// Pre-allocate the ack event to avoid garbage.
|
// Pre-allocate the ack event to avoid garbage.
|
||||||
@@ -103,13 +101,6 @@ func (w *Window) Events() <-chan Event {
|
|||||||
return w.out
|
return w.out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) setTextInput(s key.TextInputState) {
|
|
||||||
if s != w.inputState && (s == key.TextInputClose || s == key.TextInputOpen) {
|
|
||||||
w.driver.setTextInput(s)
|
|
||||||
}
|
|
||||||
w.inputState = s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Window) Queue() *Queue {
|
func (w *Window) Queue() *Queue {
|
||||||
return &w.queue
|
return &w.queue
|
||||||
}
|
}
|
||||||
@@ -127,7 +118,12 @@ func (w *Window) draw(size image.Point, frame *ui.Ops) {
|
|||||||
w.gpu.Draw(w.queue.q.Profiling(), size, frame)
|
w.gpu.Draw(w.queue.q.Profiling(), size, frame)
|
||||||
w.queue.q.Frame(frame)
|
w.queue.q.Frame(frame)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
w.setTextInput(w.queue.q.InputState())
|
switch w.queue.q.TextInputState() {
|
||||||
|
case iinput.TextInputOpen:
|
||||||
|
w.driver.showTextInput(true)
|
||||||
|
case iinput.TextInputClose:
|
||||||
|
w.driver.showTextInput(false)
|
||||||
|
}
|
||||||
frameDur := now.Sub(w.lastFrame)
|
frameDur := now.Sub(w.lastFrame)
|
||||||
frameDur = frameDur.Truncate(100 * time.Microsecond)
|
frameDur = frameDur.Truncate(100 * time.Microsecond)
|
||||||
w.lastFrame = now
|
w.lastFrame = now
|
||||||
|
|||||||
@@ -30,20 +30,11 @@ type EditEvent struct {
|
|||||||
|
|
||||||
type Modifiers uint32
|
type Modifiers uint32
|
||||||
|
|
||||||
type TextInputState uint8
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ModCommand Modifiers = 1 << iota
|
ModCommand Modifiers = 1 << iota
|
||||||
ModShift
|
ModShift
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
TextInputKeep TextInputState = iota
|
|
||||||
TextInputFocus
|
|
||||||
TextInputClose
|
|
||||||
TextInputOpen
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NameLeftArrow = '←'
|
NameLeftArrow = '←'
|
||||||
NameRightArrow = '→'
|
NameRightArrow = '→'
|
||||||
|
|||||||
Reference in New Issue
Block a user