layout: unexport Context.Layout and make it a function

Layout wasn't used outside package layout, so let's not export it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-10-16 11:07:52 +02:00
parent e2d0b3cfca
commit 7f07933eb3
4 changed files with 17 additions and 16 deletions
+2 -2
View File
@@ -67,7 +67,7 @@ func (f *Flex) Rigid(gtx *Context, w Widget) FlexChild {
cs = axisConstraints(f.Axis, Constraint{Max: mainMax}, axisCrossConstraint(f.Axis, cs))
var m op.MacroOp
m.Record(gtx.Ops)
dims := gtx.Layout(cs, w)
dims := ctxLayout(gtx, cs, w)
m.Stop()
f.rigidSize += axisMain(f.Axis, dims.Size)
f.expand(dims)
@@ -95,7 +95,7 @@ func (f *Flex) Flex(gtx *Context, weight float32, w Widget) FlexChild {
cs = axisConstraints(f.Axis, submainc, axisCrossConstraint(f.Axis, cs))
var m op.MacroOp
m.Record(gtx.Ops)
dims := gtx.Layout(cs, w)
dims := ctxLayout(gtx, cs, w)
m.Stop()
f.expand(dims)
return FlexChild{m, dims}
+12 -11
View File
@@ -82,16 +82,17 @@ const (
Vertical
)
// Layout a widget with a set of constraints and return its
// dimensions. The previous constraints are restored after layout.
func (s *Context) Layout(cs Constraints, w Widget) Dimensions {
saved := s.Constraints
s.Constraints = cs
s.Dimensions = Dimensions{}
// layout a widget with a set of constraints and return its
// dimensions. The widget dimensions are constrained abd the previous
// constraints are restored after layout.
func ctxLayout(gtx *Context, cs Constraints, w Widget) Dimensions {
saved := gtx.Constraints
gtx.Constraints = cs
gtx.Dimensions = Dimensions{}
w()
s.Dimensions.Size = cs.Constrain(s.Dimensions.Size)
s.Constraints = saved
return s.Dimensions
gtx.Dimensions.Size = cs.Constrain(gtx.Dimensions.Size)
gtx.Constraints = saved
return gtx.Dimensions
}
// Reset the context. The constraints' minimum and maximum values are
@@ -166,7 +167,7 @@ func (in Inset) Layout(gtx *Context, w Widget) {
var stack op.StackOp
stack.Push(gtx.Ops)
op.TransformOp{}.Offset(toPointF(image.Point{X: left, Y: top})).Add(gtx.Ops)
dims := gtx.Layout(mcs, w)
dims := ctxLayout(gtx, mcs, w)
stack.Pop()
gtx.Dimensions = Dimensions{
Size: dims.Size.Add(image.Point{X: right + left, Y: top + bottom}),
@@ -188,7 +189,7 @@ func (a Align) Layout(gtx *Context, w Widget) {
mcs := cs
mcs.Width.Min = 0
mcs.Height.Min = 0
dims := gtx.Layout(mcs, w)
dims := ctxLayout(gtx, mcs, w)
macro.Stop()
sz := dims.Size
if sz.X < cs.Width.Min {
+1 -1
View File
@@ -93,7 +93,7 @@ func (l *List) Layout(gtx *Context, len int, w ListElement) {
for l.init(gtx, len); l.more(); l.next() {
cs := axisConstraints(l.Axis, Constraint{Max: inf}, axisCrossConstraint(l.Axis, l.ctx.Constraints))
i := l.index()
l.end(gtx.Layout(cs, func() {
l.end(ctxLayout(gtx, cs, func() {
w(i)
}))
}
+2 -2
View File
@@ -32,7 +32,7 @@ func (s *Stack) Rigid(gtx *Context, w Widget) StackChild {
cs.Height.Min = 0
var m op.MacroOp
m.Record(gtx.Ops)
dims := gtx.Layout(cs, w)
dims := ctxLayout(gtx, cs, w)
m.Stop()
s.expand(dims)
return StackChild{m, dims}
@@ -46,7 +46,7 @@ func (s *Stack) Expand(gtx *Context, w Widget) StackChild {
Width: Constraint{Min: s.maxSZ.X, Max: gtx.Constraints.Width.Max},
Height: Constraint{Min: s.maxSZ.Y, Max: gtx.Constraints.Height.Max},
}
dims := gtx.Layout(cs, w)
dims := ctxLayout(gtx, cs, w)
m.Stop()
s.expand(dims)
return StackChild{m, dims}