tweaks to artists list
This commit is contained in:
@@ -36,6 +36,9 @@ func NewArtistsPage(sm *backend.ServerManager, nav func(Route)) *ArtistsPage {
|
|||||||
a.list = widgets.NewArtistGenrePlaylist(nil)
|
a.list = widgets.NewArtistGenrePlaylist(nil)
|
||||||
a.list.ShowAlbumCount = true
|
a.list.ShowAlbumCount = true
|
||||||
a.list.ShowTrackCount = false
|
a.list.ShowTrackCount = false
|
||||||
|
a.list.OnNavTo = func(id string) {
|
||||||
|
nav(ArtistRoute(id))
|
||||||
|
}
|
||||||
a.buildContainer()
|
a.buildContainer()
|
||||||
go a.loadAsync()
|
go a.loadAsync()
|
||||||
return a
|
return a
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package widgets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"supersonic/ui/layouts"
|
||||||
|
|
||||||
"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/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ type ArtistGenrePlaylist struct {
|
|||||||
Items []ArtistGenrePlaylistItemModel
|
Items []ArtistGenrePlaylistItemModel
|
||||||
ShowAlbumCount bool
|
ShowAlbumCount bool
|
||||||
ShowTrackCount bool
|
ShowTrackCount bool
|
||||||
|
OnNavTo func(string)
|
||||||
|
|
||||||
list *widget.List
|
list *widget.List
|
||||||
}
|
}
|
||||||
@@ -31,6 +32,7 @@ type ArtistGenrePlaylistRow struct {
|
|||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
Item ArtistGenrePlaylistItemModel
|
Item ArtistGenrePlaylistItemModel
|
||||||
|
OnTapped func()
|
||||||
|
|
||||||
nameLabel *widget.Label
|
nameLabel *widget.Label
|
||||||
albumCountLabel *widget.Label
|
albumCountLabel *widget.Label
|
||||||
@@ -46,8 +48,7 @@ func NewArtistGenrePlaylistRow() *ArtistGenrePlaylistRow {
|
|||||||
trackCountLabel: widget.NewLabel(""),
|
trackCountLabel: widget.NewLabel(""),
|
||||||
}
|
}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
// layouts.NewColumnsLayout([]float32{-1, 50, 50})
|
a.container = container.New(layouts.NewColumnsLayout([]float32{-1, 100, 100}), a.nameLabel, a.albumCountLabel, a.trackCountLabel)
|
||||||
a.container = container.New(layout.NewHBoxLayout(), a.nameLabel, a.albumCountLabel, a.trackCountLabel)
|
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,12 +59,16 @@ func NewArtistGenrePlaylist(items []ArtistGenrePlaylistItemModel) *ArtistGenrePl
|
|||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.list = widget.NewList(
|
a.list = widget.NewList(
|
||||||
func() int { return len(a.Items) },
|
func() int { return len(a.Items) },
|
||||||
func() fyne.CanvasObject { return NewArtistGenrePlaylistRow() },
|
func() fyne.CanvasObject {
|
||||||
|
r := NewArtistGenrePlaylistRow()
|
||||||
|
r.OnTapped = func() { a.onRowDoubleTapped(r.Item) }
|
||||||
|
return r
|
||||||
|
},
|
||||||
func(id widget.ListItemID, item fyne.CanvasObject) {
|
func(id widget.ListItemID, item fyne.CanvasObject) {
|
||||||
row := item.(*ArtistGenrePlaylistRow)
|
row := item.(*ArtistGenrePlaylistRow)
|
||||||
row.Item = a.Items[id]
|
row.Item = a.Items[id]
|
||||||
row.albumCountLabel.Hidden = a.ShowAlbumCount
|
row.albumCountLabel.Hidden = !a.ShowAlbumCount
|
||||||
row.trackCountLabel.Hidden = a.ShowTrackCount
|
row.trackCountLabel.Hidden = !a.ShowTrackCount
|
||||||
row.nameLabel.Text = row.Item.Name
|
row.nameLabel.Text = row.Item.Name
|
||||||
row.albumCountLabel.Text = strconv.Itoa(row.Item.AlbumCount)
|
row.albumCountLabel.Text = strconv.Itoa(row.Item.AlbumCount)
|
||||||
row.trackCountLabel.Text = strconv.Itoa(row.Item.TrackCount)
|
row.trackCountLabel.Text = strconv.Itoa(row.Item.TrackCount)
|
||||||
@@ -73,6 +78,18 @@ func NewArtistGenrePlaylist(items []ArtistGenrePlaylistItemModel) *ArtistGenrePl
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *ArtistGenrePlaylist) onRowDoubleTapped(item ArtistGenrePlaylistItemModel) {
|
||||||
|
if a.OnNavTo != nil {
|
||||||
|
a.OnNavTo(item.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ArtistGenrePlaylistRow) Tapped(*fyne.PointEvent) {
|
||||||
|
if a.OnTapped != nil {
|
||||||
|
a.OnTapped()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *ArtistGenrePlaylist) CreateRenderer() fyne.WidgetRenderer {
|
func (a *ArtistGenrePlaylist) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return widget.NewSimpleRenderer(a.list)
|
return widget.NewSimpleRenderer(a.list)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user