op: change CallOp to be a return value from MacroOp.Stop

Converting

	macro := op.Record(ops)
	...
	macro.Stop()

	macro.Add()

to

	macro := op.Record(ops)
	...
	call := macro.Stop()

	call.Add(ops)

Which is more general (call.Add can take a different ops than the op.Record
that started it), and enforced the order between Stop and the subsequent Add.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-02 12:07:20 +02:00
parent ce0cc706ad
commit c19ed05342
10 changed files with 69 additions and 110 deletions
+7 -7
View File
@@ -28,8 +28,8 @@ type FlexChild struct {
widget Widget
// Scratch space.
macro op.MacroOp
dims Dimensions
call op.CallOp
dims Dimensions
}
// Spacing determine the spacing mode for a Flex.
@@ -93,10 +93,10 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
gtx := gtx
gtx.Constraints = cs
dims := child.widget(gtx)
macro.Stop()
c := macro.Stop()
sz := axisMain(f.Axis, dims.Size)
size += sz
children[i].macro = macro
children[i].call = c
children[i].dims = dims
}
rigidSize := size
@@ -127,10 +127,10 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
gtx := gtx
gtx.Constraints = cs
dims := child.widget(gtx)
macro.Stop()
c := macro.Stop()
sz := axisMain(f.Axis, dims.Size)
size += sz
children[i].macro = macro
children[i].call = c
children[i].dims = dims
}
var maxCross int
@@ -176,7 +176,7 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
}
stack := op.Push(gtx.Ops)
op.TransformOp{}.Offset(FPt(axisPoint(f.Axis, mainSize, cross))).Add(gtx.Ops)
child.macro.Add()
child.call.Add(gtx.Ops)
stack.Pop()
mainSize += axisMain(f.Axis, dims.Size)
if i < len(children)-1 {
+2 -2
View File
@@ -158,7 +158,7 @@ func (a Direction) Layout(gtx Context, w Widget) Dimensions {
cs := gtx.Constraints
gtx.Constraints.Min = image.Point{}
dims := w(gtx)
macro.Stop()
call := macro.Stop()
sz := dims.Size
if sz.X < cs.Min.X {
sz.X = cs.Min.X
@@ -181,7 +181,7 @@ func (a Direction) Layout(gtx Context, w Widget) Dimensions {
}
stack := op.Push(gtx.Ops)
op.TransformOp{}.Offset(FPt(p)).Add(gtx.Ops)
macro.Add()
call.Add(gtx.Ops)
stack.Pop()
return Dimensions{
Size: sz,
+7 -7
View File
@@ -12,8 +12,8 @@ import (
)
type scrollChild struct {
size image.Point
macro op.MacroOp
size image.Point
call op.CallOp
}
// List displays a subsection of a potentially infinitely
@@ -181,8 +181,8 @@ func (l *List) nextDir() iterationDir {
// End the current child by specifying its dimensions.
func (l *List) end(dims Dimensions) {
l.child.Stop()
child := scrollChild{dims.Size, l.child}
call := l.child.Stop()
child := scrollChild{dims.Size, call}
mainSize := axisMain(l.Axis, child.size)
l.maxSize += mainSize
switch l.dir {
@@ -260,7 +260,7 @@ func (l *List) layout() Dimensions {
stack := op.Push(ops)
clip.Rect{Rect: FRect(r)}.Op(ops).Add(ops)
op.TransformOp{}.Offset(FPt(axisPoint(l.Axis, pos, cross))).Add(ops)
child.macro.Add()
child.call.Add(ops)
stack.Pop()
pos += childSize
}
@@ -277,10 +277,10 @@ func (l *List) layout() Dimensions {
pos = mainMax
}
dims := axisPoint(l.Axis, pos, maxCross)
l.macro.Stop()
call := l.macro.Stop()
defer op.Push(l.ctx.Ops).Pop()
pointer.Rect(image.Rectangle{Max: dims}).Add(ops)
l.scroll.Add(ops)
l.macro.Add()
call.Add(ops)
return Dimensions{Size: dims}
}
+7 -7
View File
@@ -22,8 +22,8 @@ type StackChild struct {
widget Widget
// Scratch space.
macro op.MacroOp
dims Dimensions
call op.CallOp
dims Dimensions
}
// Stacked returns a Stack child that is laid out with no minimum
@@ -58,14 +58,14 @@ func (s Stack) Layout(gtx Context, children ...StackChild) Dimensions {
gtx := gtx
gtx.Constraints.Min = image.Pt(0, 0)
dims := w.widget(gtx)
macro.Stop()
call := macro.Stop()
if w := dims.Size.X; w > maxSZ.X {
maxSZ.X = w
}
if h := dims.Size.Y; h > maxSZ.Y {
maxSZ.Y = h
}
children[i].macro = macro
children[i].call = call
children[i].dims = dims
}
// Then lay out Expanded children.
@@ -79,14 +79,14 @@ func (s Stack) Layout(gtx Context, children ...StackChild) Dimensions {
Min: maxSZ, Max: gtx.Constraints.Max,
}
dims := w.widget(gtx)
macro.Stop()
call := macro.Stop()
if w := dims.Size.X; w > maxSZ.X {
maxSZ.X = w
}
if h := dims.Size.Y; h > maxSZ.Y {
maxSZ.Y = h
}
children[i].macro = macro
children[i].call = call
children[i].dims = dims
}
@@ -109,7 +109,7 @@ func (s Stack) Layout(gtx Context, children ...StackChild) Dimensions {
}
stack := op.Push(gtx.Ops)
op.TransformOp{}.Offset(FPt(p)).Add(gtx.Ops)
ch.macro.Add()
ch.call.Add(gtx.Ops)
stack.Pop()
if baseline == 0 {
if b := ch.dims.Baseline; b != 0 {