forked from joejulian/gio
io/input,io/key: [API] replace SoftKeyboardOp with a command
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -69,7 +69,6 @@ const (
|
|||||||
TypeTarget
|
TypeTarget
|
||||||
TypeOffer
|
TypeOffer
|
||||||
TypeKeyInput
|
TypeKeyInput
|
||||||
TypeKeySoftKeyboard
|
|
||||||
TypeSave
|
TypeSave
|
||||||
TypeLoad
|
TypeLoad
|
||||||
TypeAux
|
TypeAux
|
||||||
@@ -153,7 +152,6 @@ const (
|
|||||||
TypeTargetLen = 1
|
TypeTargetLen = 1
|
||||||
TypeOfferLen = 1
|
TypeOfferLen = 1
|
||||||
TypeKeyInputLen = 1 + 1
|
TypeKeyInputLen = 1 + 1
|
||||||
TypeKeySoftKeyboardLen = 1 + 1
|
|
||||||
TypeSaveLen = 1 + 4
|
TypeSaveLen = 1 + 4
|
||||||
TypeLoadLen = 1 + 4
|
TypeLoadLen = 1 + 4
|
||||||
TypeAuxLen = 1
|
TypeAuxLen = 1
|
||||||
@@ -435,7 +433,6 @@ var opProps = [0x100]opProp{
|
|||||||
TypeTarget: {Size: TypeTargetLen, NumRefs: 2},
|
TypeTarget: {Size: TypeTargetLen, NumRefs: 2},
|
||||||
TypeOffer: {Size: TypeOfferLen, NumRefs: 3},
|
TypeOffer: {Size: TypeOfferLen, NumRefs: 3},
|
||||||
TypeKeyInput: {Size: TypeKeyInputLen, NumRefs: 2},
|
TypeKeyInput: {Size: TypeKeyInputLen, NumRefs: 2},
|
||||||
TypeKeySoftKeyboard: {Size: TypeKeySoftKeyboardLen, NumRefs: 0},
|
|
||||||
TypeSave: {Size: TypeSaveLen, NumRefs: 0},
|
TypeSave: {Size: TypeSaveLen, NumRefs: 0},
|
||||||
TypeLoad: {Size: TypeLoadLen, NumRefs: 0},
|
TypeLoad: {Size: TypeLoadLen, NumRefs: 0},
|
||||||
TypeAux: {Size: TypeAuxLen, NumRefs: 0},
|
TypeAux: {Size: TypeAuxLen, NumRefs: 0},
|
||||||
@@ -511,8 +508,6 @@ func (t OpType) String() string {
|
|||||||
return "Offer"
|
return "Offer"
|
||||||
case TypeKeyInput:
|
case TypeKeyInput:
|
||||||
return "KeyInput"
|
return "KeyInput"
|
||||||
case TypeKeySoftKeyboard:
|
|
||||||
return "KeySoftKeyboard"
|
|
||||||
case TypeSave:
|
case TypeSave:
|
||||||
return "Save"
|
return "Save"
|
||||||
case TypeLoad:
|
case TypeLoad:
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestKeyMultiples(t *testing.T) {
|
|||||||
ops := new(op.Ops)
|
ops := new(op.Ops)
|
||||||
r := new(Router)
|
r := new(Router)
|
||||||
|
|
||||||
key.SoftKeyboardOp{Show: true}.Add(ops)
|
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
|
||||||
key.InputOp{Tag: &handlers[0]}.Add(ops)
|
key.InputOp{Tag: &handlers[0]}.Add(ops)
|
||||||
r.Source().Queue(key.FocusCmd{Tag: &handlers[2]})
|
r.Source().Queue(key.FocusCmd{Tag: &handlers[2]})
|
||||||
key.InputOp{Tag: &handlers[1]}.Add(ops)
|
key.InputOp{Tag: &handlers[1]}.Add(ops)
|
||||||
@@ -61,11 +61,11 @@ func TestKeyStacked(t *testing.T) {
|
|||||||
|
|
||||||
key.InputOp{Tag: &handlers[0]}.Add(ops)
|
key.InputOp{Tag: &handlers[0]}.Add(ops)
|
||||||
r.Source().Queue(key.FocusCmd{})
|
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)
|
key.InputOp{Tag: &handlers[1]}.Add(ops)
|
||||||
r.Source().Queue(key.FocusCmd{Tag: &handlers[1]})
|
r.Source().Queue(key.FocusCmd{Tag: &handlers[1]})
|
||||||
key.InputOp{Tag: &handlers[2]}.Add(ops)
|
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)
|
key.InputOp{Tag: &handlers[3]}.Add(ops)
|
||||||
|
|
||||||
r.Frame(ops)
|
r.Frame(ops)
|
||||||
@@ -84,7 +84,7 @@ func TestKeySoftKeyboardNoFocus(t *testing.T) {
|
|||||||
|
|
||||||
// It's possible to open the keyboard
|
// It's possible to open the keyboard
|
||||||
// without any active focus:
|
// without any active focus:
|
||||||
key.SoftKeyboardOp{Show: true}.Add(ops)
|
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
|
||||||
|
|
||||||
r.Frame(ops)
|
r.Frame(ops)
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ func TestKeyRemoveFocus(t *testing.T) {
|
|||||||
// New InputOp with Focus and Keyboard:
|
// New InputOp with Focus and Keyboard:
|
||||||
key.InputOp{Tag: &handlers[0], Keys: "Short-Tab"}.Add(ops)
|
key.InputOp{Tag: &handlers[0], Keys: "Short-Tab"}.Add(ops)
|
||||||
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
|
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:
|
// New InputOp without any focus:
|
||||||
key.InputOp{Tag: &handlers[1], Keys: "Short-Tab"}.Add(ops)
|
key.InputOp{Tag: &handlers[1], Keys: "Short-Tab"}.Add(ops)
|
||||||
@@ -152,7 +152,7 @@ func TestKeyRemoveFocus(t *testing.T) {
|
|||||||
// exists in the previous frame:
|
// exists in the previous frame:
|
||||||
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
|
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
|
||||||
key.InputOp{Tag: &handlers[0]}.Add(ops)
|
key.InputOp{Tag: &handlers[0]}.Add(ops)
|
||||||
key.SoftKeyboardOp{Show: true}.Add(ops)
|
r.Source().Queue(key.SoftKeyboardCmd{Show: true})
|
||||||
|
|
||||||
// Remove focus.
|
// Remove focus.
|
||||||
key.InputOp{Tag: &handlers[1]}.Add(ops)
|
key.InputOp{Tag: &handlers[1]}.Add(ops)
|
||||||
@@ -173,7 +173,7 @@ func TestKeyFocusedInvisible(t *testing.T) {
|
|||||||
// Set new InputOp with focus:
|
// Set new InputOp with focus:
|
||||||
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
|
r.Source().Queue(key.FocusCmd{Tag: &handlers[0]})
|
||||||
key.InputOp{Tag: &handlers[0]}.Add(ops)
|
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:
|
// Set new InputOp without focus:
|
||||||
key.InputOp{Tag: &handlers[1]}.Add(ops)
|
key.InputOp{Tag: &handlers[1]}.Add(ops)
|
||||||
|
|||||||
+2
-5
@@ -216,6 +216,8 @@ func (q *Router) executeCommands() {
|
|||||||
switch req := req.(type) {
|
switch req := req.(type) {
|
||||||
case key.FocusCmd:
|
case key.FocusCmd:
|
||||||
q.key.queue.Focus(req.Tag, &q.handlers)
|
q.key.queue.Focus(req.Tag, &q.handlers)
|
||||||
|
case key.SoftKeyboardCmd:
|
||||||
|
q.key.queue.softKeyboard(req.Show)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
q.commands = nil
|
q.commands = nil
|
||||||
@@ -504,11 +506,6 @@ func (q *Router) collect() {
|
|||||||
act := system.Action(encOp.Data[1])
|
act := system.Action(encOp.Data[1])
|
||||||
pc.actionInputOp(act)
|
pc.actionInputOp(act)
|
||||||
|
|
||||||
case ops.TypeKeySoftKeyboard:
|
|
||||||
op := key.SoftKeyboardOp{
|
|
||||||
Show: encOp.Data[1] != 0,
|
|
||||||
}
|
|
||||||
kq.softKeyboard(op.Show)
|
|
||||||
case ops.TypeKeyInput:
|
case ops.TypeKeyInput:
|
||||||
filter := key.Set(*encOp.Refs[1].(*string))
|
filter := key.Set(*encOp.Refs[1].(*string))
|
||||||
op := key.InputOp{
|
op := key.InputOp{
|
||||||
|
|||||||
+6
-14
@@ -34,6 +34,11 @@ type InputOp struct {
|
|||||||
Keys Set
|
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
|
// Set is an expression that describes a set of key combinations, in the form
|
||||||
// "<modifiers>-<keyset>|...". Modifiers are separated by dashes, optional
|
// "<modifiers>-<keyset>|...". Modifiers are separated by dashes, optional
|
||||||
// modifiers are enclosed by parentheses. A key set is either a literal key
|
// 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.
|
// - Shift-(Ctrl)-A matches A if shift is pressed, and optionally ctrl.
|
||||||
type Set string
|
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.
|
// SelectionOp updates the selection for an input handler.
|
||||||
type SelectionOp struct {
|
type SelectionOp struct {
|
||||||
Tag event.Tag
|
Tag event.Tag
|
||||||
@@ -337,14 +336,6 @@ func (h InputOp) Add(o *op.Ops) {
|
|||||||
data[1] = byte(h.Hint)
|
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) {
|
func (s SnippetOp) Add(o *op.Ops) {
|
||||||
data := ops.Write2String(&o.Internal, ops.TypeSnippetLen, s.Tag, s.Text)
|
data := ops.Write2String(&o.Internal, ops.TypeSnippetLen, s.Tag, s.Text)
|
||||||
data[0] = byte(ops.TypeSnippet)
|
data[0] = byte(ops.TypeSnippet)
|
||||||
@@ -372,6 +363,7 @@ func (SnippetEvent) ImplementsEvent() {}
|
|||||||
func (SelectionEvent) ImplementsEvent() {}
|
func (SelectionEvent) ImplementsEvent() {}
|
||||||
|
|
||||||
func (FocusCmd) ImplementsCommand() {}
|
func (FocusCmd) ImplementsCommand() {}
|
||||||
|
func (SoftKeyboardCmd) ImplementsCommand() {}
|
||||||
|
|
||||||
func (m Modifiers) String() string {
|
func (m Modifiers) String() string {
|
||||||
var strs []string
|
var strs []string
|
||||||
|
|||||||
+1
-1
@@ -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)
|
key.InputOp{Tag: &e.eventKey, Hint: e.InputHint, Keys: keys}.Add(gtx.Ops)
|
||||||
if e.requestFocus {
|
if e.requestFocus {
|
||||||
gtx.Queue(key.FocusCmd{Tag: &e.eventKey})
|
gtx.Queue(key.FocusCmd{Tag: &e.eventKey})
|
||||||
key.SoftKeyboardOp{Show: true}.Add(gtx.Ops)
|
gtx.Queue(key.SoftKeyboardCmd{Show: true})
|
||||||
}
|
}
|
||||||
e.requestFocus = false
|
e.requestFocus = false
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
key.InputOp{Tag: l, Keys: keys}.Add(gtx.Ops)
|
||||||
if l.requestFocus {
|
if l.requestFocus {
|
||||||
gtx.Queue(key.FocusCmd{Tag: l})
|
gtx.Queue(key.FocusCmd{Tag: l})
|
||||||
key.SoftKeyboardOp{Show: true}.Add(gtx.Ops)
|
gtx.Queue(key.SoftKeyboardCmd{Show: true})
|
||||||
}
|
}
|
||||||
l.requestFocus = false
|
l.requestFocus = false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user