mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
op: add op.Push and op.Record funcs
The funcs replace stack.Push and macro.Record, which become private. This makes stack and macro faster to write, in particular for stacks where you can just write the following line to save and restore the state : defer op.Push(ops).Pop() This usage requires Push to return a pointer (since Pop has a pointer receiver), or else the code doesn't compile. For consistancy, I tried to do the same for op.Record, but this implied to turn all the MacroOp fields into pointers, and this caused some panics. As a result, op.Record doesn't return a pointer. An other side effect pointed by Larry Clapp: StackOp and MacroOp are not re-usable any more, you have to allocate a new one for each usage, using the described funcs above. Signed-off-by: Thomas Bruyelle <thomas.bruyelle@gmail.com>
This commit is contained in:
committed by
Elias Naur
parent
bade277876
commit
ae8a377cda
+7
-10
@@ -89,15 +89,14 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
|
||||
}
|
||||
crossMin, crossMax := axisCrossConstraint(f.Axis, cs)
|
||||
cs = axisConstraints(f.Axis, 0, mainMax, crossMin, crossMax)
|
||||
var m op.MacroOp
|
||||
m.Record(gtx.Ops)
|
||||
macro := op.Record(gtx.Ops)
|
||||
gtx := gtx
|
||||
gtx.Constraints = cs
|
||||
dims := child.widget(gtx)
|
||||
m.Stop()
|
||||
macro.Stop()
|
||||
sz := axisMain(f.Axis, dims.Size)
|
||||
size += sz
|
||||
children[i].macro = m
|
||||
children[i].macro = macro
|
||||
children[i].dims = dims
|
||||
}
|
||||
rigidSize := size
|
||||
@@ -124,15 +123,14 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
|
||||
}
|
||||
crossMin, crossMax := axisCrossConstraint(f.Axis, cs)
|
||||
cs = axisConstraints(f.Axis, flexSize, flexSize, crossMin, crossMax)
|
||||
var m op.MacroOp
|
||||
m.Record(gtx.Ops)
|
||||
macro := op.Record(gtx.Ops)
|
||||
gtx := gtx
|
||||
gtx.Constraints = cs
|
||||
dims := child.widget(gtx)
|
||||
m.Stop()
|
||||
macro.Stop()
|
||||
sz := axisMain(f.Axis, dims.Size)
|
||||
size += sz
|
||||
children[i].macro = m
|
||||
children[i].macro = macro
|
||||
children[i].dims = dims
|
||||
}
|
||||
var maxCross int
|
||||
@@ -176,8 +174,7 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
|
||||
cross = maxBaseline - b
|
||||
}
|
||||
}
|
||||
var stack op.StackOp
|
||||
stack.Push(gtx.Ops)
|
||||
stack := op.Push(gtx.Ops)
|
||||
op.TransformOp{}.Offset(FPt(axisPoint(f.Axis, mainSize, cross))).Add(gtx.Ops)
|
||||
child.macro.Add()
|
||||
stack.Pop()
|
||||
|
||||
Reference in New Issue
Block a user