add list header
This commit is contained in:
@@ -25,7 +25,10 @@ type ArtistGenrePlaylist struct {
|
|||||||
ShowTrackCount bool
|
ShowTrackCount bool
|
||||||
OnNavTo func(string)
|
OnNavTo func(string)
|
||||||
|
|
||||||
|
columnsLayout *layouts.ColumnsLayout
|
||||||
|
hdr *ListHeader
|
||||||
list *widget.List
|
list *widget.List
|
||||||
|
container *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistGenrePlaylistRow struct {
|
type ArtistGenrePlaylistRow struct {
|
||||||
@@ -41,26 +44,28 @@ type ArtistGenrePlaylistRow struct {
|
|||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArtistGenrePlaylistRow() *ArtistGenrePlaylistRow {
|
func NewArtistGenrePlaylistRow(layout *layouts.ColumnsLayout) *ArtistGenrePlaylistRow {
|
||||||
a := &ArtistGenrePlaylistRow{
|
a := &ArtistGenrePlaylistRow{
|
||||||
nameLabel: widget.NewLabel(""),
|
nameLabel: widget.NewLabel(""),
|
||||||
albumCountLabel: widget.NewLabel("alCount"),
|
albumCountLabel: widget.NewLabel("alCount"),
|
||||||
trackCountLabel: widget.NewLabel(""),
|
trackCountLabel: widget.NewLabel(""),
|
||||||
}
|
}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.container = container.New(layouts.NewColumnsLayout([]float32{-1, 100, 100}), a.nameLabel, a.albumCountLabel, a.trackCountLabel)
|
a.container = container.New(layout, a.nameLabel, a.albumCountLabel, a.trackCountLabel)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArtistGenrePlaylist(items []ArtistGenrePlaylistItemModel) *ArtistGenrePlaylist {
|
func NewArtistGenrePlaylist(items []ArtistGenrePlaylistItemModel) *ArtistGenrePlaylist {
|
||||||
a := &ArtistGenrePlaylist{
|
a := &ArtistGenrePlaylist{
|
||||||
Items: items,
|
Items: items,
|
||||||
|
columnsLayout: layouts.NewColumnsLayout([]float32{-1, 125, 125}),
|
||||||
}
|
}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
|
a.hdr = NewListHeader([]string{"Name", "Album Count", "Track Count"}, a.columnsLayout)
|
||||||
a.list = widget.NewList(
|
a.list = widget.NewList(
|
||||||
func() int { return len(a.Items) },
|
func() int { return len(a.Items) },
|
||||||
func() fyne.CanvasObject {
|
func() fyne.CanvasObject {
|
||||||
r := NewArtistGenrePlaylistRow()
|
r := NewArtistGenrePlaylistRow(a.columnsLayout)
|
||||||
r.OnTapped = func() { a.onRowDoubleTapped(r.Item) }
|
r.OnTapped = func() { a.onRowDoubleTapped(r.Item) }
|
||||||
return r
|
return r
|
||||||
},
|
},
|
||||||
@@ -75,9 +80,16 @@ func NewArtistGenrePlaylist(items []ArtistGenrePlaylistItemModel) *ArtistGenrePl
|
|||||||
row.Refresh()
|
row.Refresh()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
a.container = container.NewBorder(a.hdr, nil, nil, nil, a.list)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *ArtistGenrePlaylist) Refresh() {
|
||||||
|
a.hdr.SetColumnVisible(1, a.ShowAlbumCount)
|
||||||
|
a.hdr.SetColumnVisible(2, a.ShowTrackCount)
|
||||||
|
a.BaseWidget.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
func (a *ArtistGenrePlaylist) onRowDoubleTapped(item ArtistGenrePlaylistItemModel) {
|
func (a *ArtistGenrePlaylist) onRowDoubleTapped(item ArtistGenrePlaylistItemModel) {
|
||||||
if a.OnNavTo != nil {
|
if a.OnNavTo != nil {
|
||||||
a.OnNavTo(item.ID)
|
a.OnNavTo(item.ID)
|
||||||
@@ -91,7 +103,7 @@ func (a *ArtistGenrePlaylistRow) Tapped(*fyne.PointEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArtistGenrePlaylist) CreateRenderer() fyne.WidgetRenderer {
|
func (a *ArtistGenrePlaylist) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return widget.NewSimpleRenderer(a.list)
|
return widget.NewSimpleRenderer(a.container)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArtistGenrePlaylistRow) CreateRenderer() fyne.WidgetRenderer {
|
func (a *ArtistGenrePlaylistRow) CreateRenderer() fyne.WidgetRenderer {
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package widgets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"supersonic/ui/layouts"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/canvas"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListHeader struct {
|
||||||
|
widget.BaseWidget
|
||||||
|
|
||||||
|
columns []string
|
||||||
|
columnsLayout *layouts.ColumnsLayout
|
||||||
|
|
||||||
|
columnsContainer *fyne.Container
|
||||||
|
container *fyne.Container
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewListHeader(cols []string, layout *layouts.ColumnsLayout) *ListHeader {
|
||||||
|
l := &ListHeader{
|
||||||
|
columns: cols,
|
||||||
|
columnsLayout: layout,
|
||||||
|
columnsContainer: container.New(layout),
|
||||||
|
}
|
||||||
|
l.container = container.NewMax(canvas.NewRectangle(theme.BackgroundColor()), l.columnsContainer)
|
||||||
|
l.ExtendBaseWidget(l)
|
||||||
|
l.buildColumns()
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListHeader) SetColumnVisible(colNum int, visible bool) {
|
||||||
|
if visible {
|
||||||
|
l.columnsContainer.Objects[colNum].Show()
|
||||||
|
} else {
|
||||||
|
l.columnsContainer.Objects[colNum].Hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListHeader) buildColumns() {
|
||||||
|
for _, c := range l.columns {
|
||||||
|
t := widget.NewRichTextWithText(c)
|
||||||
|
t.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = true
|
||||||
|
l.columnsContainer.Add(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListHeader) CreateRenderer() fyne.WidgetRenderer {
|
||||||
|
return widget.NewSimpleRenderer(l.container)
|
||||||
|
}
|
||||||
+10
-4
@@ -30,7 +30,7 @@ type TrackRow struct {
|
|||||||
|
|
||||||
var _ fyne.DoubleTappable = (*TrackRow)(nil)
|
var _ fyne.DoubleTappable = (*TrackRow)(nil)
|
||||||
|
|
||||||
func NewTrackRow() *TrackRow {
|
func NewTrackRow(layout *layouts.ColumnsLayout) *TrackRow {
|
||||||
t := &TrackRow{}
|
t := &TrackRow{}
|
||||||
t.ExtendBaseWidget(t)
|
t.ExtendBaseWidget(t)
|
||||||
t.num = widget.NewRichTextWithText("")
|
t.num = widget.NewRichTextWithText("")
|
||||||
@@ -40,7 +40,7 @@ func NewTrackRow() *TrackRow {
|
|||||||
t.artist.Wrapping = fyne.TextTruncate
|
t.artist.Wrapping = fyne.TextTruncate
|
||||||
t.dur = widget.NewRichTextWithText("")
|
t.dur = widget.NewRichTextWithText("")
|
||||||
|
|
||||||
t.container = container.New(layouts.NewColumnsLayout([]float32{35, -1, -1, 55}),
|
t.container = container.New(layout,
|
||||||
t.num, t.name, t.artist, t.dur)
|
t.num, t.name, t.artist, t.dur)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
@@ -82,20 +82,26 @@ type Tracklist struct {
|
|||||||
OnPlayTrackAt func(int)
|
OnPlayTrackAt func(int)
|
||||||
|
|
||||||
nowPlayingIdx int
|
nowPlayingIdx int
|
||||||
|
colLayout *layouts.ColumnsLayout
|
||||||
|
hdr *ListHeader
|
||||||
list *widget.List
|
list *widget.List
|
||||||
|
container *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
||||||
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1}
|
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1}
|
||||||
t.ExtendBaseWidget(t)
|
t.ExtendBaseWidget(t)
|
||||||
|
t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, 55})
|
||||||
|
t.hdr = NewListHeader([]string{"#", "Title", "Artist", "Time"}, t.colLayout)
|
||||||
t.list = widget.NewList(
|
t.list = widget.NewList(
|
||||||
func() int { return len(t.Tracks) },
|
func() int { return len(t.Tracks) },
|
||||||
func() fyne.CanvasObject { return NewTrackRow() },
|
func() fyne.CanvasObject { return NewTrackRow(t.colLayout) },
|
||||||
func(itemID widget.ListItemID, item fyne.CanvasObject) {
|
func(itemID widget.ListItemID, item fyne.CanvasObject) {
|
||||||
tr := item.(*TrackRow)
|
tr := item.(*TrackRow)
|
||||||
tr.OnDoubleTapped = func() { t.onPlayTrackAt(itemID) }
|
tr.OnDoubleTapped = func() { t.onPlayTrackAt(itemID) }
|
||||||
tr.Update(t.Tracks[itemID], itemID == t.nowPlayingIdx)
|
tr.Update(t.Tracks[itemID], itemID == t.nowPlayingIdx)
|
||||||
})
|
})
|
||||||
|
t.container = container.NewBorder(t.hdr, nil, nil, nil, t.list)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +117,7 @@ func (t *Tracklist) SetNowPlaying(trackID string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
|
func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return widget.NewSimpleRenderer(t.list)
|
return widget.NewSimpleRenderer(t.container)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracklist) onPlayTrackAt(idx int) {
|
func (t *Tracklist) onPlayTrackAt(idx int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user