Skip to content

Commit

Permalink
Add a dialog.ShowCustom function for handling bespoke needs
Browse files Browse the repository at this point in the history
This is a pretty simple wrapper but could do more in the future.
  • Loading branch information
andydotxyz committed Oct 1, 2018
1 parent eda92aa commit 777d489
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
20 changes: 18 additions & 2 deletions dialog/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@ func (d *dialog) MinSize(obj []fyne.CanvasObject) fyne.Size {
textMin.Height+btnMin.Height+theme.Padding()+32)
}

func newDialogWin(title string, parent fyne.App) fyne.Window {
win := parent.NewWindow(title)
win.SetFixedSize(true)

return win
}

func newDialog(title, message string, icon fyne.Resource, callback func(bool), parent fyne.App) *dialog {
dialog := &dialog{message: message, icon: icon}

win := parent.NewWindow(title)
win := newDialogWin(title, parent)
win.SetOnClosed(dialog.closed)
win.SetFixedSize(true)

dialog.win = win
dialog.response = make(chan bool, 1)
Expand All @@ -101,3 +107,13 @@ func newButtonList(buttons ...*widget.Button) fyne.CanvasObject {

return list
}

// ShowCustom shows a dialog over the specified application using custom
// content. The MinSize() of the CanvasObject passed will be used to set
// the size of the window.
func ShowCustom(title string, content fyne.CanvasObject, parent fyne.App) {
win := newDialogWin(title, parent)

win.SetContent(content)
win.Show()
}
3 changes: 3 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func welcome(app fyne.App) {
&W.Button{Text: "Confirm", OnTapped: func() {
dialog.ShowConfirm("Confirmation", "Do you want to confirm?", confirmCallback, app)
}},
&W.Button{Text: "Custom", OnTapped: func() {
dialog.ShowCustom("Custom Dialog", &W.Check{Text: "Inside a dialog"}, app)
}},
}...),
layout.NewSpacer(),

Expand Down
2 changes: 1 addition & 1 deletion window.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Window interface {
FixedSize() bool
// SetFixedSize sets a hint that states whether the window should be a fixed
// size or allow resizing.
SetFixedSize(b bool)
SetFixedSize(bool)

SetOnClosed(func())

Expand Down

0 comments on commit 777d489

Please sign in to comment.