mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
op: remove operation list argument from MacroOp.Add
The ability to invoke other operation lists belongs in the new CallOp. While we're here, make MacroOp.Add use a pointer receiver to match the other methods. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -31,7 +31,7 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
TypeMacroDefLen = 1 + 4 + 4
|
TypeMacroDefLen = 1 + 4 + 4
|
||||||
TypeMacroLen = 1 + 4 + 4 + 4
|
TypeMacroLen = 1 + 4 + 4
|
||||||
TypeTransformLen = 1 + 4*2
|
TypeTransformLen = 1 + 4*2
|
||||||
TypeLayerLen = 1
|
TypeLayerLen = 1
|
||||||
TypeRedrawLen = 1 + 8
|
TypeRedrawLen = 1 + 8
|
||||||
@@ -77,7 +77,7 @@ func (t OpType) Size() int {
|
|||||||
|
|
||||||
func (t OpType) NumRefs() int {
|
func (t OpType) NumRefs() int {
|
||||||
switch t {
|
switch t {
|
||||||
case TypeMacro, TypeKeyInput, TypePointerInput, TypeProfile, TypeCall:
|
case TypeKeyInput, TypePointerInput, TypeProfile, TypeCall:
|
||||||
return 1
|
return 1
|
||||||
case TypeImage:
|
case TypeImage:
|
||||||
return 2
|
return 2
|
||||||
|
|||||||
+4
-15
@@ -33,9 +33,7 @@ type Key struct {
|
|||||||
|
|
||||||
// Shadow of op.MacroOp.
|
// Shadow of op.MacroOp.
|
||||||
type macroOp struct {
|
type macroOp struct {
|
||||||
ops *op.Ops
|
pc pc
|
||||||
version int
|
|
||||||
pc pc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shadow of op.CallOp.
|
// Shadow of op.CallOp.
|
||||||
@@ -119,16 +117,11 @@ func (r *Reader) Decode() (EncodedOp, bool) {
|
|||||||
continue
|
continue
|
||||||
case opconst.TypeMacro:
|
case opconst.TypeMacro:
|
||||||
var op macroOp
|
var op macroOp
|
||||||
op.decode(data, refs)
|
op.decode(data)
|
||||||
macroOps := op.ops
|
macroData := r.ops.Data()[op.pc.data:]
|
||||||
macroData := macroOps.Data()
|
|
||||||
macroData = macroData[op.pc.data:]
|
|
||||||
if opconst.OpType(macroData[0]) != opconst.TypeMacroDef {
|
if opconst.OpType(macroData[0]) != opconst.TypeMacroDef {
|
||||||
panic("invalid macro reference")
|
panic("invalid macro reference")
|
||||||
}
|
}
|
||||||
if op.version != op.ops.Version() {
|
|
||||||
panic("invalid MacroOp reference to reset Ops")
|
|
||||||
}
|
|
||||||
var opDef opMacroDef
|
var opDef opMacroDef
|
||||||
opDef.decode(macroData[:opconst.TypeMacroDef.Size()])
|
opDef.decode(macroData[:opconst.TypeMacroDef.Size()])
|
||||||
retPC := r.pc
|
retPC := r.pc
|
||||||
@@ -139,7 +132,6 @@ func (r *Reader) Decode() (EncodedOp, bool) {
|
|||||||
retPC: retPC,
|
retPC: retPC,
|
||||||
endPC: opDef.endpc,
|
endPC: opDef.endpc,
|
||||||
})
|
})
|
||||||
r.ops = macroOps
|
|
||||||
r.pc = op.pc
|
r.pc = op.pc
|
||||||
r.pc.data += opconst.TypeMacroDef.Size()
|
r.pc.data += opconst.TypeMacroDef.Size()
|
||||||
r.pc.refs += opconst.TypeMacroDef.NumRefs()
|
r.pc.refs += opconst.TypeMacroDef.NumRefs()
|
||||||
@@ -180,20 +172,17 @@ func (m *callOp) decode(data []byte, refs []interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *macroOp) decode(data []byte, refs []interface{}) {
|
func (m *macroOp) decode(data []byte) {
|
||||||
if opconst.OpType(data[0]) != opconst.TypeMacro {
|
if opconst.OpType(data[0]) != opconst.TypeMacro {
|
||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
dataIdx := int(int32(bo.Uint32(data[1:])))
|
dataIdx := int(int32(bo.Uint32(data[1:])))
|
||||||
refsIdx := int(int32(bo.Uint32(data[5:])))
|
refsIdx := int(int32(bo.Uint32(data[5:])))
|
||||||
version := int(int32(bo.Uint32(data[9:])))
|
|
||||||
*m = macroOp{
|
*m = macroOp{
|
||||||
ops: refs[0].(*op.Ops),
|
|
||||||
pc: pc{
|
pc: pc{
|
||||||
data: dataIdx,
|
data: dataIdx,
|
||||||
refs: refsIdx,
|
refs: refsIdx,
|
||||||
},
|
},
|
||||||
version: version,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -173,7 +173,7 @@ func (f *Flex) Layout(gtx *Context, children ...FlexChild) {
|
|||||||
var stack op.StackOp
|
var stack op.StackOp
|
||||||
stack.Push(gtx.Ops)
|
stack.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(toPointF(axisPoint(f.Axis, mainSize, cross))).Add(gtx.Ops)
|
op.TransformOp{}.Offset(toPointF(axisPoint(f.Axis, mainSize, cross))).Add(gtx.Ops)
|
||||||
child.macro.Add(gtx.Ops)
|
child.macro.Add()
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
mainSize += axisMain(f.Axis, dims.Size)
|
mainSize += axisMain(f.Axis, dims.Size)
|
||||||
if i < len(children)-1 {
|
if i < len(children)-1 {
|
||||||
|
|||||||
+1
-1
@@ -173,7 +173,7 @@ func (a Align) Layout(gtx *Context, w Widget) {
|
|||||||
var stack op.StackOp
|
var stack op.StackOp
|
||||||
stack.Push(gtx.Ops)
|
stack.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(toPointF(p)).Add(gtx.Ops)
|
op.TransformOp{}.Offset(toPointF(p)).Add(gtx.Ops)
|
||||||
macro.Add(gtx.Ops)
|
macro.Add()
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
gtx.Dimensions = Dimensions{
|
gtx.Dimensions = Dimensions{
|
||||||
Size: sz,
|
Size: sz,
|
||||||
|
|||||||
+2
-2
@@ -262,7 +262,7 @@ func (l *List) layout() Dimensions {
|
|||||||
stack.Push(ops)
|
stack.Push(ops)
|
||||||
clip.Rect{Rect: toRectF(r)}.Op(ops).Add(ops)
|
clip.Rect{Rect: toRectF(r)}.Op(ops).Add(ops)
|
||||||
op.TransformOp{}.Offset(toPointF(axisPoint(l.Axis, pos, cross))).Add(ops)
|
op.TransformOp{}.Offset(toPointF(axisPoint(l.Axis, pos, cross))).Add(ops)
|
||||||
child.macro.Add(ops)
|
child.macro.Add()
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
pos += childSize
|
pos += childSize
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ func (l *List) layout() Dimensions {
|
|||||||
l.macro.Stop()
|
l.macro.Stop()
|
||||||
pointer.Rect(image.Rectangle{Max: dims}).Add(ops)
|
pointer.Rect(image.Rectangle{Max: dims}).Add(ops)
|
||||||
l.scroll.Add(ops)
|
l.scroll.Add(ops)
|
||||||
l.macro.Add(ops)
|
l.macro.Add()
|
||||||
return Dimensions{Size: dims}
|
return Dimensions{Size: dims}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -97,7 +97,7 @@ func (s *Stack) Layout(gtx *Context, children ...StackChild) {
|
|||||||
var stack op.StackOp
|
var stack op.StackOp
|
||||||
stack.Push(gtx.Ops)
|
stack.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(toPointF(p)).Add(gtx.Ops)
|
op.TransformOp{}.Offset(toPointF(p)).Add(gtx.Ops)
|
||||||
ch.macro.Add(gtx.Ops)
|
ch.macro.Add()
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
if baseline == 0 {
|
if baseline == 0 {
|
||||||
if b := ch.dims.Baseline; b != 0 {
|
if b := ch.dims.Baseline; b != 0 {
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ type Op struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p Op) Add(o *op.Ops) {
|
func (p Op) Add(o *op.Ops) {
|
||||||
p.macro.Add(o)
|
p.macro.Add()
|
||||||
data := o.Write(opconst.TypeClipLen)
|
data := o.Write(opconst.TypeClipLen)
|
||||||
data[0] = byte(opconst.TypeClip)
|
data[0] = byte(opconst.TypeClip)
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ The MacroOp records a list of operations to be executed later:
|
|||||||
macro.Stop()
|
macro.Stop()
|
||||||
|
|
||||||
// replay the recorded operations by calling Add:
|
// replay the recorded operations by calling Add:
|
||||||
macro.Add(ops)
|
macro.Add()
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package op
|
package op
|
||||||
@@ -106,7 +106,6 @@ type StackOp struct {
|
|||||||
type MacroOp struct {
|
type MacroOp struct {
|
||||||
recording bool
|
recording bool
|
||||||
ops *Ops
|
ops *Ops
|
||||||
version int
|
|
||||||
id stackID
|
id stackID
|
||||||
pc pc
|
pc pc
|
||||||
}
|
}
|
||||||
@@ -255,25 +254,21 @@ func (m *MacroOp) fill() {
|
|||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
bo.PutUint32(data[1:], uint32(pc.data))
|
bo.PutUint32(data[1:], uint32(pc.data))
|
||||||
bo.PutUint32(data[5:], uint32(pc.refs))
|
bo.PutUint32(data[5:], uint32(pc.refs))
|
||||||
m.version = m.ops.version
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the recorded list of operations. The Ops
|
// Add the recorded list of operations.
|
||||||
// argument may be different than the Ops argument
|
func (m *MacroOp) Add() {
|
||||||
// passed to Record.
|
|
||||||
func (m MacroOp) Add(o *Ops) {
|
|
||||||
if m.recording {
|
if m.recording {
|
||||||
panic("a recording is in progress")
|
panic("a recording is in progress")
|
||||||
}
|
}
|
||||||
if m.ops == nil {
|
if m.ops == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := o.Write(opconst.TypeMacroLen, m.ops)
|
data := m.ops.Write(opconst.TypeMacroLen)
|
||||||
data[0] = byte(opconst.TypeMacro)
|
data[0] = byte(opconst.TypeMacro)
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
bo.PutUint32(data[1:], uint32(m.pc.data))
|
bo.PutUint32(data[1:], uint32(m.pc.data))
|
||||||
bo.PutUint32(data[5:], uint32(m.pc.refs))
|
bo.PutUint32(data[5:], uint32(m.pc.refs))
|
||||||
bo.PutUint32(data[9:], uint32(m.version))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r InvalidateOp) Add(o *Ops) {
|
func (r InvalidateOp) Add(o *Ops) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ func (e Editor) Layout(gtx *layout.Context, editor *widget.Editor) {
|
|||||||
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
|
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
|
||||||
editor.PaintText(gtx)
|
editor.PaintText(gtx)
|
||||||
} else {
|
} else {
|
||||||
macro.Add(gtx.Ops)
|
macro.Add()
|
||||||
}
|
}
|
||||||
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
|
paint.ColorOp{Color: e.Color}.Add(gtx.Ops)
|
||||||
editor.PaintCaret(gtx)
|
editor.PaintCaret(gtx)
|
||||||
|
|||||||
Reference in New Issue
Block a user