Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dialog content to expand instead of use min size. #1367

Merged
merged 11 commits into from Oct 7, 2020
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.