Skip to content

Commit

Permalink
use larger playing icon for expanded tracklist rows and fix positioni…
Browse files Browse the repository at this point in the history
…ng bug when replacing back with track number
  • Loading branch information
dweymouth committed May 31, 2024
1 parent 41af03c commit 5f8a25b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 12 additions & 5 deletions ui/widgets/tracklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/dweymouth/supersonic/ui/util"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
Expand Down Expand Up @@ -100,15 +101,25 @@ type Tracklist struct {
}

func NewTracklist(tracks []*mediaprovider.Track, im *backend.ImageManager, useCompactRows bool) *Tracklist {
playIcon := theme.NewThemedResource(theme.MediaPlayIcon())
playIcon.ColorName = theme.ColorNamePrimary

t := &Tracklist{compactRows: useCompactRows}
t.ExtendBaseWidget(t)
t.columns = ExpandedTracklistRowColumns
colWidths := ExpandedTracklistRowColumnWidths
var playingIcon fyne.CanvasObject
if useCompactRows {
t.columns = CompactTracklistRowColumns
colWidths = CompactTracklistRowColumnWidths
playingIcon = container.NewCenter(container.NewHBox(util.NewHSpace(2), widget.NewIcon(playIcon)))
} else {
playIconImg := canvas.NewImageFromResource(playIcon)
playIconImg.FillMode = canvas.ImageFillContain
playIconImg.SetMinSize(fyne.NewSquareSize(theme.IconInlineSize() * 1.5))
playingIcon = container.NewCenter(playIconImg)
}
t.visibleColumns = make([]bool, len(t.columns))
t.ExtendBaseWidget(t)

if len(tracks) > 0 {
t._setTracks(tracks)
Expand All @@ -125,10 +136,6 @@ func NewTracklist(tracks []*mediaprovider.Track, im *backend.ImageManager, useCo
}
}

playIcon := theme.NewThemedResource(theme.MediaPlayIcon())
playIcon.ColorName = theme.ColorNamePrimary
playingIcon := container.NewCenter(container.NewHBox(util.NewHSpace(2), widget.NewIcon(playIcon)))

t.list = NewFocusList(
t.lenTracks,
func() fyne.CanvasObject {
Expand Down
8 changes: 7 additions & 1 deletion ui/widgets/tracklistrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ type tracklistRowBase struct {
// set by extending widget
playingIcon fyne.CanvasObject

// when replacing the content of col 0 with playing icon,
// the original content is saved here for resetting
originalNumColContent fyne.CanvasObject

// internal state
tracklist *Tracklist
trackNum int
Expand All @@ -108,6 +112,7 @@ type tracklistRowBase struct {
size *widget.Label
path *widget.Label

// must be injected by extending widget
setColVisibility func(int, bool) bool
}

Expand Down Expand Up @@ -303,9 +308,10 @@ func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int) {
t.name.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying

if isPlaying {
t.originalNumColContent = t.Content.(*fyne.Container).Objects[0]
t.Content.(*fyne.Container).Objects[0] = t.playingIcon
} else {
t.Content.(*fyne.Container).Objects[0] = t.num
t.Content.(*fyne.Container).Objects[0] = t.originalNumColContent
}
changed = true
}
Expand Down

0 comments on commit 5f8a25b

Please sign in to comment.