forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirm.go
46 lines (38 loc) · 1.48 KB
/
confirm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package dialog
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
// ConfirmDialog is like the standard Dialog but with an additional confirmation button
type ConfirmDialog struct {
*dialog
confirm *widget.Button
}
// SetConfirmText allows custom text to be set in the confirmation button
func (d *ConfirmDialog) SetConfirmText(label string) {
d.confirm.SetText(label)
d.win.Refresh()
}
// NewConfirm creates a dialog over the specified window for user confirmation.
// The title is used for the dialog window and message is the content.
// The callback is executed when the user decides. After creation you should call Show().
func NewConfirm(title, message string, callback func(bool), parent fyne.Window) *ConfirmDialog {
d := newDialog(title, message, theme.QuestionIcon(), callback, parent)
d.dismiss = &widget.Button{Text: "No", Icon: theme.CancelIcon(),
OnTapped: d.Hide,
}
confirm := &widget.Button{Text: "Yes", Icon: theme.ConfirmIcon(), Importance: widget.HighImportance,
OnTapped: func() {
d.hideWithResponse(true)
},
}
d.setButtons(newButtonList(d.dismiss, confirm))
return &ConfirmDialog{d, confirm}
}
// ShowConfirm shows a dialog over the specified window for a user
// confirmation. The title is used for the dialog window and message is the content.
// The callback is executed when the user decides.
func ShowConfirm(title, message string, callback func(bool), parent fyne.Window) {
NewConfirm(title, message, callback, parent).Show()
}