From 1af438e24c07a8bd02866995139ef21cf01c6474 Mon Sep 17 00:00:00 2001 From: Jacob Date: Fri, 29 Dec 2023 23:52:26 +0100 Subject: [PATCH] Optimize MinSize for gridlayout --- layout/gridlayout.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/layout/gridlayout.go b/layout/gridlayout.go index f0a64a8e62..e5e99946c8 100644 --- a/layout/gridlayout.go +++ b/layout/gridlayout.go @@ -62,7 +62,6 @@ func (g *gridLayout) countRows(objects []fyne.CanvasObject) int { // size is the ideal cell size and the offset is which col or row its on. func getLeading(size float64, offset int) float32 { ret := (size + float64(theme.Padding())) * float64(offset) - return float32(ret) } @@ -139,11 +138,19 @@ func (g *gridLayout) MinSize(objects []fyne.CanvasObject) fyne.Size { minSize = minSize.Max(child.MinSize()) } + padding := theme.Padding() if g.horizontal() { minContentSize := fyne.NewSize(minSize.Width*float32(g.Cols), minSize.Height*float32(rows)) - return minContentSize.Add(fyne.NewSize(theme.Padding()*fyne.Max(float32(g.Cols-1), 0), theme.Padding()*fyne.Max(float32(rows-1), 0))) + if rows == 0 { + return minContentSize + } + + return minContentSize.Add(fyne.NewSize(padding*float32(g.Cols-1), padding*float32(rows-1))) } minContentSize := fyne.NewSize(minSize.Width*float32(rows), minSize.Height*float32(g.Cols)) - return minContentSize.Add(fyne.NewSize(theme.Padding()*fyne.Max(float32(rows-1), 0), theme.Padding()*fyne.Max(float32(g.Cols-1), 0))) + if rows == 0 { + return minContentSize + } + return minContentSize.Add(fyne.NewSize(padding*float32(rows-1), padding*float32(g.Cols-1))) }