op: add package op for operations

Extract operation types from package ui into package op.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-09-30 15:41:15 +02:00
parent eba1b3a95f
commit 8cf35a1f97
27 changed files with 225 additions and 227 deletions
+3 -3
View File
@@ -6,17 +6,17 @@ import (
"encoding/binary"
"math"
"gioui.org/ui"
"gioui.org/f32"
"gioui.org/internal/opconst"
"gioui.org/op"
)
func DecodeTransformOp(d []byte) ui.TransformOp {
func DecodeTransformOp(d []byte) op.TransformOp {
bo := binary.LittleEndian
if opconst.OpType(d[0]) != opconst.TypeTransform {
panic("invalid op")
}
return ui.TransformOp{}.Offset(f32.Point{
return op.TransformOp{}.Offset(f32.Point{
X: math.Float32frombits(bo.Uint32(d[1:])),
Y: math.Float32frombits(bo.Uint32(d[5:])),
})
+8 -8
View File
@@ -5,15 +5,15 @@ package ops
import (
"encoding/binary"
"gioui.org/ui"
"gioui.org/internal/opconst"
"gioui.org/op"
)
// Reader parses an ops list.
type Reader struct {
pc pc
stack []macro
ops *ui.Ops
ops *op.Ops
}
// EncodedOp represents an encoded op returned by
@@ -26,14 +26,14 @@ type EncodedOp struct {
// Key is a unique key for a given op.
type Key struct {
ops *ui.Ops
ops *op.Ops
pc int
version int
}
// Shadow of ui.MacroOp.
// Shadow of op.MacroOp.
type macroOp struct {
ops *ui.Ops
ops *op.Ops
version int
pc pc
}
@@ -44,7 +44,7 @@ type pc struct {
}
type macro struct {
ops *ui.Ops
ops *op.Ops
retPC pc
endPC pc
}
@@ -58,7 +58,7 @@ type opAux struct {
}
// Reset start reading from the op list.
func (r *Reader) Reset(ops *ui.Ops) {
func (r *Reader) Reset(ops *op.Ops) {
r.stack = r.stack[:0]
r.pc = pc{}
r.ops = ops
@@ -170,7 +170,7 @@ func (m *macroOp) decode(data []byte, refs []interface{}) {
refsIdx := int(int32(bo.Uint32(data[5:])))
version := int(int32(bo.Uint32(data[9:])))
*m = macroOp{
ops: refs[0].(*ui.Ops),
ops: refs[0].(*op.Ops),
pc: pc{
data: dataIdx,
refs: refsIdx,