forked from joejulian/gio
io/input,io/key: [API] introduce Command, replace FocusOp with FocusCmd
Modeling focus change as an operation is awkward, because focus changes logically happen during event processing, not layout. In particular, you want to apply focus changes even if a widget is subsequently never laid out. Now that input.Source is concrete, it's much more straightforward to offer focus changes as a command which can be queued through the Source. A future change may similarly offer a command for directional focus changes. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-2
@@ -122,7 +122,7 @@ func (b *Clickable) Update(gtx layout.Context) []Click {
|
||||
b.focused = false
|
||||
}
|
||||
if b.requestFocus {
|
||||
key.FocusOp{Tag: &b.keyTag}.Add(gtx.Ops)
|
||||
gtx.Queue(key.FocusCmd{Tag: &b.keyTag})
|
||||
b.requestFocus = false
|
||||
}
|
||||
for len(b.history) > 0 {
|
||||
@@ -159,7 +159,7 @@ func (b *Clickable) Update(gtx layout.Context) []Click {
|
||||
}
|
||||
case gesture.KindPress:
|
||||
if e.Source == pointer.Mouse {
|
||||
key.FocusOp{Tag: &b.keyTag}.Add(gtx.Ops)
|
||||
gtx.Queue(key.FocusCmd{Tag: &b.keyTag})
|
||||
}
|
||||
b.history = append(b.history, Press{
|
||||
Position: e.Position,
|
||||
|
||||
+1
-1
@@ -645,7 +645,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 {
|
||||
key.FocusOp{Tag: &e.eventKey}.Add(gtx.Ops)
|
||||
gtx.Queue(key.FocusCmd{Tag: &e.eventKey})
|
||||
key.SoftKeyboardOp{Show: true}.Add(gtx.Ops)
|
||||
}
|
||||
e.requestFocus = false
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ func (e *Enum) Update(gtx layout.Context) bool {
|
||||
switch ev.Kind {
|
||||
case gesture.KindPress:
|
||||
if ev.Source == pointer.Mouse {
|
||||
key.FocusOp{Tag: &state.tag}.Add(gtx.Ops)
|
||||
gtx.Queue(key.FocusCmd{Tag: &state.tag})
|
||||
}
|
||||
case gesture.KindClick:
|
||||
if state.key != e.Value {
|
||||
|
||||
@@ -210,7 +210,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 {
|
||||
key.FocusOp{Tag: l}.Add(gtx.Ops)
|
||||
gtx.Queue(key.FocusCmd{Tag: l})
|
||||
key.SoftKeyboardOp{Show: true}.Add(gtx.Ops)
|
||||
}
|
||||
l.requestFocus = false
|
||||
|
||||
Reference in New Issue
Block a user