Avoid div-by-0 in case Flex item sizes are all 0. Resolves #332, resolves #334

This commit is contained in:
Oliver 2019-10-17 11:33:25 +02:00
parent f8bc69b903
commit de7ae86b5b
1 changed files with 7 additions and 3 deletions

View File

@ -149,9 +149,13 @@ func (f *Flex) Draw(screen tcell.Screen) {
for _, item := range f.items { for _, item := range f.items {
size := item.FixedSize size := item.FixedSize
if size <= 0 { if size <= 0 {
if proportionSum > 0 {
size = distSize * item.Proportion / proportionSum size = distSize * item.Proportion / proportionSum
distSize -= size distSize -= size
proportionSum -= item.Proportion proportionSum -= item.Proportion
} else {
size = 0
}
} }
if item.Item != nil { if item.Item != nil {
if f.direction == FlexColumn { if f.direction == FlexColumn {