io/input,io/key: [API] replace SoftKeyboardOp with a command

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-09 16:37:21 -05:00
parent be36fc88aa
commit 5dd41f74d3
6 changed files with 18 additions and 34 deletions
-5
View File
@@ -69,7 +69,6 @@ const (
TypeTarget
TypeOffer
TypeKeyInput
TypeKeySoftKeyboard
TypeSave
TypeLoad
TypeAux
@@ -153,7 +152,6 @@ const (
TypeTargetLen = 1
TypeOfferLen = 1
TypeKeyInputLen = 1 + 1
TypeKeySoftKeyboardLen = 1 + 1
TypeSaveLen = 1 + 4
TypeLoadLen = 1 + 4
TypeAuxLen = 1
@@ -435,7 +433,6 @@ var opProps = [0x100]opProp{
TypeTarget: {Size: TypeTargetLen, NumRefs: 2},
TypeOffer: {Size: TypeOfferLen, NumRefs: 3},
TypeKeyInput: {Size: TypeKeyInputLen, NumRefs: 2},
TypeKeySoftKeyboard: {Size: TypeKeySoftKeyboardLen, NumRefs: 0},
TypeSave: {Size: TypeSaveLen, NumRefs: 0},
TypeLoad: {Size: TypeLoadLen, NumRefs: 0},
TypeAux: {Size: TypeAuxLen, NumRefs: 0},
@@ -511,8 +508,6 @@ func (t OpType) String() string {
return "Offer"
case TypeKeyInput:
return "KeyInput"
case TypeKeySoftKeyboard:
return "KeySoftKeyboard"
case TypeSave:
return "Save"
case TypeLoad:
+7 -7
View File
@@ -37,7 +37,7 @@ func TestKeyMultiples(t *testing.T) {
ops := new(op.Ops)
r := new(Router)
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
key.InputOp{Tag: &handlers[0]}.Add(ops)
r.Source().Queue(key.FocusCmd{Tag: &handlers[2]})
key.InputOp{Tag: &handlers[1]}.Add(ops)
@@ -61,11 +61,11 @@ func TestKeyStacked(t *testing.T) {
key.InputOp{Tag: &handlers[0]}.Add(ops)
r.Source().Queue(key.FocusCmd{})
key.SoftKeyboardOp{Show: false}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: false})
key.InputOp{Tag: &handlers[1]}.Add(ops)
r.Source().Queue(key.FocusCmd{Tag: &handlers[1]})
key.InputOp{Tag: &handlers[2]}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
key.InputOp{Tag: &handlers[3]}.Add(ops)
r.Frame(ops)
@@ -84,7 +84,7 @@ func TestKeySoftKeyboardNoFocus(t *testing.T) {
// It's possible to open the keyboard
// without any active focus:
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
r.Frame(ops)
@@ -100,7 +100,7 @@ func TestKeyRemoveFocus(t *testing.T) {
// New InputOp with Focus and Keyboard:
key.InputOp{Tag: &handlers[0], Keys: "Short-Tab"}.Add(ops)
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
// New InputOp without any focus:
key.InputOp{Tag: &handlers[1], Keys: "Short-Tab"}.Add(ops)
@@ -152,7 +152,7 @@ func TestKeyRemoveFocus(t *testing.T) {
// exists in the previous frame:
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
key.InputOp{Tag: &handlers[0]}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
// Remove focus.
key.InputOp{Tag: &handlers[1]}.Add(ops)
@@ -173,7 +173,7 @@ func TestKeyFocusedInvisible(t *testing.T) {
// Set new InputOp with focus:
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
key.InputOp{Tag: &handlers[0]}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
// Set new InputOp without focus:
key.InputOp{Tag: &handlers[1]}.Add(ops)
+2 -5
View File
@@ -216,6 +216,8 @@ func (q *Router) executeCommands() {
switch req := req.(type) {
case key.FocusCmd:
q.key.queue.Focus(req.Tag, &q.handlers)
case key.SoftKeyboardCmd:
q.key.queue.softKeyboard(req.Show)
}
}
q.commands = nil
@@ -504,11 +506,6 @@ func (q *Router) collect() {
act := system.Action(encOp.Data[1])
pc.actionInputOp(act)
case ops.TypeKeySoftKeyboard:
op := key.SoftKeyboardOp{
Show: encOp.Data[1] != 0,
}
kq.softKeyboard(op.Show)
case ops.TypeKeyInput:
filter := key.Set(*encOp.Refs[1].(*string))
op := key.InputOp{
+7 -15
View File
@@ -34,6 +34,11 @@ type InputOp struct {
Keys Set
}
// SoftKeyboardCmd shows or hides the on-screen keyboard, if available.
type SoftKeyboardCmd struct {
Show bool
}
// Set is an expression that describes a set of key combinations, in the form
// "<modifiers>-<keyset>|...". Modifiers are separated by dashes, optional
// modifiers are enclosed by parentheses. A key set is either a literal key
@@ -50,12 +55,6 @@ type InputOp struct {
// - Shift-(Ctrl)-A matches A if shift is pressed, and optionally ctrl.
type Set string
// SoftKeyboardOp shows or hide the on-screen keyboard, if available.
// It replaces any previous SoftKeyboardOp.
type SoftKeyboardOp struct {
Show bool
}
// SelectionOp updates the selection for an input handler.
type SelectionOp struct {
Tag event.Tag
@@ -337,14 +336,6 @@ func (h InputOp) Add(o *op.Ops) {
data[1] = byte(h.Hint)
}
func (h SoftKeyboardOp) Add(o *op.Ops) {
data := ops.Write(&o.Internal, ops.TypeKeySoftKeyboardLen)
data[0] = byte(ops.TypeKeySoftKeyboard)
if h.Show {
data[1] = 1
}
}
func (s SnippetOp) Add(o *op.Ops) {
data := ops.Write2String(&o.Internal, ops.TypeSnippetLen, s.Tag, s.Text)
data[0] = byte(ops.TypeSnippet)
@@ -371,7 +362,8 @@ func (FocusEvent) ImplementsEvent() {}
func (SnippetEvent) ImplementsEvent() {}
func (SelectionEvent) ImplementsEvent() {}
func (FocusCmd) ImplementsCommand() {}
func (FocusCmd) ImplementsCommand() {}
func (SoftKeyboardCmd) ImplementsCommand() {}
func (m Modifiers) String() string {
var strs []string
+1 -1
View File
@@ -646,7 +646,7 @@ func (e *Editor) layout(gtx layout.Context, textMaterial, selectMaterial op.Call
key.InputOp{Tag: &e.eventKey, Hint: e.InputHint, Keys: keys}.Add(gtx.Ops)
if e.requestFocus {
gtx.Queue(key.FocusCmd{Tag: &e.eventKey})
key.SoftKeyboardOp{Show: true}.Add(gtx.Ops)
gtx.Queue(key.SoftKeyboardCmd{Show: true})
}
e.requestFocus = false
+1 -1
View File
@@ -211,7 +211,7 @@ func (l *Selectable) Layout(gtx layout.Context, lt *text.Shaper, font font.Font,
key.InputOp{Tag: l, Keys: keys}.Add(gtx.Ops)
if l.requestFocus {
gtx.Queue(key.FocusCmd{Tag: l})
key.SoftKeyboardOp{Show: true}.Add(gtx.Ops)
gtx.Queue(key.SoftKeyboardCmd{Show: true})
}
l.requestFocus = false