album page now highlights currently playing track (with bold/italic font for now)

This commit is contained in:
Drew Weymouth
2023-01-04 17:11:15 -08:00
parent 395f8953e3
commit 9ac497e25b
3 changed files with 70 additions and 24 deletions
+30 -11
View File
@@ -14,8 +14,9 @@ import (
type TrackRow struct {
widget.BaseWidget
trackID string
prevTrackID string
trackID string
prevTrackID string
prevIsPlaying bool
num *widget.RichText
name *widget.RichText
@@ -39,22 +40,28 @@ func NewTrackRow() *TrackRow {
t.artist.Wrapping = fyne.TextTruncate
t.dur = widget.NewRichTextWithText("")
t.container = container.New(layouts.NewColumnsLayout([]float32{30, -1, -1, 55}),
t.container = container.New(layouts.NewColumnsLayout([]float32{35, -1, -1, 55}),
t.num, t.name, t.artist, t.dur)
return t
}
func (t *TrackRow) Update(tr *subsonic.Child) {
if tr.ID == t.prevTrackID {
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool) {
if tr.ID == t.prevTrackID && isPlaying == t.prevIsPlaying {
return
}
t.prevTrackID = t.trackID
t.prevIsPlaying = isPlaying
t.trackID = tr.ID
t.num.Segments[0].(*widget.TextSegment).Text = strconv.Itoa(tr.Track)
t.name.Segments[0].(*widget.TextSegment).Text = tr.Title
t.artist.Segments[0].(*widget.TextSegment).Text = tr.Artist
t.dur.Segments[0].(*widget.TextSegment).Text = util.SecondsToTimeString(float64(tr.Duration))
t.num.Segments[0].(*widget.TextSegment).Style.TextStyle = fyne.TextStyle{Bold: isPlaying}
t.name.Segments[0].(*widget.TextSegment).Style.TextStyle = fyne.TextStyle{Bold: isPlaying, Italic: isPlaying}
t.artist.Segments[0].(*widget.TextSegment).Style.TextStyle = fyne.TextStyle{Bold: isPlaying, Italic: isPlaying}
t.dur.Segments[0].(*widget.TextSegment).Style.TextStyle = fyne.TextStyle{Bold: isPlaying}
t.Refresh()
}
@@ -71,26 +78,38 @@ func (t *TrackRow) DoubleTapped(*fyne.PointEvent) {
type Tracklist struct {
widget.BaseWidget
tracks []*subsonic.Child
list *widget.List
Tracks []*subsonic.Child
OnPlayTrackAt func(int)
nowPlayingIdx int
list *widget.List
}
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
t := &Tracklist{tracks: tracks}
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1}
t.ExtendBaseWidget(t)
t.list = widget.NewList(
func() int { return len(t.tracks) },
func() int { return len(t.Tracks) },
func() fyne.CanvasObject { return NewTrackRow() },
func(itemID widget.ListItemID, item fyne.CanvasObject) {
tr := item.(*TrackRow)
tr.OnDoubleTapped = func() { t.onPlayTrackAt(itemID) }
tr.Update(t.tracks[itemID])
tr.Update(t.Tracks[itemID], itemID == t.nowPlayingIdx)
})
return t
}
func (t *Tracklist) SetNowPlaying(trackID string) {
t.nowPlayingIdx = -1
for i, tr := range t.Tracks {
if tr.ID == trackID {
t.nowPlayingIdx = i
break
}
}
t.list.Refresh()
}
func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(t.list)
}