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:
Elias Naur
2019-06-01 20:48:36 +02:00
parent 5966aab77e
commit 0d2cffe196
11 changed files with 166 additions and 104 deletions
+3 -10
View File
@@ -3,7 +3,6 @@
package pointer
import (
"encoding/binary"
"time"
"gioui.org/ui"
@@ -72,26 +71,20 @@ const (
func (h OpHandler) Add(o *ui.Ops) {
data := make([]byte, ops.TypePointerHandlerLen)
data[0] = byte(ops.TypePointerHandler)
bo := binary.LittleEndian
if h.Grab {
data[1] = 1
}
bo.PutUint32(data[2:], uint32(o.Ref(h.Key)))
bo.PutUint32(data[6:], uint32(o.Ref(h.Area)))
o.Write(data)
o.Write(data, []interface{}{h.Key, h.Area})
}
func (h *OpHandler) Decode(d []byte, refs []interface{}) {
bo := binary.LittleEndian
if ops.OpType(d[0]) != ops.TypePointerHandler {
panic("invalid op")
}
key := int(bo.Uint32(d[2:]))
area := int(bo.Uint32(d[6:]))
*h = OpHandler{
Grab: d[1] != 0,
Key: refs[key].(Key),
Area: refs[area].(Area),
Key: refs[0].(Key),
Area: refs[1].(Area),
}
}
+2 -2
View File
@@ -39,7 +39,7 @@ type handler struct {
func (q *Queue) collectHandlers(r *ui.OpsReader, t ui.Transform, layer int) {
for {
data, ok := r.Decode()
data, refs, ok := r.Decode()
if !ok {
return
}
@@ -57,7 +57,7 @@ func (q *Queue) collectHandlers(r *ui.OpsReader, t ui.Transform, layer int) {
t = t.Mul(op.Transform)
case ops.TypePointerHandler:
var op OpHandler
op.Decode(data, r.Refs)
op.Decode(data, refs)
q.hitTree = append(q.hitTree, hitNode{level: layer, key: op.Key})
h, ok := q.handlers[op.Key]
if !ok {