forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dialog: move custom dialogs into separate file
- Loading branch information
Showing
3 changed files
with
63 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dialog | ||
|
||
import ( | ||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/container" | ||
"fyne.io/fyne/v2/layout" | ||
"fyne.io/fyne/v2/theme" | ||
"fyne.io/fyne/v2/widget" | ||
) | ||
|
||
// NewCustom creates and returns a dialog over the specified application using custom | ||
// content. The button will have the dismiss text set. | ||
// The MinSize() of the CanvasObject passed will be used to set the size of the window. | ||
func NewCustom(title, dismiss string, content fyne.CanvasObject, parent fyne.Window) Dialog { | ||
d := &dialog{content: content, title: title, parent: parent} | ||
d.layout = &dialogLayout{d: d} | ||
|
||
d.dismiss = &widget.Button{Text: dismiss, | ||
OnTapped: d.Hide, | ||
} | ||
d.create(container.NewHBox(layout.NewSpacer(), d.dismiss, layout.NewSpacer())) | ||
|
||
return d | ||
} | ||
|
||
// NewCustomConfirm creates and returns a dialog over the specified application using | ||
// custom content. The cancel button will have the dismiss text set and the "OK" will | ||
// use the confirm text. The response callback is called on user action. | ||
// The MinSize() of the CanvasObject passed will be used to set the size of the window. | ||
func NewCustomConfirm(title, confirm, dismiss string, content fyne.CanvasObject, | ||
callback func(bool), parent fyne.Window) Dialog { | ||
d := &dialog{content: content, title: title, icon: nil, parent: parent} | ||
d.layout = &dialogLayout{d: d} | ||
d.callback = callback | ||
|
||
d.dismiss = &widget.Button{Text: dismiss, Icon: theme.CancelIcon(), | ||
OnTapped: d.Hide, | ||
} | ||
ok := &widget.Button{Text: confirm, Icon: theme.ConfirmIcon(), Importance: widget.HighImportance, | ||
OnTapped: func() { | ||
d.hideWithResponse(true) | ||
}, | ||
} | ||
d.create(container.NewHBox(layout.NewSpacer(), d.dismiss, ok, layout.NewSpacer())) | ||
|
||
return d | ||
} | ||
|
||
// ShowCustom shows a dialog over the specified application using custom | ||
// content. The button will have the dismiss text set. | ||
// The MinSize() of the CanvasObject passed will be used to set the size of the window. | ||
func ShowCustom(title, dismiss string, content fyne.CanvasObject, parent fyne.Window) { | ||
NewCustom(title, dismiss, content, parent).Show() | ||
} | ||
|
||
// ShowCustomConfirm shows a dialog over the specified application using custom | ||
// content. The cancel button will have the dismiss text set and the "OK" will use | ||
// the confirm text. The response callback is called on user action. | ||
// The MinSize() of the CanvasObject passed will be used to set the size of the window. | ||
func ShowCustomConfirm(title, confirm, dismiss string, content fyne.CanvasObject, | ||
callback func(bool), parent fyne.Window) { | ||
NewCustomConfirm(title, confirm, dismiss, content, callback, parent).Show() | ||
} |
File renamed without changes.