Skip to content

Commit

Permalink
Merge pull request fyne-io#3716 from Jacalz/dialog-cleanup2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Mar 10, 2023
2 parents 693bbae + 54835d1 commit 79e5ad2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions dialog/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ type dialog struct {
icon fyne.Resource
desiredSize fyne.Size

win *widget.PopUp
bg *themedBackground
content, label fyne.CanvasObject
dismiss *widget.Button
parent fyne.Window
win *widget.PopUp
content fyne.CanvasObject
dismiss *widget.Button
parent fyne.Window
}

func (d *dialog) Hide() {
Expand Down Expand Up @@ -102,15 +101,14 @@ func (d *dialog) hideWithResponse(resp bool) {
}

func (d *dialog) create(buttons fyne.CanvasObject) {
d.bg = newThemedBackground()
d.label = widget.NewLabelWithStyle(d.title, fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
label := widget.NewLabelWithStyle(d.title, fyne.TextAlignLeading, fyne.TextStyle{Bold: true})

content := container.New(&dialogLayout{d: d},
&canvas.Image{Resource: d.icon},
d.bg,
newThemedBackground(),
d.content,
buttons,
d.label,
label,
)

d.win = widget.NewModalPopUp(content, d.parent.Canvas())
Expand Down Expand Up @@ -184,33 +182,36 @@ type dialogLayout struct {
}

func (l *dialogLayout) Layout(obj []fyne.CanvasObject, size fyne.Size) {
l.d.bg.Move(fyne.NewPos(0, 0))
l.d.bg.Resize(size)

btnMin := obj[3].MinSize()
labelMin := obj[4].MinSize()

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

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

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

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

func (l *dialogLayout) MinSize(obj []fyne.CanvasObject) fyne.Size {
contentMin := obj[2].MinSize()
btnMin := obj[3].MinSize()
labelMin := obj[4].MinSize()

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

return fyne.NewSize(width, height)
}
2 changes: 1 addition & 1 deletion dialog/information_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestDialog_MinSize(t *testing.T) {
information := d.(*dialog)

dialogContent := information.win.Content.MinSize()
label := information.label.MinSize()
label := information.win.Content.(*fyne.Container).Objects[4].MinSize()

assert.Less(t, label.Width, dialogContent.Width)
}
Expand Down

0 comments on commit 79e5ad2

Please sign in to comment.