From 37f272e7023b42d13afe9d00a8073ea4fd235c90 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Fri, 24 Feb 2023 17:07:27 -0800 Subject: [PATCH] some tweaks to ui theming for Fyne 2.3 --- main.go | 3 ++- ui/browsing/browsingpane.go | 6 ++++-- ui/theme/theme.go | 40 ++++++++++++++++++++++++++++++++++++ ui/widgets/listheader.go | 2 +- ui/widgets/nowplayingcard.go | 2 +- 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 ui/theme/theme.go diff --git a/main.go b/main.go index 203b9ea..f2b5cb9 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "path" "supersonic/backend" "supersonic/ui" + "supersonic/ui/theme" "time" "fyne.io/fyne/v2" @@ -28,7 +29,7 @@ func main() { } fyneApp := app.New() - fyneApp.Settings().SetTheme(&ui.MyTheme{}) + fyneApp.Settings().SetTheme(&theme.MyTheme{}) w := float32(myApp.Config.Application.WindowWidth) if w <= 1 { w = 1000 diff --git a/ui/browsing/browsingpane.go b/ui/browsing/browsingpane.go index 95f6959..8214c94 100644 --- a/ui/browsing/browsingpane.go +++ b/ui/browsing/browsingpane.go @@ -1,10 +1,10 @@ package browsing import ( - "image/color" "supersonic/backend" "supersonic/ui/controller" "supersonic/ui/layouts" + myTheme "supersonic/ui/theme" "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" @@ -69,7 +69,9 @@ func NewBrowsingPane(app *backend.App) *BrowsingPane { b.app.PlaybackManager.OnSongChange(b.onSongChange) b.pageContainer = container.NewMax( // TODO: get this color into the theme - canvas.NewRectangle(color.RGBA{R: 24, G: 24, B: 40, A: 255}), + canvas.NewRectangle(fyne.CurrentApp().Settings().Theme().Color( + myTheme.ColorNamePageBackground, theme.VariantDark, + )), layout.NewSpacer()) b.settingsBtn = widget.NewButtonWithIcon("", theme.SettingsIcon(), func() { p := widget.NewPopUpMenu(b.settingsMenu, diff --git a/ui/theme/theme.go b/ui/theme/theme.go new file mode 100644 index 0000000..20f29d1 --- /dev/null +++ b/ui/theme/theme.go @@ -0,0 +1,40 @@ +package theme + +import ( + "image/color" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/theme" +) + +const ColorNamePageBackground fyne.ThemeColorName = "PageBackground" + +type MyTheme struct{} + +var _ fyne.Theme = (*MyTheme)(nil) + +func (m MyTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color { + switch name { + case ColorNamePageBackground: + return color.RGBA{R: 20, G: 20, B: 20, A: 255} + case theme.ColorNameBackground: + return color.RGBA{R: 40, G: 40, B: 40, A: 255} + case theme.ColorNameScrollBar: + return theme.DarkTheme().Color(theme.ColorNameForeground, variant) + case theme.ColorNameButton: + return theme.DarkTheme().Color(theme.ColorNameInputBackground, variant) + } + return theme.DarkTheme().Color(name, variant) +} + +func (m MyTheme) Icon(name fyne.ThemeIconName) fyne.Resource { + return theme.DefaultTheme().Icon(name) +} + +func (m MyTheme) Font(style fyne.TextStyle) fyne.Resource { + return theme.DefaultTheme().Font(style) +} + +func (m MyTheme) Size(name fyne.ThemeSizeName) float32 { + return theme.DefaultTheme().Size(name) +} diff --git a/ui/widgets/listheader.go b/ui/widgets/listheader.go index cf36c8e..d0f3794 100644 --- a/ui/widgets/listheader.go +++ b/ui/widgets/listheader.go @@ -42,7 +42,7 @@ func NewListHeader(cols []ListColumn, layout *layouts.ColumnsLayout) *ListHeader for i, _ := range l.columnVisible { l.columnVisible[i] = true } - l.container = container.NewMax(canvas.NewRectangle(theme.ButtonColor()), l.columnsContainer) + l.container = container.NewMax(canvas.NewRectangle(theme.BackgroundColor()), l.columnsContainer) l.ExtendBaseWidget(l) l.buildColumns() return l diff --git a/ui/widgets/nowplayingcard.go b/ui/widgets/nowplayingcard.go index 7c0ef8f..242b6ae 100644 --- a/ui/widgets/nowplayingcard.go +++ b/ui/widgets/nowplayingcard.go @@ -36,7 +36,7 @@ func NewNowPlayingCard() *NowPlayingCard { n.cover.SetMinSize(fyne.NewSize(85, 85)) n.cover.FillMode = canvas.ImageFillContain - n.c = container.NewBorder(nil, nil, container.New(&layouts.CenterPadLayout{PadLeftRight: 3, PadTopBottom: 5}, n.cover), nil, + n.c = container.NewBorder(nil, nil, n.cover, nil, container.New(&layouts.VboxCustomPadding{ExtraPad: -12}, n.trackName, n.artistName, n.albumName)) return n }