~eliasnaur/gio

162250392b3b2423f3e019bfbc25584e2b0192e7 — Elias Naur 1 year, 10 months ago b4acc23
layout: respect minimum constraint size in Flex.Layout

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2 files changed, 15 insertions(+), 0 deletions(-)

M layout/flex.go
M layout/layout_test.go
M layout/flex.go => layout/flex.go +1 -0
@@ 216,6 216,7 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
		}
	}
	sz := f.Axis.Convert(image.Pt(mainSize, maxCross))
	sz = cs.Constrain(sz)
	return Dimensions{Size: sz, Baseline: sz.Y - maxBaseline}
}


M layout/layout_test.go => layout/layout_test.go +14 -0
@@ 30,6 30,20 @@ func TestStack(t *testing.T) {
	}
}

func TestFlex(t *testing.T) {
	gtx := Context{
		Ops: new(op.Ops),
		Constraints: Constraints{
			Min: image.Pt(100, 100),
			Max: image.Pt(100, 100),
		},
	}
	dims := Flex{}.Layout(gtx)
	if got := dims.Size; got != gtx.Constraints.Min {
		t.Errorf("Flex ignored minimum constraints, got %v expected %v", got, gtx.Constraints.Min)
	}
}

func TestDirection(t *testing.T) {
	max := image.Pt(100, 100)
	for _, tc := range []struct {