From 241e5660536fdea186ec4e0502673e1693e135c0 Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Sat, 23 Oct 2021 12:33:52 +0200 Subject: [PATCH] io/router: remove unnecessary panics while routing key ops Signed-off-by: Pierre Curto --- io/router/key.go | 29 ----------------------------- io/router/router.go | 14 +++++++++++--- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/io/router/key.go b/io/router/key.go index 357272cd..9fef7dcd 100644 --- a/io/router/key.go +++ b/io/router/key.go @@ -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: diff --git a/io/router/router.go b/io/router/router.go index 17712952..e0d7f0f0 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -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) } }