forked from gopher-atz/4klang
-
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.
feat(gioui): add confirmation dialog when deleting instrument
Closes gopher-atz#5
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package gioui | ||
|
||
import ( | ||
"gioui.org/layout" | ||
"gioui.org/op/paint" | ||
"gioui.org/unit" | ||
"gioui.org/widget" | ||
"gioui.org/widget/material" | ||
) | ||
|
||
type Dialog struct { | ||
Visible bool | ||
BtnOk widget.Clickable | ||
BtnCancel widget.Clickable | ||
} | ||
|
||
type DialogStyle struct { | ||
dialog *Dialog | ||
Text string | ||
Inset layout.Inset | ||
OkStyle material.ButtonStyle | ||
CancelStyle material.ButtonStyle | ||
} | ||
|
||
func ConfirmDialog(th *material.Theme, dialog *Dialog, text string) DialogStyle { | ||
ret := DialogStyle{ | ||
dialog: dialog, | ||
Text: text, | ||
Inset: layout.Inset{Top: unit.Dp(12), Bottom: unit.Dp(12), Left: unit.Dp(20), Right: unit.Dp(20)}, | ||
OkStyle: material.Button(th, &dialog.BtnOk, "Ok"), | ||
CancelStyle: material.Button(th, &dialog.BtnCancel, "Cancel"), | ||
} | ||
ret.OkStyle.Background = primaryColor | ||
ret.CancelStyle.Background = primaryColor | ||
return ret | ||
} | ||
|
||
func (d *DialogStyle) Layout(gtx C) D { | ||
if d.dialog.Visible { | ||
paint.Fill(gtx.Ops, dialogBgColor) | ||
return layout.Center.Layout(gtx, func(gtx C) D { | ||
return Popup(&d.dialog.Visible).Layout(gtx, func(gtx C) D { | ||
return d.Inset.Layout(gtx, func(gtx C) D { | ||
return layout.Flex{Axis: layout.Vertical, Alignment: layout.Middle}.Layout(gtx, | ||
layout.Rigid(Label(d.Text, highEmphasisTextColor)), | ||
layout.Rigid(func(gtx C) D { | ||
gtx.Constraints.Min.X = gtx.Px(unit.Dp(120)) | ||
return layout.Flex{Axis: layout.Horizontal, Spacing: layout.SpaceBetween}.Layout(gtx, | ||
layout.Rigid(d.OkStyle.Layout), | ||
layout.Rigid(d.CancelStyle.Layout), | ||
) | ||
}), | ||
) | ||
}) | ||
}) | ||
}) | ||
} | ||
return D{} | ||
} |
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
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