add theme choice to settings dialog

This commit is contained in:
Drew Weymouth
2023-05-03 17:32:36 -07:00
parent a1d91d748c
commit 4ed6a75778
4 changed files with 42 additions and 5 deletions
+2 -1
View File
@@ -315,7 +315,7 @@ func (c *Controller) ShowAboutDialog() {
pop.Show() pop.Show()
} }
func (c *Controller) ShowSettingsDialog() { func (c *Controller) ShowSettingsDialog(themeUpdateCallbk func()) {
devs, err := c.App.Player.ListAudioDevices() devs, err := c.App.Player.ListAudioDevices()
if err != nil { if err != nil {
log.Printf("error listing audio devices: %v", err) log.Printf("error listing audio devices: %v", err)
@@ -332,6 +332,7 @@ func (c *Controller) ShowSettingsDialog() {
dlg.OnAudioDeviceSettingChanged = func() { dlg.OnAudioDeviceSettingChanged = func() {
c.App.Player.SetAudioDevice(c.App.Config.LocalPlayback.AudioDeviceName) c.App.Player.SetAudioDevice(c.App.Config.LocalPlayback.AudioDeviceName)
} }
dlg.OnThemeSettingChanged = themeUpdateCallbk
pop := widget.NewModalPopUp(dlg, c.MainWindow.Canvas()) pop := widget.NewModalPopUp(dlg, c.MainWindow.Canvas())
dlg.OnDismiss = func() { dlg.OnDismiss = func() {
pop.Hide() pop.Hide()
+25 -1
View File
@@ -9,6 +9,7 @@ import (
"supersonic/backend" "supersonic/backend"
"supersonic/player" "supersonic/player"
"supersonic/ui/layouts" "supersonic/ui/layouts"
myTheme "supersonic/ui/theme"
"supersonic/ui/util" "supersonic/ui/util"
"supersonic/ui/widgets" "supersonic/ui/widgets"
"unicode" "unicode"
@@ -31,6 +32,7 @@ type SettingsDialog struct {
OnReplayGainSettingsChanged func() OnReplayGainSettingsChanged func()
OnAudioExclusiveSettingChanged func() OnAudioExclusiveSettingChanged func()
OnAudioDeviceSettingChanged func() OnAudioDeviceSettingChanged func()
OnThemeSettingChanged func()
OnDismiss func() OnDismiss func()
config *backend.Config config *backend.Config
@@ -50,6 +52,10 @@ func NewSettingsDialog(config *backend.Config, audioDeviceList []player.AudioDev
s.createPlaybackTab(), s.createPlaybackTab(),
s.createExperimentalTab(window), s.createExperimentalTab(window),
) )
// workaround issue where inactivated tabs don't fully update when theme setting is changed
tabs.OnSelected = func(ti *container.TabItem) {
ti.Content.Refresh()
}
s.promptText = widget.NewRichTextWithText("") s.promptText = widget.NewRichTextWithText("")
s.content = container.NewVBox(tabs, widget.NewSeparator(), s.content = container.NewVBox(tabs, widget.NewSeparator(),
container.NewHBox(s.promptText, layout.NewSpacer(), widget.NewButton("Close", func() { container.NewHBox(s.promptText, layout.NewSpacer(), widget.NewButton("Close", func() {
@@ -62,6 +68,21 @@ func NewSettingsDialog(config *backend.Config, audioDeviceList []player.AudioDev
} }
func (s *SettingsDialog) createGeneralTab() *container.TabItem { func (s *SettingsDialog) createGeneralTab() *container.TabItem {
themeSelect := widget.NewSelect([]string{
string(myTheme.AppearanceDark),
string(myTheme.AppearanceLight),
string(myTheme.AppearanceAuto)}, nil)
themeSelect.OnChanged = func(_ string) {
s.config.Theme.Appearance = themeSelect.Options[themeSelect.SelectedIndex()]
if s.OnThemeSettingChanged != nil {
s.OnThemeSettingChanged()
}
}
themeSelect.SetSelected(s.config.Theme.Appearance)
if themeSelect.Selected == "" {
themeSelect.SetSelectedIndex(0)
}
startupPage := widget.NewSelect(backend.SupportedStartupPages, func(choice string) { startupPage := widget.NewSelect(backend.SupportedStartupPages, func(choice string) {
s.config.Application.StartupPage = choice s.config.Application.StartupPage = choice
}) })
@@ -161,7 +182,10 @@ func (s *SettingsDialog) createGeneralTab() *container.TabItem {
scrobbleEnabled.Checked = s.config.Scrobbling.Enabled scrobbleEnabled.Checked = s.config.Scrobbling.Enabled
return container.NewTabItem("General", container.NewVBox( return container.NewTabItem("General", container.NewVBox(
container.New(layout.NewFormLayout(), widget.NewLabel("Startup page"), startupPage), container.New(layout.NewFormLayout(),
widget.NewLabel("Appearance"), container.NewGridWithColumns(2, themeSelect),
widget.NewLabel("Startup page"), container.NewGridWithColumns(2, startupPage),
),
container.NewHBox(systemTrayEnable, closeToTray), container.NewHBox(systemTrayEnable, closeToTray),
s.newSectionSeparator(), s.newSectionSeparator(),
+11 -1
View File
@@ -43,6 +43,7 @@ type MainWindow struct {
BrowsingPane *browsing.BrowsingPane BrowsingPane *browsing.BrowsingPane
BottomPanel *BottomPanel BottomPanel *BottomPanel
theme *theme.MyTheme
haveSystemTray bool haveSystemTray bool
container *fyne.Container container *fyne.Container
} }
@@ -52,8 +53,13 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
App: app, App: app,
Window: fyneApp.NewWindow(appName), Window: fyneApp.NewWindow(appName),
BrowsingPane: browsing.NewBrowsingPane(app), BrowsingPane: browsing.NewBrowsingPane(app),
theme: theme.NewMyTheme(&app.Config.Theme),
} }
m.theme.NormalFont = app.Config.Application.FontNormalTTF
m.theme.BoldFont = app.Config.Application.FontBoldTTF
fyneApp.Settings().SetTheme(m.theme)
if app.Config.Application.EnableSystemTray { if app.Config.Application.EnableSystemTray {
m.SetupSystemTrayMenu(appName, fyneApp) m.SetupSystemTrayMenu(appName, fyneApp)
} }
@@ -118,7 +124,11 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
} }
}() }()
}) })
m.BrowsingPane.AddSettingsMenuItem("Settings...", m.Controller.ShowSettingsDialog) m.BrowsingPane.AddSettingsMenuItem("Settings...", func() {
m.Controller.ShowSettingsDialog(func() {
fyneApp.Settings().SetTheme(m.theme)
})
})
m.BrowsingPane.AddSettingsMenuItem("About...", m.Controller.ShowAboutDialog) m.BrowsingPane.AddSettingsMenuItem("About...", m.Controller.ShowAboutDialog)
m.addNavigationButtons() m.addNavigationButtons()
m.BrowsingPane.DisableNavigationButtons() m.BrowsingPane.DisableNavigationButtons()
+4 -2
View File
@@ -22,6 +22,8 @@ const (
AppearanceLight AppearanceMode = "Light" AppearanceLight AppearanceMode = "Light"
AppearanceDark AppearanceMode = "Dark" AppearanceDark AppearanceMode = "Dark"
AppearanceAuto AppearanceMode = "Auto" AppearanceAuto AppearanceMode = "Auto"
DefaultAppearance AppearanceMode = AppearanceDark
) )
var ( var (
@@ -170,11 +172,11 @@ func (m *MyTheme) Size(name fyne.ThemeSizeName) float32 {
} }
func (m *MyTheme) getVariant() fyne.ThemeVariant { func (m *MyTheme) getVariant() fyne.ThemeVariant {
v := "Dark" // default if config has invalid or missing setting v := DefaultAppearance // default if config has invalid or missing setting
if sharedutil.SliceContains( if sharedutil.SliceContains(
[]string{string(AppearanceLight), string(AppearanceDark), string(AppearanceAuto)}, []string{string(AppearanceLight), string(AppearanceDark), string(AppearanceAuto)},
m.config.Appearance) { m.config.Appearance) {
v = m.config.Appearance v = AppearanceMode(m.config.Appearance)
} }
if AppearanceMode(v) == AppearanceDark { if AppearanceMode(v) == AppearanceDark {