From 4054f3d70848158a038e0b3a8a25c6cfee21e730 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sat, 30 Dec 2023 00:18:27 +0100 Subject: [PATCH] More cleanup of gridlayout code --- layout/gridlayout.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/layout/gridlayout.go b/layout/gridlayout.go index a67be66965..2d83fd59c7 100644 --- a/layout/gridlayout.go +++ b/layout/gridlayout.go @@ -78,17 +78,18 @@ func (g *gridLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) { rows := g.countRows(objects) padding := theme.Padding() - padWidth := float32(g.Cols-1) * padding - padHeight := float32(rows-1) * padding - cellWidth := float64(size.Width-padWidth) / float64(g.Cols) - cellHeight := float64(size.Height-padHeight) / float64(rows) - - if !g.horizontal() { - padWidth, padHeight = padHeight, padWidth - cellWidth = float64(size.Width-padWidth) / float64(rows) - cellHeight = float64(size.Height-padHeight) / float64(g.Cols) + + primaryObjects := rows + secondaryObjects := g.Cols + if g.horizontal() { + primaryObjects, secondaryObjects = secondaryObjects, primaryObjects } + padWidth := float32(primaryObjects-1) * padding + padHeight := float32(secondaryObjects-1) * padding + cellWidth := float64(size.Width-padWidth) / float64(primaryObjects) + cellHeight := float64(size.Height-padHeight) / float64(secondaryObjects) + row, col := 0, 0 i := 0 for _, child := range objects { @@ -139,13 +140,11 @@ func (g *gridLayout) MinSize(objects []fyne.CanvasObject) fyne.Size { } padding := theme.Padding() - var primaryObjects, secondaryObjects int + + primaryObjects := rows + secondaryObjects := g.Cols if g.horizontal() { - primaryObjects = g.Cols - secondaryObjects = rows - } else { - primaryObjects = rows - secondaryObjects = g.Cols + primaryObjects, secondaryObjects = secondaryObjects, primaryObjects } width := minSize.Width * float32(primaryObjects)