mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
ui: let OpsReader keep track of references
Instead of exposing the entire reference slice, return the relevant references from Next. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+3
-9
@@ -3,8 +3,6 @@
|
||||
package key
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
||||
"gioui.org/ui"
|
||||
"gioui.org/ui/internal/ops"
|
||||
)
|
||||
@@ -73,30 +71,26 @@ const (
|
||||
func (h OpHandler) Add(o *ui.Ops) {
|
||||
data := make([]byte, ops.TypeKeyHandlerLen)
|
||||
data[0] = byte(ops.TypeKeyHandler)
|
||||
bo := binary.LittleEndian
|
||||
if h.Focus {
|
||||
data[1] = 1
|
||||
}
|
||||
bo.PutUint32(data[2:], uint32(o.Ref(h.Key)))
|
||||
o.Write(data)
|
||||
o.Write(data, []interface{}{h.Key})
|
||||
}
|
||||
|
||||
func (h *OpHandler) Decode(d []byte, refs []interface{}) {
|
||||
bo := binary.LittleEndian
|
||||
if ops.OpType(d[0]) != ops.TypeKeyHandler {
|
||||
panic("invalid op")
|
||||
}
|
||||
key := int(bo.Uint32(d[2:]))
|
||||
*h = OpHandler{
|
||||
Focus: d[1] != 0,
|
||||
Key: refs[key].(Key),
|
||||
Key: refs[0].(Key),
|
||||
}
|
||||
}
|
||||
|
||||
func (h OpHideInput) Add(o *ui.Ops) {
|
||||
data := make([]byte, ops.TypeHideInputLen)
|
||||
data[0] = byte(ops.TypeHideInput)
|
||||
o.Write(data)
|
||||
o.Write(data, nil)
|
||||
}
|
||||
|
||||
func (Edit) ImplementsEvent() {}
|
||||
|
||||
+2
-2
@@ -80,14 +80,14 @@ func resolveFocus(r *ui.OpsReader, focus Key) (Key, listenerPriority, bool) {
|
||||
var hide bool
|
||||
loop:
|
||||
for {
|
||||
data, ok := r.Decode()
|
||||
data, refs, ok := r.Decode()
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
switch ops.OpType(data[0]) {
|
||||
case ops.TypeKeyHandler:
|
||||
var op OpHandler
|
||||
op.Decode(data, r.Refs)
|
||||
op.Decode(data, refs)
|
||||
var newPri listenerPriority
|
||||
switch {
|
||||
case op.Focus:
|
||||
|
||||
Reference in New Issue
Block a user