mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
refactor(gioui): move common button code to two functions
This commit is contained in:
parent
c0a0a5d501
commit
e544e955cb
@ -18,3 +18,19 @@ func IconButton(th *material.Theme, w *widget.Clickable, icon []byte, enabled bo
|
|||||||
}
|
}
|
||||||
return ret
|
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
|
||||||
|
}
|
||||||
|
@ -30,13 +30,10 @@ func ConfirmDialog(th *material.Theme, dialog *Dialog, text string) DialogStyle
|
|||||||
dialog: dialog,
|
dialog: dialog,
|
||||||
Text: text,
|
Text: text,
|
||||||
Inset: layout.Inset{Top: unit.Dp(12), Bottom: unit.Dp(12), Left: unit.Dp(20), Right: unit.Dp(20)},
|
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"),
|
AltStyle: HighEmphasisButton(th, &dialog.BtnAlt, "Alt"),
|
||||||
OkStyle: material.Button(th, &dialog.BtnOk, "Ok"),
|
OkStyle: HighEmphasisButton(th, &dialog.BtnOk, "Ok"),
|
||||||
CancelStyle: material.Button(th, &dialog.BtnCancel, "Cancel"),
|
CancelStyle: HighEmphasisButton(th, &dialog.BtnCancel, "Cancel"),
|
||||||
}
|
}
|
||||||
ret.AltStyle.Background = primaryColor
|
|
||||||
ret.OkStyle.Background = primaryColor
|
|
||||||
ret.CancelStyle.Background = primaryColor
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,11 +76,9 @@ func commonFileDialog(th *material.Theme, f *FileDialog) FileDialogStyle {
|
|||||||
FolderUpStyle: IconButton(th, &f.BtnFolderUp, icons.NavigationArrowUpward, true),
|
FolderUpStyle: IconButton(th, &f.BtnFolderUp, icons.NavigationArrowUpward, true),
|
||||||
DirEditorStyle: material.Editor(th, &f.Directory, "Directory"),
|
DirEditorStyle: material.Editor(th, &f.Directory, "Directory"),
|
||||||
FileNameStyle: material.Editor(th, &f.FileName, "Filename"),
|
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),
|
UseAltExtStyle: material.Switch(th, &f.UseAltExt),
|
||||||
}
|
}
|
||||||
ret.CancelStyle.Background = transparent
|
|
||||||
ret.CancelStyle.Color = primaryColor
|
|
||||||
ret.UseAltExtStyle.Color.Enabled = white
|
ret.UseAltExtStyle.Color.Enabled = white
|
||||||
ret.UseAltExtStyle.Color.Disabled = white
|
ret.UseAltExtStyle.Color.Disabled = white
|
||||||
ret.ExtMain = ".yml"
|
ret.ExtMain = ".yml"
|
||||||
|
@ -112,13 +112,11 @@ func (t *Tracker) layoutSongOptions(gtx C) D {
|
|||||||
|
|
||||||
in := layout.UniformInset(unit.Dp(1))
|
in := layout.UniformInset(unit.Dp(1))
|
||||||
|
|
||||||
panicBtnStyle := material.Button(t.Theme, t.PanicBtn, "Panic")
|
var panicBtnStyle material.ButtonStyle
|
||||||
if t.player.Enabled() {
|
if t.player.Enabled() {
|
||||||
panicBtnStyle.Background = transparent
|
panicBtnStyle = LowEmphasisButton(t.Theme, t.PanicBtn, "Panic")
|
||||||
panicBtnStyle.Color = t.Theme.Palette.Fg
|
|
||||||
} else {
|
} else {
|
||||||
panicBtnStyle.Background = t.Theme.Palette.Fg
|
panicBtnStyle = HighEmphasisButton(t.Theme, t.PanicBtn, "Panic")
|
||||||
panicBtnStyle.Color = t.Theme.Palette.ContrastFg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for t.PanicBtn.Clicked() {
|
for t.PanicBtn.Clicked() {
|
||||||
|
@ -66,26 +66,11 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu := func(gtx C) D {
|
menu := func(gtx C) D {
|
||||||
addSemitoneBtnStyle := material.Button(t.Theme, t.AddSemitoneBtn, "+1")
|
addSemitoneBtnStyle := LowEmphasisButton(t.Theme, t.AddSemitoneBtn, "+1")
|
||||||
addSemitoneBtnStyle.Color = primaryColor
|
subtractSemitoneBtnStyle := LowEmphasisButton(t.Theme, t.SubtractSemitoneBtn, "-1")
|
||||||
addSemitoneBtnStyle.Background = transparent
|
addOctaveBtnStyle := LowEmphasisButton(t.Theme, t.AddOctaveBtn, "+12")
|
||||||
addSemitoneBtnStyle.Inset = layout.UniformInset(unit.Dp(6))
|
subtractOctaveBtnStyle := LowEmphasisButton(t.Theme, t.SubtractOctaveBtn, "-12")
|
||||||
subtractSemitoneBtnStyle := material.Button(t.Theme, t.SubtractSemitoneBtn, "-1")
|
noteOffBtnStyle := LowEmphasisButton(t.Theme, t.NoteOffBtn, "Note Off")
|
||||||
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))
|
|
||||||
deleteTrackBtnStyle := IconButton(t.Theme, t.DeleteTrackBtn, icons.ActionDelete, t.CanDeleteTrack())
|
deleteTrackBtnStyle := IconButton(t.Theme, t.DeleteTrackBtn, icons.ActionDelete, t.CanDeleteTrack())
|
||||||
newTrackBtnStyle := IconButton(t.Theme, t.NewTrackBtn, icons.ContentAdd, t.CanAddTrack())
|
newTrackBtnStyle := IconButton(t.Theme, t.NewTrackBtn, icons.ContentAdd, t.CanAddTrack())
|
||||||
in := layout.UniformInset(unit.Dp(1))
|
in := layout.UniformInset(unit.Dp(1))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user