Skip to content

Commit 5ea0bcd

Browse files
authored
Merge pull request #732 from dweymouth/feature/queue-sidebar
Add toggleable play queue sidebar
2 parents 153cb62 + 27ae29a commit 5ea0bcd

File tree

11 files changed

+768
-190
lines changed

11 files changed

+768
-190
lines changed

backend/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type AppConfig struct {
5757
EnableAutoUpdateChecker bool
5858
RequestTimeoutSeconds int
5959
EnableOSMediaPlayerAPIs bool
60+
ShowSidebar bool
61+
SidebarWidthFraction float64
6062

6163
FontNormalTTF string
6264
FontBoldTTF string
@@ -207,6 +209,7 @@ func DefaultConfig(appVersionTag string) *Config {
207209
EnableAutoUpdateChecker: true,
208210
RequestTimeoutSeconds: 15,
209211
EnableOSMediaPlayerAPIs: true,
212+
SidebarWidthFraction: 0.8,
210213
},
211214
AlbumPage: AlbumPageConfig{
212215
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"},

res/bundled.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

res/bundled_gen.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fyne bundle -append -prefix Res icons/publicdomain/oscilloscope.svg >> bundled.g
1515
fyne bundle -append -prefix Res icons/publicdomain/people.svg >> bundled.go
1616
fyne bundle -append -prefix Res icons/publicdomain/playlist.svg >> bundled.go
1717
fyne bundle -append -prefix Res icons/publicdomain/playqueue.svg >> bundled.go
18+
fyne bundle -append -prefix Res icons/publicdomain/sidebar.svg >> bundled.go
1819
fyne bundle -append -prefix Res icons/publicdomain/star-outline.svg >> bundled.go
1920
fyne bundle -append -prefix Res icons/publicdomain/star-filled.svg >> bundled.go
2021
fyne bundle -append -prefix Res icons/publicdomain/theatermasks.svg >> bundled.go

res/icons/publicdomain/sidebar.svg

Lines changed: 5 additions & 0 deletions
Loading

res/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
"Time": "Time",
237237
"Title": "Title",
238238
"Title (A-Z)": "Title (A-Z)",
239+
"Toggle sidebar": "Toggle sidebar",
239240
"Top Tracks": "Top Tracks",
240241
"Total time": "Total time",
241242
"Track": "Track",

ui/browsing/browsingpane.go

Lines changed: 27 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ package browsing
33
import (
44
"fyne.io/fyne/v2"
55
"fyne.io/fyne/v2/container"
6-
"fyne.io/fyne/v2/lang"
76
"fyne.io/fyne/v2/layout"
8-
"fyne.io/fyne/v2/theme"
97
"fyne.io/fyne/v2/widget"
108
"github.com/dweymouth/supersonic/backend"
119
"github.com/dweymouth/supersonic/backend/mediaprovider"
1210
"github.com/dweymouth/supersonic/ui/controller"
13-
"github.com/dweymouth/supersonic/ui/layouts"
1411
myTheme "github.com/dweymouth/supersonic/ui/theme"
15-
16-
ttwidget "github.com/dweymouth/fyne-tooltip/widget"
1712
)
1813

1914
type Page interface {
@@ -60,60 +55,25 @@ type CanShowPlayQueue interface {
6055
type BrowsingPane struct {
6156
widget.BaseWidget
6257

63-
app *backend.App
58+
OnHistoryChanged func()
6459

65-
curPage Page
60+
playbackManager *backend.PlaybackManager
6661

67-
home *ttwidget.Button
68-
forward *ttwidget.Button
69-
back *ttwidget.Button
70-
reload *ttwidget.Button
62+
curPage Page
7163
history []SavedPage
7264
historyIdx int
7365

74-
settingsBtn *ttwidget.Button
75-
settingsMenu *fyne.Menu
76-
navBtnsContainer *fyne.Container
77-
pageContainer *fyne.Container
78-
container *fyne.Container
79-
navBtnsPageMap map[controller.PageName]fyne.Resource
66+
pageContainer *fyne.Container
8067
}
8168

82-
func NewBrowsingPane(app *backend.App, contr *controller.Controller, onGoHome func()) *BrowsingPane {
83-
b := &BrowsingPane{app: app}
69+
func NewBrowsingPane(app *backend.PlaybackManager, contr *controller.Controller, onGoHome func()) *BrowsingPane {
70+
b := &BrowsingPane{playbackManager: app}
8471
b.ExtendBaseWidget(b)
85-
b.home = ttwidget.NewButtonWithIcon("", theme.HomeIcon(), onGoHome)
86-
b.home.SetToolTip(lang.L("Home"))
87-
b.back = ttwidget.NewButtonWithIcon("", theme.NavigateBackIcon(), b.GoBack)
88-
b.back.SetToolTip(lang.L("Back"))
89-
b.forward = ttwidget.NewButtonWithIcon("", theme.NavigateNextIcon(), b.GoForward)
90-
b.forward.SetToolTip(lang.L("Forward"))
91-
b.reload = ttwidget.NewButtonWithIcon("", theme.ViewRefreshIcon(), b.Reload)
92-
b.reload.SetToolTip(lang.L("Reload"))
93-
b.app.PlaybackManager.OnSongChange(b.onSongChange)
94-
b.app.PlaybackManager.OnPlayTimeUpdate(b.onPlayTimeUpdate)
95-
b.app.PlaybackManager.OnQueueChange(b.onQueueChange)
72+
b.playbackManager.OnSongChange(b.onSongChange)
73+
b.playbackManager.OnPlayTimeUpdate(b.onPlayTimeUpdate)
74+
b.playbackManager.OnQueueChange(b.onQueueChange)
9675
bkgrnd := myTheme.NewThemedRectangle(myTheme.ColorNamePageBackground)
9776
b.pageContainer = container.NewStack(bkgrnd, layout.NewSpacer())
98-
b.settingsBtn = ttwidget.NewButtonWithIcon("", theme.SettingsIcon(), func() {
99-
p := widget.NewPopUpMenu(b.settingsMenu,
100-
fyne.CurrentApp().Driver().CanvasForObject(b.settingsBtn))
101-
p.ShowAtPosition(fyne.NewPos(b.Size().Width-p.MinSize().Width+4,
102-
b.navBtnsContainer.MinSize().Height+theme.Padding()))
103-
})
104-
b.settingsBtn.SetToolTip(lang.L("Menu"))
105-
quickSearchBtn := ttwidget.NewButtonWithIcon("", theme.SearchIcon(), contr.ShowQuickSearch)
106-
quickSearchBtn.SetToolTip(lang.L("Search Everywhere"))
107-
b.settingsMenu = fyne.NewMenu("")
108-
b.navBtnsContainer = container.NewHBox()
109-
b.navBtnsPageMap = map[controller.PageName]fyne.Resource{}
110-
b.container = container.NewBorder(container.New(
111-
&layout.CustomPaddedLayout{LeftPadding: -5, RightPadding: -5},
112-
container.New(layouts.NewLeftMiddleRightLayout(0, 0),
113-
container.NewHBox(b.home, b.back, b.forward, b.reload), b.navBtnsContainer,
114-
container.NewHBox(layout.NewSpacer(), quickSearchBtn, b.settingsBtn))),
115-
nil, nil, nil, b.pageContainer)
116-
b.updateHistoryButtons()
11777
return b
11878
}
11979

@@ -124,77 +84,19 @@ func (b *BrowsingPane) SetPage(p Page) {
12484
b.pageContainer.Objects[1] = layout.NewSpacer()
12585
b.curPage = nil
12686
b.pageContainer.Refresh()
127-
b.updateNavBtnsColor(p)
12887
} else {
12988
oldPage := b.curPage
13089
if b.doSetPage(p) && oldPage != nil {
13190
b.addPageToHistory(oldPage, true)
132-
b.updateHistoryButtons()
13391
}
13492
}
93+
b.onHistoryChanged()
13594
}
13695

13796
func (b *BrowsingPane) ClearHistory() {
13897
b.history = nil
13998
b.historyIdx = 0
140-
b.updateHistoryButtons()
141-
}
142-
143-
func (b *BrowsingPane) AddSettingsMenuItem(label string, icon fyne.Resource, action func()) {
144-
item := fyne.NewMenuItem(label, action)
145-
item.Icon = icon
146-
b.settingsMenu.Items = append(b.settingsMenu.Items, item)
147-
}
148-
149-
func (b *BrowsingPane) AddSettingsSubmenu(label string, icon fyne.Resource, menu *fyne.Menu) {
150-
item := fyne.NewMenuItem(label, nil)
151-
item.ChildMenu = menu
152-
item.Icon = icon
153-
b.settingsMenu.Items = append(b.settingsMenu.Items, item)
154-
}
155-
156-
func (b *BrowsingPane) SetSubmenuForMenuItem(label string, submenu *fyne.Menu) {
157-
for _, item := range b.settingsMenu.Items {
158-
if item.Label == label {
159-
item.ChildMenu = submenu
160-
}
161-
}
162-
}
163-
164-
func (b *BrowsingPane) AddSettingsMenuSeparator() {
165-
b.settingsMenu.Items = append(b.settingsMenu.Items,
166-
fyne.NewMenuItemSeparator())
167-
}
168-
169-
func (b *BrowsingPane) AddNavigationButton(icon fyne.Resource, pageName controller.PageName, action func()) *ttwidget.Button {
170-
// make a copy of the icon, because it can change the color
171-
browsingPaneIcon := theme.NewThemedResource(icon)
172-
btn := ttwidget.NewButtonWithIcon("", browsingPaneIcon, action)
173-
btn.SetToolTip(lang.L(pageName.String()))
174-
b.navBtnsContainer.Add(btn)
175-
b.navBtnsPageMap[pageName] = browsingPaneIcon
176-
return btn
177-
}
178-
179-
func (b *BrowsingPane) DisableNavigationButtons() {
180-
for _, obj := range b.navBtnsContainer.Objects {
181-
obj.(fyne.Disableable).Disable()
182-
}
183-
}
184-
185-
func (b *BrowsingPane) EnableNavigationButtons() {
186-
for _, obj := range b.navBtnsContainer.Objects {
187-
obj.(fyne.Disableable).Enable()
188-
}
189-
}
190-
191-
func (b *BrowsingPane) ActivateNavigationButton(num int) {
192-
if num < len(b.navBtnsContainer.Objects) {
193-
btn := b.navBtnsContainer.Objects[num].(*widget.Button)
194-
if !btn.Disabled() && !btn.Hidden {
195-
btn.OnTapped()
196-
}
197-
}
99+
b.onHistoryChanged()
198100
}
199101

200102
func (b *BrowsingPane) GetSearchBarIfAny() fyne.Focusable {
@@ -255,15 +157,20 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
255157
b.curPage = p
256158
if np, ok := p.(CanShowNowPlaying); ok {
257159
// inform page of currently playing track
258-
np.OnSongChange(b.app.PlaybackManager.NowPlaying(), nil)
160+
np.OnSongChange(b.playbackManager.NowPlaying(), nil)
259161
}
260162
b.pageContainer.Remove(b.curPage)
261163
b.pageContainer.Objects[1] = p
262-
b.updateNavBtnsColor(p)
263164
b.Refresh()
264165
return true
265166
}
266167

168+
func (b *BrowsingPane) onHistoryChanged() {
169+
if b.OnHistoryChanged != nil {
170+
b.OnHistoryChanged()
171+
}
172+
}
173+
267174
func (b *BrowsingPane) onSongChange(song mediaprovider.MediaItem, lastScrobbledIfAny *mediaprovider.Track) {
268175
fyne.Do(func() {
269176
if b.curPage == nil {
@@ -313,17 +220,12 @@ func (b *BrowsingPane) addPageToHistory(p Page, truncate bool) {
313220
b.historyIdx++
314221
}
315222

316-
func (b *BrowsingPane) updateHistoryButtons() {
317-
if b.historyIdx > 0 {
318-
b.back.Enable()
319-
} else {
320-
b.back.Disable()
321-
}
322-
if b.historyIdx < len(b.history)-1 {
323-
b.forward.Enable()
324-
} else {
325-
b.forward.Disable()
326-
}
223+
func (b *BrowsingPane) CanGoBack() bool {
224+
return b.historyIdx > 0
225+
}
226+
227+
func (b *BrowsingPane) CanGoForward() bool {
228+
return b.historyIdx < len(b.history)-1
327229
}
328230

329231
func (b *BrowsingPane) GoBack() {
@@ -334,7 +236,7 @@ func (b *BrowsingPane) GoBack() {
334236
b.addPageToHistory(b.curPage, false)
335237
b.historyIdx -= 2
336238
b.doSetPage(p)
337-
b.updateHistoryButtons()
239+
b.onHistoryChanged()
338240
}
339241
}
340242

@@ -343,7 +245,7 @@ func (b *BrowsingPane) GoForward() {
343245
p := b.history[b.historyIdx+1].Restore()
344246
b.addPageToHistory(b.curPage, false)
345247
b.doSetPage(p)
346-
b.updateHistoryButtons()
248+
b.onHistoryChanged()
347249
}
348250
}
349251

@@ -361,15 +263,5 @@ func (b *BrowsingPane) CurrentPage() controller.Route {
361263
}
362264

363265
func (b *BrowsingPane) CreateRenderer() fyne.WidgetRenderer {
364-
return widget.NewSimpleRenderer(b.container)
365-
}
366-
367-
func (b *BrowsingPane) updateNavBtnsColor(p Page) {
368-
for pageName, icon := range b.navBtnsPageMap {
369-
if p != nil && pageName == p.Route().Page {
370-
icon.(*theme.ThemedResource).ColorName = theme.ColorNamePrimary
371-
} else {
372-
icon.(*theme.ThemedResource).ColorName = theme.ColorNameForeground
373-
}
374-
}
266+
return widget.NewSimpleRenderer(b.pageContainer)
375267
}

0 commit comments

Comments
 (0)