mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
io/router/key: add explicit tag to FocusOp; make last SoftKeyboardOp apply
The target of FocusOp is too subtle; be explicit instead and remove any doubt. Multiple SoftKeyboardOp in a single frame is rare, but if they do occur, they should behave as if they were from separate frames: the last one applies. As a side-effect the key event router can be much simplified. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+7
-8
@@ -26,15 +26,17 @@ type InputOp struct {
|
||||
}
|
||||
|
||||
// SoftKeyboardOp shows or hide the on-screen keyboard, if available.
|
||||
// It replaces any previous SoftKeyboardOp.
|
||||
type SoftKeyboardOp struct {
|
||||
Show bool
|
||||
}
|
||||
|
||||
// FocusOp sets or clears the keyboard focus.
|
||||
// FocusOp sets or clears the keyboard focus. It replaces any previous
|
||||
// FocusOp in the same frame.
|
||||
type FocusOp struct {
|
||||
// Focus, if set, moves the focus to the current InputOp. If Focus
|
||||
// is false, the focus is cleared.
|
||||
Focus bool
|
||||
// Tag is the new focus. The focus is cleared if Tag is nil, or if Tag
|
||||
// has no InputOp in the same frame.
|
||||
Tag event.Tag
|
||||
}
|
||||
|
||||
// A FocusEvent is generated when a handler gains or loses
|
||||
@@ -132,11 +134,8 @@ func (h SoftKeyboardOp) Add(o *op.Ops) {
|
||||
}
|
||||
|
||||
func (h FocusOp) Add(o *op.Ops) {
|
||||
data := o.Write(opconst.TypeKeyFocusLen)
|
||||
data := o.Write1(opconst.TypeKeyFocusLen, h.Tag)
|
||||
data[0] = byte(opconst.TypeKeyFocus)
|
||||
if h.Focus {
|
||||
data[1] = 1
|
||||
}
|
||||
}
|
||||
|
||||
func (EditEvent) ImplementsEvent() {}
|
||||
|
||||
Reference in New Issue
Block a user