From f5a4146e2b102949c7c6c1b854ef3b9b9e2b6e41 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Fri, 14 Jun 2024 08:30:04 -0700 Subject: [PATCH] move to list fork --- go.mod | 1 + go.sum | 4 ++++ ui/browsing/genrespage.go | 1 - ui/browsing/playlistspage.go | 1 - ui/browsing/radiospage.go | 1 - ui/widgets/albumfilterbutton.go | 1 - ui/widgets/focuslist.go | 36 +++++++++++---------------------- ui/widgets/playqueuelist.go | 3 --- ui/widgets/tracklist.go | 5 ----- 9 files changed, 17 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index dc95f667..ec9317f2 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( github.com/danieljoos/wincred v1.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/disintegration/imaging v1.6.2 // indirect + github.com/dweymouth/fyne-advanced-list v0.0.0-20240614152514-d7bef361f680 // indirect github.com/fredbi/uri v1.1.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect diff --git a/go.sum b/go.sum index 335b6a50..192940cb 100644 --- a/go.sum +++ b/go.sum @@ -84,6 +84,10 @@ github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1 h1:mGvOb3zxl4vCLv+ github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1/go.mod h1:ZNCLJfehvEf34B7BbLKjgpsL9lyW7q938w/GY1XgV4E= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= +github.com/dweymouth/fyne-advanced-list v0.0.0-20240614151622-9f11c64def19 h1:AfKaUmPlcXyQRlCH/3tX2A+oIOKLC14Ns3AfIjn4NC4= +github.com/dweymouth/fyne-advanced-list v0.0.0-20240614151622-9f11c64def19/go.mod h1:5bICtCEhLzJ4MlRORlUa3L0CadB6xQTNW9DhTXl/UN0= +github.com/dweymouth/fyne-advanced-list v0.0.0-20240614152514-d7bef361f680 h1:PDffxh0kv4czCCrFV2uSWDRKnIgpaDZhqohB4mYX9Vg= +github.com/dweymouth/fyne-advanced-list v0.0.0-20240614152514-d7bef361f680/go.mod h1:5bICtCEhLzJ4MlRORlUa3L0CadB6xQTNW9DhTXl/UN0= github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64 h1:RUIrnGY034rDMlcOui/daurwX5b+52KdUKhH9aXaDSg= github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64/go.mod h1:3YrjFDHMlhCsSZ/OvmJCxWm9QHSgOVWZBxnraZz9Z7c= github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240604143614-256525c6a602 h1:k3jFLjmAuPJ5ZFNF57szZp8XrLIb6mIdEEGPkm6EZ7Q= diff --git a/ui/browsing/genrespage.go b/ui/browsing/genrespage.go index a8afdad7..504d9110 100644 --- a/ui/browsing/genrespage.go +++ b/ui/browsing/genrespage.go @@ -212,7 +212,6 @@ func NewGenreList(sorting widgets.ListHeaderSort) *GenreList { }, func(id widget.ListItemID, item fyne.CanvasObject) { row := item.(*GenreListRow) - a.list.SetItemForID(id, row) if row.Item != a.genres[id] { row.EnsureUnfocused() row.ListItemID = id diff --git a/ui/browsing/playlistspage.go b/ui/browsing/playlistspage.go index 305c0705..95c4ac19 100644 --- a/ui/browsing/playlistspage.go +++ b/ui/browsing/playlistspage.go @@ -354,7 +354,6 @@ func NewPlaylistList(initialSort widgets.ListHeaderSort) *PlaylistList { row := item.(*PlaylistListRow) if row.PlaylistID != a.playlists[id].ID { row.EnsureUnfocused() - a.list.SetItemForID(id, row) row.ListItemID = id row.PlaylistID = a.playlists[id].ID row.nameLabel.Text = a.playlists[id].Name diff --git a/ui/browsing/radiospage.go b/ui/browsing/radiospage.go index 82b6f14c..2cb04c9e 100644 --- a/ui/browsing/radiospage.go +++ b/ui/browsing/radiospage.go @@ -279,7 +279,6 @@ func NewRadioList(nowPlayingIDPtr *string) *RadioList { }, func(id widget.ListItemID, item fyne.CanvasObject) { row := item.(*RadioListRow) - a.list.SetItemForID(id, row) changed := false if row.Item != a.radios[id] { row.EnsureUnfocused() diff --git a/ui/widgets/albumfilterbutton.go b/ui/widgets/albumfilterbutton.go index 78c18293..68f92df5 100644 --- a/ui/widgets/albumfilterbutton.go +++ b/ui/widgets/albumfilterbutton.go @@ -274,7 +274,6 @@ func NewGenreFilterSubsection(onChanged func([]string), initialSelectedGenres [] _, selected := g.selectedGenres[genre] g.selectedGenresMutex.RUnlock() row := obj.(*genreListViewRow) - g.genreListView.SetItemForID(id, row) row.ListItemID = id row.Content.(*widget.Check).Text = genre row.Content.(*widget.Check).Checked = selected diff --git a/ui/widgets/focuslist.go b/ui/widgets/focuslist.go index 6dabac73..3c1c2c6b 100644 --- a/ui/widgets/focuslist.go +++ b/ui/widgets/focuslist.go @@ -9,16 +9,17 @@ import ( "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" + + list "github.com/dweymouth/fyne-advanced-list" ) // FocusList extends List to be disabled so that the focus manager // considers it unfocusable, and adds utilities for handling our // own focus navigation on the rows directly (with FocusListRow type FocusList struct { - widget.List + list.List - mutex sync.Mutex - itemForIndex map[widget.ListItemID]FocusListRow + mutex sync.Mutex } type FocusListRow interface { @@ -33,13 +34,12 @@ type FocusListRow interface { func NewFocusList(len func() int, create func() fyne.CanvasObject, update func(widget.GridWrapItemID, fyne.CanvasObject)) *FocusList { g := &FocusList{ - List: widget.List{ + List: list.List{ HideSeparators: true, Length: len, CreateItem: create, UpdateItem: update, }, - itemForIndex: make(map[int]FocusListRow), } g.ExtendBaseWidget(g) return g @@ -53,21 +53,6 @@ func (g *FocusList) Disable() {} func (g *FocusList) Enable() {} -// MUST be called *before* updating the ListItemID field to the -// new ItemID this row will be bound to. -func (g *FocusList) SetItemForID(id widget.ListItemID, item FocusListRow) { - g.mutex.Lock() - if other, ok := g.itemForIndex[id]; ok && other == item { - delete(g.itemForIndex, other.ItemID()) - } - g.itemForIndex[id] = item - g.mutex.Unlock() -} - -func (g *FocusList) ClearItemForIDMap() { - g.itemForIndex = make(map[int]FocusListRow) -} - func (g *FocusList) FocusNeighbor(curItem widget.ListItemID, up bool) { focusIdx := curItem + 1 if up { @@ -77,10 +62,10 @@ func (g *FocusList) FocusNeighbor(curItem widget.ListItemID, up bool) { g.ScrollTo(focusIdx) } g.mutex.Lock() - other, ok := g.itemForIndex[focusIdx] + other := g.ItemForID(focusIdx) g.mutex.Unlock() - if ok { - fyne.CurrentApp().Driver().CanvasForObject(g).Focus(other) + if other != nil { + fyne.CurrentApp().Driver().CanvasForObject(g).Focus(other.(fyne.Focusable)) } } @@ -128,7 +113,10 @@ func (l *FocusListRowBase) SetItemID(id widget.ListItemID) { func (l *FocusListRowBase) EnsureUnfocused() { if l.Focused { - fyne.CurrentApp().Driver().CanvasForObject(l).Unfocus() + c := fyne.CurrentApp().Driver().CanvasForObject(l) + if c != nil { + c.Unfocus() + } } l.Focused = false } diff --git a/ui/widgets/playqueuelist.go b/ui/widgets/playqueuelist.go index 57b6cbd5..71118577 100644 --- a/ui/widgets/playqueuelist.go +++ b/ui/widgets/playqueuelist.go @@ -96,7 +96,6 @@ func NewPlayQueueList(im *backend.ImageManager, useNonQueueMenu bool) *PlayQueue p.tracksMutex.RUnlock() tr := item.(*PlayQueueListRow) - p.list.SetItemForID(itemID, tr) if tr.trackID != model.Item.Metadata().ID || tr.ListItemID != itemID { tr.ListItemID = itemID } @@ -109,7 +108,6 @@ func NewPlayQueueList(im *backend.ImageManager, useNonQueueMenu bool) *PlayQueue func (p *PlayQueueList) SetTracks(trs []*mediaprovider.Track) { p.tracksMutex.Lock() - p.list.ClearItemForIDMap() p.items = util.ToTrackListModels(trs) p.tracksMutex.Unlock() p.Refresh() @@ -117,7 +115,6 @@ func (p *PlayQueueList) SetTracks(trs []*mediaprovider.Track) { func (p *PlayQueueList) SetItems(items []mediaprovider.MediaItem) { p.tracksMutex.Lock() - p.list.ClearItemForIDMap() p.items = sharedutil.MapSlice(items, func(item mediaprovider.MediaItem) *util.TrackListModel { return &util.TrackListModel{Item: item} }) diff --git a/ui/widgets/tracklist.go b/ui/widgets/tracklist.go index feb8d119..1537a78c 100644 --- a/ui/widgets/tracklist.go +++ b/ui/widgets/tracklist.go @@ -170,7 +170,6 @@ func NewTracklist(tracks []*mediaprovider.Track, im *backend.ImageManager, useCo t.tracksMutex.RUnlock() tr := item.(TracklistRow) - t.list.SetItemForID(itemID, tr) if tr.TrackID() != model.Item.Metadata().ID || tr.ItemID() != itemID { tr.SetItemID(itemID) } @@ -300,7 +299,6 @@ func (t *Tracklist) Clear() { defer t.tracksMutex.Unlock() t.tracks = nil t.tracksOrigOrder = nil - t.list.ClearItemForIDMap() } // Sets the tracks in the tracklist. Thread-safe. @@ -312,9 +310,6 @@ func (t *Tracklist) SetTracks(trs []*mediaprovider.Track) { func (t *Tracklist) _setTracks(trs []*mediaprovider.Track) { t.tracksMutex.Lock() defer t.tracksMutex.Unlock() - if t.list != nil { - t.list.ClearItemForIDMap() - } t.tracksOrigOrder = util.ToTrackListModels(trs) t.doSortTracks() }