forked from joejulian/gio
io/router: remove unnecessary panics while routing key ops
Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gioui.org/internal/ops"
|
|
||||||
"gioui.org/io/event"
|
"gioui.org/io/event"
|
||||||
"gioui.org/io/key"
|
"gioui.org/io/key"
|
||||||
)
|
)
|
||||||
@@ -130,34 +129,6 @@ func (k *keyCollector) inputOp(op key.InputOp) {
|
|||||||
h.hint = op.Hint
|
h.hint = op.Hint
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeKeyInputOp(d []byte, refs []interface{}) key.InputOp {
|
|
||||||
if ops.OpType(d[0]) != ops.TypeKeyInput {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
return key.InputOp{
|
|
||||||
Tag: refs[0].(event.Tag),
|
|
||||||
Hint: key.InputHint(d[1]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeSoftKeyboardOp(d []byte, refs []interface{}) key.SoftKeyboardOp {
|
|
||||||
if ops.OpType(d[0]) != ops.TypeKeySoftKeyboard {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
return key.SoftKeyboardOp{
|
|
||||||
Show: d[1] != 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeFocusOp(d []byte, refs []interface{}) key.FocusOp {
|
|
||||||
if ops.OpType(d[0]) != ops.TypeKeyFocus {
|
|
||||||
panic("invalid op")
|
|
||||||
}
|
|
||||||
return key.FocusOp{
|
|
||||||
Tag: refs[0],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t TextInputState) String() string {
|
func (t TextInputState) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case TextInputKeep:
|
case TextInputKeep:
|
||||||
|
|||||||
+11
-3
@@ -201,13 +201,21 @@ func (q *Router) collect() {
|
|||||||
|
|
||||||
// Key ops.
|
// Key ops.
|
||||||
case ops.TypeKeyFocus:
|
case ops.TypeKeyFocus:
|
||||||
op := decodeFocusOp(encOp.Data, encOp.Refs)
|
tag, _ := encOp.Refs[0].(event.Tag)
|
||||||
|
op := key.FocusOp{
|
||||||
|
Tag: tag,
|
||||||
|
}
|
||||||
kc.focusOp(op.Tag)
|
kc.focusOp(op.Tag)
|
||||||
case ops.TypeKeySoftKeyboard:
|
case ops.TypeKeySoftKeyboard:
|
||||||
op := decodeSoftKeyboardOp(encOp.Data, encOp.Refs)
|
op := key.SoftKeyboardOp{
|
||||||
|
Show: encOp.Data[1] != 0,
|
||||||
|
}
|
||||||
kc.softKeyboard(op.Show)
|
kc.softKeyboard(op.Show)
|
||||||
case ops.TypeKeyInput:
|
case ops.TypeKeyInput:
|
||||||
op := decodeKeyInputOp(encOp.Data, encOp.Refs)
|
op := key.InputOp{
|
||||||
|
Tag: encOp.Refs[0].(event.Tag),
|
||||||
|
Hint: key.InputHint(encOp.Data[1]),
|
||||||
|
}
|
||||||
kc.inputOp(op)
|
kc.inputOp(op)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user