From de7ae86b5b6329ebd79ed8654cdb7325640e8594 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 17 Oct 2019 11:33:25 +0200 Subject: [PATCH] Avoid div-by-0 in case Flex item sizes are all 0. Resolves #332, resolves #334 --- flex.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/flex.go b/flex.go index 7235614..56cbc75 100644 --- a/flex.go +++ b/flex.go @@ -149,9 +149,13 @@ func (f *Flex) Draw(screen tcell.Screen) { for _, item := range f.items { size := item.FixedSize if size <= 0 { - size = distSize * item.Proportion / proportionSum - distSize -= size - proportionSum -= item.Proportion + if proportionSum > 0 { + size = distSize * item.Proportion / proportionSum + distSize -= size + proportionSum -= item.Proportion + } else { + size = 0 + } } if item.Item != nil { if f.direction == FlexColumn {