mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
op: introduce CallOp
We'd like to improve the API of Flex, Stack and similar layouts that use MacroOps internall. Unfortunately, the func (m MacroOp) Add(o *Ops) method causes the MacroOp to be allocated on the heap, ruining the nice garbage-free property of layouts. Fortunately, layouts don't need the feature that caused the heap allocation: invoking operation lists different than the current. CallOp separates the invoke-different-list semantic from MacroOp, in preparation for removing the feature from MacroOp. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -45,6 +45,12 @@ The StackOp saves the current state to the state stack and restores it later:
|
||||
// Restore the previous transform.
|
||||
stack.Pop()
|
||||
|
||||
The CallOp invokes another operation list:
|
||||
|
||||
ops := new(op.Ops)
|
||||
ops2 := new(op.Ops)
|
||||
op.CallOp{Ops: ops2}.Add(ops)
|
||||
|
||||
The MacroOp records a list of operations to be executed later:
|
||||
|
||||
ops := new(op.Ops)
|
||||
@@ -105,6 +111,13 @@ type MacroOp struct {
|
||||
pc pc
|
||||
}
|
||||
|
||||
// CallOp invokes all the operations from a separate
|
||||
// operations list.
|
||||
type CallOp struct {
|
||||
// Ops is the list of operations to invoke.
|
||||
Ops *Ops
|
||||
}
|
||||
|
||||
// InvalidateOp requests a redraw at the given time. Use
|
||||
// the zero value to request an immediate redraw.
|
||||
type InvalidateOp struct {
|
||||
@@ -134,6 +147,15 @@ type pc struct {
|
||||
refs int
|
||||
}
|
||||
|
||||
// Add the call to the operation list.
|
||||
func (c CallOp) Add(o *Ops) {
|
||||
if c.Ops == nil {
|
||||
return
|
||||
}
|
||||
data := o.Write(opconst.TypeCallLen, c.Ops)
|
||||
data[0] = byte(opconst.TypeCall)
|
||||
}
|
||||
|
||||
// Push (save) the current operations state.
|
||||
func (s *StackOp) Push(o *Ops) {
|
||||
if s.active {
|
||||
|
||||
Reference in New Issue
Block a user