Highlight the icon of the current page and reset the original color of the rest

This commit is contained in:
natilou
2024-01-06 10:25:08 -03:00
committed by Natalí Paura
parent f5cc27b67c
commit 159c127be8
2 changed files with 32 additions and 17 deletions
+25 -10
View File
@@ -1,17 +1,16 @@
package browsing package browsing
import ( import (
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/ui/controller"
"github.com/dweymouth/supersonic/ui/layouts"
myTheme "github.com/dweymouth/supersonic/ui/theme"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/ui/controller"
"github.com/dweymouth/supersonic/ui/layouts"
myTheme "github.com/dweymouth/supersonic/ui/theme"
) )
type Page interface { type Page interface {
@@ -62,9 +61,10 @@ type BrowsingPane struct {
navBtnsContainer *fyne.Container navBtnsContainer *fyne.Container
pageContainer *fyne.Container pageContainer *fyne.Container
container *fyne.Container container *fyne.Container
navBtnsPageMap map[controller.PageName]fyne.Resource
} }
func NewBrowsingPane(app *backend.App, controller *controller.Controller) *BrowsingPane { func NewBrowsingPane(app *backend.App, contr *controller.Controller) *BrowsingPane {
b := &BrowsingPane{app: app} b := &BrowsingPane{app: app}
b.ExtendBaseWidget(b) b.ExtendBaseWidget(b)
b.home = widget.NewButtonWithIcon("", theme.HomeIcon(), b.GoHome) b.home = widget.NewButtonWithIcon("", theme.HomeIcon(), b.GoHome)
@@ -81,9 +81,10 @@ func NewBrowsingPane(app *backend.App, controller *controller.Controller) *Brows
p.ShowAtPosition(fyne.NewPos(b.Size().Width-p.MinSize().Width+4, p.ShowAtPosition(fyne.NewPos(b.Size().Width-p.MinSize().Width+4,
b.navBtnsContainer.MinSize().Height+theme.Padding())) b.navBtnsContainer.MinSize().Height+theme.Padding()))
}) })
quickSearchBtn := widget.NewButtonWithIcon("", theme.SearchIcon(), controller.ShowQuickSearch) quickSearchBtn := widget.NewButtonWithIcon("", theme.SearchIcon(), contr.ShowQuickSearch)
b.settingsMenu = fyne.NewMenu("") b.settingsMenu = fyne.NewMenu("")
b.navBtnsContainer = container.NewHBox() b.navBtnsContainer = container.NewHBox()
b.navBtnsPageMap = map[controller.PageName]fyne.Resource{}
b.container = container.NewBorder(container.New( b.container = container.NewBorder(container.New(
&layouts.MaxPadLayout{PadLeft: -5, PadRight: -5}, &layouts.MaxPadLayout{PadLeft: -5, PadRight: -5},
container.New(layouts.NewLeftMiddleRightLayout(0), container.New(layouts.NewLeftMiddleRightLayout(0),
@@ -126,8 +127,11 @@ func (b *BrowsingPane) AddSettingsMenuSeparator() {
fyne.NewMenuItemSeparator()) fyne.NewMenuItemSeparator())
} }
func (b *BrowsingPane) AddNavigationButton(icon fyne.Resource, action func()) { func (b *BrowsingPane) AddNavigationButton(icon fyne.Resource, pageName controller.PageName, action func()) {
b.navBtnsContainer.Add(widget.NewButtonWithIcon("", icon, action)) // make a copy of the icon, because it can change the color
browsingPaneIcon := theme.NewThemedResource(icon)
b.navBtnsContainer.Add(widget.NewButtonWithIcon("", browsingPaneIcon, action))
b.navBtnsPageMap[pageName] = browsingPaneIcon
} }
func (b *BrowsingPane) DisableNavigationButtons() { func (b *BrowsingPane) DisableNavigationButtons() {
@@ -175,6 +179,7 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
} }
b.pageContainer.Remove(b.curPage) b.pageContainer.Remove(b.curPage)
b.pageContainer.Objects[1] = p b.pageContainer.Objects[1] = p
b.updateNavBtnsColor(p)
b.Refresh() b.Refresh()
return true return true
} }
@@ -274,3 +279,13 @@ func (b *BrowsingPane) CurrentPage() controller.Route {
func (b *BrowsingPane) CreateRenderer() fyne.WidgetRenderer { func (b *BrowsingPane) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(b.container) return widget.NewSimpleRenderer(b.container)
} }
func (b *BrowsingPane) updateNavBtnsColor(p Page) {
for pageName, icon := range b.navBtnsPageMap {
if pageName == p.Route().Page {
icon.(*theme.ThemedResource).ColorName = theme.ColorNamePrimary
} else {
icon.(*theme.ThemedResource).ColorName = ""
}
}
}
+7 -7
View File
@@ -216,25 +216,25 @@ func (m *MainWindow) ShowWhatsNewDialog() {
} }
func (m *MainWindow) addNavigationButtons() { func (m *MainWindow) addNavigationButtons() {
m.BrowsingPane.AddNavigationButton(theme.NowPlayingIcon, func() { m.BrowsingPane.AddNavigationButton(theme.NowPlayingIcon, controller.NowPlaying, func() {
m.Router.NavigateTo(controller.NowPlayingRoute("")) m.Router.NavigateTo(controller.NowPlayingRoute(""))
}) })
m.BrowsingPane.AddNavigationButton(theme.FavoriteIcon, func() { m.BrowsingPane.AddNavigationButton(theme.FavoriteIcon, controller.Favorites, func() {
m.Router.NavigateTo(controller.FavoritesRoute()) m.Router.NavigateTo(controller.FavoritesRoute())
}) })
m.BrowsingPane.AddNavigationButton(theme.AlbumIcon, func() { m.BrowsingPane.AddNavigationButton(theme.AlbumIcon, controller.Albums, func() {
m.Router.NavigateTo(controller.AlbumsRoute()) m.Router.NavigateTo(controller.AlbumsRoute())
}) })
m.BrowsingPane.AddNavigationButton(theme.ArtistIcon, func() { m.BrowsingPane.AddNavigationButton(theme.ArtistIcon, controller.Artists, func() {
m.Router.NavigateTo(controller.ArtistsRoute()) m.Router.NavigateTo(controller.ArtistsRoute())
}) })
m.BrowsingPane.AddNavigationButton(theme.GenreIcon, func() { m.BrowsingPane.AddNavigationButton(theme.GenreIcon, controller.Genres, func() {
m.Router.NavigateTo(controller.GenresRoute()) m.Router.NavigateTo(controller.GenresRoute())
}) })
m.BrowsingPane.AddNavigationButton(theme.PlaylistIcon, func() { m.BrowsingPane.AddNavigationButton(theme.PlaylistIcon, controller.Playlists, func() {
m.Router.NavigateTo(controller.PlaylistsRoute()) m.Router.NavigateTo(controller.PlaylistsRoute())
}) })
m.BrowsingPane.AddNavigationButton(theme.TracksIcon, func() { m.BrowsingPane.AddNavigationButton(theme.TracksIcon, controller.Tracks, func() {
m.Router.NavigateTo(controller.TracksRoute()) m.Router.NavigateTo(controller.TracksRoute())
}) })
} }