From 162250392b3b2423f3e019bfbc25584e2b0192e7 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 8 Jul 2022 08:00:59 +0200 Subject: [PATCH] layout: respect minimum constraint size in Flex.Layout Signed-off-by: Elias Naur --- layout/flex.go | 1 + layout/layout_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/layout/flex.go b/layout/flex.go index 55ca0285..30472492 100644 --- a/layout/flex.go +++ b/layout/flex.go @@ -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} } diff --git a/layout/layout_test.go b/layout/layout_test.go index 8a44d0e9..c6434b2c 100644 --- a/layout/layout_test.go +++ b/layout/layout_test.go @@ -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 { -- 2.38.5