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:
Elias Naur
2019-07-21 13:12:24 +02:00
parent b46bad09bd
commit 9e0e4af8c6
10 changed files with 41 additions and 54 deletions
+13 -8
View File
@@ -9,11 +9,13 @@ import (
"gioui.org/ui/key"
)
type TextInputState uint8
type keyQueue struct {
focus input.Key
handlers map[input.Key]*keyHandler
reader ui.OpsReader
state key.TextInputState
state TextInputState
}
type keyHandler struct {
@@ -29,9 +31,15 @@ const (
priNewFocus
)
const (
TextInputKeep TextInputState = iota
TextInputClose
TextInputOpen
)
// InputState returns the last text input state as
// determined in Frame.
func (q *keyQueue) InputState() key.TextInputState {
func (q *keyQueue) InputState() TextInputState {
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 q.focus != nil {
events.Add(q.focus, key.FocusEvent{Focus: false})
@@ -67,13 +74,11 @@ func (q *keyQueue) Frame(root *ui.Ops, events *handlerEvents) {
}
switch {
case pri == priNewFocus:
q.state = key.TextInputOpen
q.state = TextInputOpen
case hide:
q.state = key.TextInputClose
case changed:
q.state = key.TextInputFocus
q.state = TextInputClose
default:
q.state = key.TextInputKeep
q.state = TextInputKeep
}
}
+1 -1
View File
@@ -65,7 +65,7 @@ func (q *Router) Add(e input.Event) bool {
return q.handlers.Updated()
}
func (q *Router) InputState() key.TextInputState {
func (q *Router) TextInputState() TextInputState {
return q.kqueue.InputState()
}
+6 -9
View File
@@ -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 {
return
}
switch s {
case key.TextInputOpen:
runInJVM(func(env *C.JNIEnv) {
runInJVM(func(env *C.JNIEnv) {
if show {
C.gio_jni_CallVoidMethod(env, w.view, w.mshowTextInput)
})
case key.TextInputClose:
runInJVM(func(env *C.JNIEnv) {
} else {
C.gio_jni_CallVoidMethod(env, w.view, w.mhideTextInput)
})
}
}
})
}
func Main() {
+3 -4
View File
@@ -235,14 +235,13 @@ func (w *window) isVisible() bool {
return w.visible.Load().(bool)
}
func (w *window) setTextInput(s key.TextInputState) {
func (w *window) showTextInput(show bool) {
if w.view == 0 {
return
}
switch s {
case key.TextInputOpen:
if show {
C.gio_showTextInput(w.view)
case key.TextInputClose:
} else {
C.gio_hideTextInput(w.view)
}
}
+3 -4
View File
@@ -317,11 +317,10 @@ func (w *window) setAnimating(anim bool) {
w.animating = anim
}
func (w *window) setTextInput(s key.TextInputState) {
switch s {
case key.TextInputOpen:
func (w *window) showTextInput(show bool) {
if show {
w.focus()
case key.TextInputClose:
} else {
w.blur()
}
}
+1 -1
View File
@@ -77,7 +77,7 @@ func (w *window) contextView() C.CFTypeRef {
return w.view
}
func (w *window) setTextInput(s key.TextInputState) {}
func (w *window) showTextInput(show bool) {}
func (w *window) setAnimating(anim bool) {
var animb C.BOOL
+1 -1
View File
@@ -1087,7 +1087,7 @@ func (w *window) nativeWindow(visID int) (unsafe.Pointer, int, int) {
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
// if it fails.
+1 -1
View File
@@ -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 {
return uintptr(w.hdc)
+12 -16
View File
@@ -12,7 +12,6 @@ import (
"gioui.org/ui/app/internal/gpu"
iinput "gioui.org/ui/app/internal/input"
"gioui.org/ui/input"
"gioui.org/ui/key"
"gioui.org/ui/system"
)
@@ -23,11 +22,10 @@ type WindowOptions struct {
}
type Window struct {
driver *window
lastFrame time.Time
drawStart time.Time
gpu *gpu.GPU
inputState key.TextInputState
driver *window
lastFrame time.Time
drawStart time.Time
gpu *gpu.GPU
out chan Event
in chan Event
@@ -63,8 +61,8 @@ var _ interface {
// setAnimating sets the animation flag. When the window is animating,
// DrawEvents are delivered as fast as the display can handle them.
setAnimating(anim bool)
// setTextInput updates the virtual keyboard state.
setTextInput(s key.TextInputState)
// showTextInput updates the virtual keyboard state.
showTextInput(show bool)
} = (*window)(nil)
// Pre-allocate the ack event to avoid garbage.
@@ -103,13 +101,6 @@ func (w *Window) Events() <-chan Event {
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 {
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.queue.q.Frame(frame)
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 = frameDur.Truncate(100 * time.Microsecond)
w.lastFrame = now
-9
View File
@@ -30,20 +30,11 @@ type EditEvent struct {
type Modifiers uint32
type TextInputState uint8
const (
ModCommand Modifiers = 1 << iota
ModShift
)
const (
TextInputKeep TextInputState = iota
TextInputFocus
TextInputClose
TextInputOpen
)
const (
NameLeftArrow = '←'
NameRightArrow = '→'