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
+2 -8
View File
@@ -3,7 +3,6 @@
package draw
import (
"encoding/binary"
"math"
"gioui.org/ui"
@@ -37,20 +36,15 @@ func (p *Path) Data() interface{} {
func (c OpClip) Add(o *ui.Ops) {
data := make([]byte, ops.TypeClipLen)
data[0] = byte(ops.TypeClip)
bo := binary.LittleEndian
ref := o.Ref(c.Path)
bo.PutUint32(data[1:], uint32(ref))
o.Write(data)
o.Write(data, []interface{}{c.Path})
}
func (c *OpClip) Decode(d []byte, refs []interface{}) {
bo := binary.LittleEndian
if ops.OpType(d[0]) != ops.TypeClip {
panic("invalid op")
}
ref := int(bo.Uint32(d[1:]))
*c = OpClip{
Path: refs[ref].(*Path),
Path: refs[0].(*Path),
}
}