optimize tracklist rendering
This commit is contained in:
@@ -410,6 +410,17 @@ func (t *tracklistRowBase) TrackID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int, onUpdate func()) {
|
func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int, onUpdate func()) {
|
||||||
|
// Show only columns configured to be visible
|
||||||
|
for i := 2; i < len(t.tracklist.columns); i++ {
|
||||||
|
t.setColVisibility(i, !t.tracklist.visibleColumns[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ealy return if nothing else needs updating
|
||||||
|
if !t.needsUpdate(tm, rowNum) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Throttle updates when many are happening in a short time
|
||||||
if tracklistUpdateCounter.NumEventsSince(time.Now().Add(-300*time.Millisecond)) > 10 {
|
if tracklistUpdateCounter.NumEventsSince(time.Now().Add(-300*time.Millisecond)) > 10 {
|
||||||
t.doUpdate(&emptyTrack, 1)
|
t.doUpdate(&emptyTrack, 1)
|
||||||
if t.nextUpdateModel == nil {
|
if t.nextUpdateModel == nil {
|
||||||
@@ -434,6 +445,26 @@ func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int, onUpdate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *tracklistRowBase) needsUpdate(tm *util.TrackListModel, rowNum int) bool {
|
||||||
|
tr := tm.Track()
|
||||||
|
if tm.Selected != t.Selected {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if t.trackID != tr.ID || t.trackNum != rowNum {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if t.playCount != tr.PlayCount || t.isFavorite != tr.Favorite || t.rating.Rating != tr.Rating {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if t.rating.IsDisabled != t.tracklist.Options.DisableRating {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if isPlaying := t.tracklist.nowPlayingID == tr.ID; isPlaying != t.isPlaying {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
|
func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
|
||||||
changed := false
|
changed := false
|
||||||
if tm.Selected != t.Selected {
|
if tm.Selected != t.Selected {
|
||||||
@@ -535,13 +566,6 @@ func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
|
|||||||
t.rating.Refresh()
|
t.rating.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show only columns configured to be visible
|
|
||||||
for i := 2; i < len(t.tracklist.columns); i++ {
|
|
||||||
if ch := t.setColVisibility(i, !t.tracklist.visibleColumns[i]); ch {
|
|
||||||
changed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
tracklistUpdateCounter.Add()
|
tracklistUpdateCounter.Add()
|
||||||
t.Refresh()
|
t.Refresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user