From e9cd8958de7ce1cae350ed5659e791c336fc445e Mon Sep 17 00:00:00 2001 From: pierre Date: Thu, 3 Dec 2020 14:02:37 +0100 Subject: [PATCH] layout: fixed divisions by zero in Flex.Layout Signed-off-by: pierre --- layout/flex.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/layout/flex.go b/layout/flex.go index fe85b644..2ccc4c25 100644 --- a/layout/flex.go +++ b/layout/flex.go @@ -165,7 +165,9 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions { case SpaceEvenly: mainSize += space / (1 + len(children)) case SpaceAround: - mainSize += space / (len(children) * 2) + if len(children) > 0 { + mainSize += space / (len(children) * 2) + } } for i, child := range children { dims := child.dims @@ -191,9 +193,13 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions { case SpaceEvenly: mainSize += space / (1 + len(children)) case SpaceAround: - mainSize += space / len(children) + if len(children) > 0 { + mainSize += space / len(children) + } case SpaceBetween: - mainSize += space / (len(children) - 1) + if len(children) > 1 { + mainSize += space / (len(children) - 1) + } } } } @@ -205,7 +211,9 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions { case SpaceEvenly: mainSize += space / (1 + len(children)) case SpaceAround: - mainSize += space / (len(children) * 2) + if len(children) > 0 { + mainSize += space / (len(children) * 2) + } } sz := axisPoint(f.Axis, mainSize, maxCross) return Dimensions{Size: sz, Baseline: sz.Y - maxBaseline}