mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 21:14:31 -04:00
feat(tracker, gioui): add confirmation dialogs before quit/new/load song
This should avoid accidentally losing all work by destroying window.
This commit is contained in:
@ -10,6 +10,7 @@ import (
|
||||
|
||||
type Dialog struct {
|
||||
Visible bool
|
||||
BtnAlt widget.Clickable
|
||||
BtnOk widget.Clickable
|
||||
BtnCancel widget.Clickable
|
||||
}
|
||||
@ -18,6 +19,8 @@ type DialogStyle struct {
|
||||
dialog *Dialog
|
||||
Text string
|
||||
Inset layout.Inset
|
||||
ShowAlt bool
|
||||
AltStyle material.ButtonStyle
|
||||
OkStyle material.ButtonStyle
|
||||
CancelStyle material.ButtonStyle
|
||||
}
|
||||
@ -27,9 +30,11 @@ func ConfirmDialog(th *material.Theme, dialog *Dialog, text string) DialogStyle
|
||||
dialog: dialog,
|
||||
Text: text,
|
||||
Inset: layout.Inset{Top: unit.Dp(12), Bottom: unit.Dp(12), Left: unit.Dp(20), Right: unit.Dp(20)},
|
||||
AltStyle: material.Button(th, &dialog.BtnAlt, "Alt"),
|
||||
OkStyle: material.Button(th, &dialog.BtnOk, "Ok"),
|
||||
CancelStyle: material.Button(th, &dialog.BtnCancel, "Cancel"),
|
||||
}
|
||||
ret.AltStyle.Background = primaryColor
|
||||
ret.OkStyle.Background = primaryColor
|
||||
ret.CancelStyle.Background = primaryColor
|
||||
return ret
|
||||
@ -45,6 +50,13 @@ func (d *DialogStyle) Layout(gtx C) D {
|
||||
layout.Rigid(Label(d.Text, highEmphasisTextColor)),
|
||||
layout.Rigid(func(gtx C) D {
|
||||
gtx.Constraints.Min.X = gtx.Px(unit.Dp(120))
|
||||
if d.ShowAlt {
|
||||
return layout.Flex{Axis: layout.Horizontal, Spacing: layout.SpaceBetween}.Layout(gtx,
|
||||
layout.Rigid(d.OkStyle.Layout),
|
||||
layout.Rigid(d.AltStyle.Layout),
|
||||
layout.Rigid(d.CancelStyle.Layout),
|
||||
)
|
||||
}
|
||||
return layout.Flex{Axis: layout.Horizontal, Spacing: layout.SpaceBetween}.Layout(gtx,
|
||||
layout.Rigid(d.OkStyle.Layout),
|
||||
layout.Rigid(d.CancelStyle.Layout),
|
||||
|
Reference in New Issue
Block a user