Skip to content

Commit

Permalink
Fix dialog content to expand instead of use min size. (#1367)
Browse files Browse the repository at this point in the history
* Fix dialog content to expand instead of use min size.

* Dialog already provides horizontal padding on its edges.

* Increase horizontal padding and update test images

* Update to use const width padding for horizontal padding

* Center the text in the label in the base test

* Make content sizing code read clearer

* Remove extra padding and improve code readability for sizing

* Use padHeight instead of theme.Padding() between label and content

* Update color dialog images to work with dialog changes

* I think this file slipped in by accident. Not sure what it is.
  • Loading branch information
okratitan committed Oct 7, 2020
1 parent 5d4d997 commit a7b74d9
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 11 deletions.
21 changes: 11 additions & 10 deletions dialog/base.go
Expand Up @@ -108,32 +108,33 @@ func (d *dialog) Show() {
}

func (d *dialog) Layout(obj []fyne.CanvasObject, size fyne.Size) {
d.bg.Move(fyne.NewPos(-theme.Padding(), -theme.Padding()))
d.bg.Resize(size.Add(fyne.NewSize(theme.Padding()*2, theme.Padding()*2)))
d.bg.Move(fyne.NewPos(0, 0))
d.bg.Resize(size)

textMin := obj[2].MinSize()
btnMin := obj[3].MinSize().Union(obj[3].Size())

// icon
iconHeight := padHeight*2 + d.label.MinSize().Height*2 - theme.Padding()
obj[0].Resize(fyne.NewSize(iconHeight, iconHeight))
obj[0].Move(fyne.NewPos(size.Width-iconHeight+theme.Padding(), -theme.Padding()))

// content (text)
obj[2].Move(fyne.NewPos(size.Width/2-(textMin.Width/2), size.Height-padHeight-btnMin.Height-textMin.Height-theme.Padding()))
obj[2].Resize(fyne.NewSize(textMin.Width, textMin.Height))

// buttons
obj[3].Resize(btnMin)
obj[3].Move(fyne.NewPos(size.Width/2-(btnMin.Width/2), size.Height-padHeight-btnMin.Height))

// content
contentStart := d.label.Position().Y + d.label.MinSize().Height + padHeight
contentEnd := obj[3].Position().Y - theme.Padding()
obj[2].Move(fyne.NewPos((padWidth / 2), d.label.MinSize().Height+padHeight))
obj[2].Resize(fyne.NewSize(size.Width-padWidth, contentEnd-contentStart))
}

func (d *dialog) MinSize(obj []fyne.CanvasObject) fyne.Size {
textMin := obj[2].MinSize()
contentMin := obj[2].MinSize()
btnMin := obj[3].MinSize().Union(obj[3].Size())

width := fyne.Max(fyne.Max(textMin.Width, btnMin.Width), obj[4].MinSize().Width) + padWidth*2
height := textMin.Height + btnMin.Height + d.label.MinSize().Height + theme.Padding() + padHeight*2
width := fyne.Max(fyne.Max(contentMin.Width, btnMin.Width), obj[4].MinSize().Width) + padWidth
height := contentMin.Height + btnMin.Height + d.label.MinSize().Height + theme.Padding() + padHeight*2

return fyne.NewSize(width, height)
}
Expand Down
6 changes: 5 additions & 1 deletion dialog/base_test.go
Expand Up @@ -15,7 +15,11 @@ func TestShowCustom_ApplyTheme(t *testing.T) {
test.ApplyTheme(t, theme.DarkTheme())
w := test.NewWindow(canvas.NewRectangle(color.Transparent))
w.Resize(fyne.NewSize(300, 200))
d := NewCustom("Title", "OK", widget.NewLabel("Content"), w)

label := widget.NewLabel("Content")
label.Alignment = fyne.TextAlignCenter

d := NewCustom("Title", "OK", label, w)

d.Show()
test.AssertImageMatches(t, "dialog-custom-dark.png", w.Canvas().Capture())
Expand Down
Binary file modified dialog/testdata/color/dialog_expanded_theme_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_expanded_theme_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_recents_theme_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_recents_theme_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_simple_recents_theme_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_simple_recents_theme_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_simple_theme_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_simple_theme_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_theme_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_theme_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/dialog-custom-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/dialog-custom-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a7b74d9

Please sign in to comment.