add history and navigation controls

This commit is contained in:
Drew Weymouth
2023-01-01 09:34:51 -08:00
parent 0ff1b6bafd
commit e27cb1a048
2 changed files with 37 additions and 3 deletions
+36 -2
View File
@@ -8,6 +8,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
@@ -28,11 +29,17 @@ type BrowsingPane struct {
app *backend.App
curPage Page
forward *widget.Button
back *widget.Button
history []Page
historyIdx int
searchBar *widgets.SearchEntry
pendingSearchLock sync.Mutex
pendingSearch bool
searchGoroutine bool
curPage Page
container *fyne.Container
}
@@ -46,14 +53,21 @@ func NewBrowsingPane(app *backend.App) *BrowsingPane {
b.ExtendBaseWidget(b)
b.searchBar = widgets.NewSearchEntry()
b.searchBar.OnTextChanged = b.onSearchTextChanged
b.back = widget.NewButtonWithIcon("", theme.NavigateBackIcon(), b.GoBack)
b.forward = widget.NewButtonWithIcon("", theme.NavigateNextIcon(), b.GoForward)
b.curPage = &blankPage{}
b.container = container.NewBorder(
container.NewHBox(widgets.NewHSpace(15), b.searchBar),
container.NewHBox(b.back, b.forward, b.searchBar),
nil, nil, nil, b.curPage)
return b
}
func (b *BrowsingPane) SetPage(p Page) {
b.addPageToHistory(p)
b.doSetPage(p)
}
func (b *BrowsingPane) doSetPage(p Page) {
b.curPage = p
if pa, ok := p.(CanPlayAlbum); ok {
pa.SetPlayAlbumCallback(func(albumID string) {
@@ -66,6 +80,26 @@ func (b *BrowsingPane) SetPage(p Page) {
b.Refresh()
}
func (b *BrowsingPane) addPageToHistory(p Page) {
b.history = b.history[:b.historyIdx]
b.history = append(b.history, p)
b.historyIdx++
}
func (b *BrowsingPane) GoBack() {
if b.historyIdx > 1 {
b.historyIdx -= 1
b.doSetPage(b.history[b.historyIdx-1])
}
}
func (b *BrowsingPane) GoForward() {
if b.historyIdx < len(b.history) {
b.historyIdx++
b.doSetPage(b.history[b.historyIdx-1])
}
}
func (b *BrowsingPane) onSearchTextChanged(text string) {
if text == "" {
b.sendSearch("")
+1 -1
View File
@@ -40,7 +40,7 @@ func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App) MainWindo
m.Window.SetTitle(song.Title)
})
app.ServerManager.OnServerConnected(func() {
m.Router.OpenRoute(AlbumsRoute(backend.AlbumSortFrequentlyPlayed))
m.Router.OpenRoute(AlbumsRoute(backend.AlbumSortRecentlyAdded))
})
return m
}