io/router: remove unnecessary panics while routing key ops

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2021-10-23 12:33:52 +02:00
committed by Elias Naur
parent da0e1bd439
commit 241e566053
2 changed files with 11 additions and 32 deletions
-29
View File
@@ -3,7 +3,6 @@
package router
import (
"gioui.org/internal/ops"
"gioui.org/io/event"
"gioui.org/io/key"
)
@@ -130,34 +129,6 @@ func (k *keyCollector) inputOp(op key.InputOp) {
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 {
switch t {
case TextInputKeep:
+11 -3
View File
@@ -201,13 +201,21 @@ func (q *Router) collect() {
// Key ops.
case ops.TypeKeyFocus:
op := decodeFocusOp(encOp.Data, encOp.Refs)
tag, _ := encOp.Refs[0].(event.Tag)
op := key.FocusOp{
Tag: tag,
}
kc.focusOp(op.Tag)
case ops.TypeKeySoftKeyboard:
op := decodeSoftKeyboardOp(encOp.Data, encOp.Refs)
op := key.SoftKeyboardOp{
Show: encOp.Data[1] != 0,
}
kc.softKeyboard(op.Show)
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)
}
}