Skip to content

Commit

Permalink
Fix MinSize calculations in Form layout
Browse files Browse the repository at this point in the history
Fixes #4471
  • Loading branch information
andydotxyz committed Dec 22, 2023
1 parent cf8de0f commit 28c057c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion layout/formlayout.go
Expand Up @@ -42,6 +42,7 @@ func (f *formLayout) tableCellsSize(objects []fyne.CanvasObject, containerWidth
}

padding := theme.Padding()
innerPadding := theme.InnerPadding()
lowBound := 0
highBound := 2
labelCellMaxWidth := float32(0)
Expand All @@ -56,7 +57,7 @@ func (f *formLayout) tableCellsSize(objects []fyne.CanvasObject, containerWidth

labelCell := currentRow[0].MinSize()
if _, ok := currentRow[0].(*canvas.Text); ok {
labelCell.Width += padding * 4
labelCell.Width += innerPadding * 2
}
labelCellMaxWidth = fyne.Max(labelCellMaxWidth, labelCell.Width)

Expand Down
8 changes: 8 additions & 0 deletions layout/formlayout_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -106,6 +107,13 @@ func TestFormLayout_MinSize(t *testing.T) {
expectedRowWidth := 70 + 120 + theme.Padding()
expectedRowHeight := 100 + 80 + theme.Padding()
assert.Equal(t, fyne.NewSize(expectedRowWidth, expectedRowHeight), layoutMin)

text := canvas.NewText("Text", color.Black)
value := widget.NewLabel("Text")
l = layout.NewFormLayout()
layoutMin = l.MinSize([]fyne.CanvasObject{text, value})
// check that the text minsize is padded to match a label
assert.Equal(t, value.MinSize().Width*2+theme.Padding(), layoutMin.Width)
}

func TestFormLayout_MinSize_Hidden(t *testing.T) {
Expand Down

0 comments on commit 28c057c

Please sign in to comment.