From e544e955cbdb9c4247dbf4cfc52bb84addd1d27b Mon Sep 17 00:00:00 2001 From: vsariola <5684185+vsariola@users.noreply.github.com> Date: Tue, 20 Apr 2021 18:21:21 +0300 Subject: [PATCH] refactor(gioui): move common button code to two functions --- tracker/gioui/buttons.go | 16 ++++++++++++++++ tracker/gioui/dialog.go | 9 +++------ tracker/gioui/filedialog.go | 4 +--- tracker/gioui/songpanel.go | 8 +++----- tracker/gioui/track.go | 25 +++++-------------------- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/tracker/gioui/buttons.go b/tracker/gioui/buttons.go index 25f988c..0fe4e18 100644 --- a/tracker/gioui/buttons.go +++ b/tracker/gioui/buttons.go @@ -18,3 +18,19 @@ func IconButton(th *material.Theme, w *widget.Clickable, icon []byte, enabled bo } return ret } + +func LowEmphasisButton(th *material.Theme, w *widget.Clickable, text string) material.ButtonStyle { + ret := material.Button(th, w, text) + ret.Color = th.Palette.Fg + ret.Background = transparent + ret.Inset = layout.UniformInset(unit.Dp(6)) + return ret +} + +func HighEmphasisButton(th *material.Theme, w *widget.Clickable, text string) material.ButtonStyle { + ret := material.Button(th, w, text) + ret.Color = th.Palette.ContrastFg + ret.Background = th.Palette.Fg + ret.Inset = layout.UniformInset(unit.Dp(6)) + return ret +} diff --git a/tracker/gioui/dialog.go b/tracker/gioui/dialog.go index a88366b..8c406be 100644 --- a/tracker/gioui/dialog.go +++ b/tracker/gioui/dialog.go @@ -30,13 +30,10 @@ 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"), + AltStyle: HighEmphasisButton(th, &dialog.BtnAlt, "Alt"), + OkStyle: HighEmphasisButton(th, &dialog.BtnOk, "Ok"), + CancelStyle: HighEmphasisButton(th, &dialog.BtnCancel, "Cancel"), } - ret.AltStyle.Background = primaryColor - ret.OkStyle.Background = primaryColor - ret.CancelStyle.Background = primaryColor return ret } diff --git a/tracker/gioui/filedialog.go b/tracker/gioui/filedialog.go index e539eae..b191585 100644 --- a/tracker/gioui/filedialog.go +++ b/tracker/gioui/filedialog.go @@ -76,11 +76,9 @@ func commonFileDialog(th *material.Theme, f *FileDialog) FileDialogStyle { FolderUpStyle: IconButton(th, &f.BtnFolderUp, icons.NavigationArrowUpward, true), DirEditorStyle: material.Editor(th, &f.Directory, "Directory"), FileNameStyle: material.Editor(th, &f.FileName, "Filename"), - CancelStyle: material.Button(th, &f.BtnCancel, "Cancel"), + CancelStyle: LowEmphasisButton(th, &f.BtnCancel, "Cancel"), UseAltExtStyle: material.Switch(th, &f.UseAltExt), } - ret.CancelStyle.Background = transparent - ret.CancelStyle.Color = primaryColor ret.UseAltExtStyle.Color.Enabled = white ret.UseAltExtStyle.Color.Disabled = white ret.ExtMain = ".yml" diff --git a/tracker/gioui/songpanel.go b/tracker/gioui/songpanel.go index 5668fcc..dba53e9 100644 --- a/tracker/gioui/songpanel.go +++ b/tracker/gioui/songpanel.go @@ -112,13 +112,11 @@ func (t *Tracker) layoutSongOptions(gtx C) D { in := layout.UniformInset(unit.Dp(1)) - panicBtnStyle := material.Button(t.Theme, t.PanicBtn, "Panic") + var panicBtnStyle material.ButtonStyle if t.player.Enabled() { - panicBtnStyle.Background = transparent - panicBtnStyle.Color = t.Theme.Palette.Fg + panicBtnStyle = LowEmphasisButton(t.Theme, t.PanicBtn, "Panic") } else { - panicBtnStyle.Background = t.Theme.Palette.Fg - panicBtnStyle.Color = t.Theme.Palette.ContrastFg + panicBtnStyle = HighEmphasisButton(t.Theme, t.PanicBtn, "Panic") } for t.PanicBtn.Clicked() { diff --git a/tracker/gioui/track.go b/tracker/gioui/track.go index 419312d..12bc7bd 100644 --- a/tracker/gioui/track.go +++ b/tracker/gioui/track.go @@ -66,26 +66,11 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions { } menu := func(gtx C) D { - addSemitoneBtnStyle := material.Button(t.Theme, t.AddSemitoneBtn, "+1") - addSemitoneBtnStyle.Color = primaryColor - addSemitoneBtnStyle.Background = transparent - addSemitoneBtnStyle.Inset = layout.UniformInset(unit.Dp(6)) - subtractSemitoneBtnStyle := material.Button(t.Theme, t.SubtractSemitoneBtn, "-1") - subtractSemitoneBtnStyle.Color = primaryColor - subtractSemitoneBtnStyle.Background = transparent - subtractSemitoneBtnStyle.Inset = layout.UniformInset(unit.Dp(6)) - addOctaveBtnStyle := material.Button(t.Theme, t.AddOctaveBtn, "+12") - addOctaveBtnStyle.Color = primaryColor - addOctaveBtnStyle.Background = transparent - addOctaveBtnStyle.Inset = layout.UniformInset(unit.Dp(6)) - subtractOctaveBtnStyle := material.Button(t.Theme, t.SubtractOctaveBtn, "-12") - subtractOctaveBtnStyle.Color = primaryColor - subtractOctaveBtnStyle.Background = transparent - subtractOctaveBtnStyle.Inset = layout.UniformInset(unit.Dp(6)) - noteOffBtnStyle := material.Button(t.Theme, t.NoteOffBtn, "Note Off") - noteOffBtnStyle.Color = primaryColor - noteOffBtnStyle.Background = transparent - noteOffBtnStyle.Inset = layout.UniformInset(unit.Dp(6)) + addSemitoneBtnStyle := LowEmphasisButton(t.Theme, t.AddSemitoneBtn, "+1") + subtractSemitoneBtnStyle := LowEmphasisButton(t.Theme, t.SubtractSemitoneBtn, "-1") + addOctaveBtnStyle := LowEmphasisButton(t.Theme, t.AddOctaveBtn, "+12") + subtractOctaveBtnStyle := LowEmphasisButton(t.Theme, t.SubtractOctaveBtn, "-12") + noteOffBtnStyle := LowEmphasisButton(t.Theme, t.NoteOffBtn, "Note Off") deleteTrackBtnStyle := IconButton(t.Theme, t.DeleteTrackBtn, icons.ActionDelete, t.CanDeleteTrack()) newTrackBtnStyle := IconButton(t.Theme, t.NewTrackBtn, icons.ContentAdd, t.CanAddTrack()) in := layout.UniformInset(unit.Dp(1))