layout: include Expanded sizes in Stack size calculation

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-01-16 13:20:50 +01:00
parent a7dc7c01c0
commit 18cddc0300
2 changed files with 33 additions and 0 deletions
+6
View File
@@ -83,6 +83,12 @@ func (s Stack) Layout(gtx *Context, children ...StackChild) {
}
dims := ctxLayout(gtx, cs, w.widget)
m.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 = m
children[i].dims = dims
}
+27
View File
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Unlicense OR MIT
package layout
import (
"image"
"testing"
)
func TestStack(t *testing.T) {
var gtx Context
gtx.Reset(nil, image.Point{X: 100, Y: 100})
gtx.Constraints.Width.Min = 0
gtx.Constraints.Height.Min = 0
exp := image.Point{X: 60, Y: 70}
Stack{Alignment: Center}.Layout(&gtx,
Expanded(func() {
gtx.Dimensions.Size = exp
}),
Stacked(func() {
gtx.Dimensions.Size = image.Point{X: 50, Y: 50}
}),
)
if got := gtx.Dimensions.Size; got != exp {
t.Errorf("Stack ignored Expanded size, got %v expected %v", got, exp)
}
}