feat(slint): virtualize the favorites tracks list
Drop the redundant "N tracks" / "N albums" toolbar count (the tab-menu badge is now the permanent counter) and split the content area: the Tracks tab renders in a virtualized, self-scrolling ListView + ListScrollbar (the PlaylistView pattern, now possible thanks to the fixed-chrome restructure), while Albums/Artists/Playlists/Labels keep a Flickable. Loading/error states center in the content area. Group headers + all per-row behavior are preserved inside the ListView items. cc
This commit is contained in:
1 file changed
+57
-61
@@ -32,6 +32,7 @@ import { QbzIcon } from "../primitives/QbzIcon.slint";
|
||||
import { LoadingSpinner } from "../primitives/LoadingSpinner.slint";
|
||||
import { ListScrollbar } from "../primitives/ListScrollbar.slint";
|
||||
import { NavButtons } from "../shell/NavButtons.slint";
|
||||
import { ListView } from "std-widgets.slint";
|
||||
|
||||
// One tab in the favorites tab menu.
|
||||
component FavTab inherits Rectangle {
|
||||
@@ -468,18 +469,6 @@ export component FavoritesView inherits Rectangle {
|
||||
if FavoritesState.active-tab == "tracks"
|
||||
&& FavoritesState.tracks.length > 0: HorizontalLayout {
|
||||
spacing: 8px;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Text {
|
||||
text: FavoritesState.tracks-visible.length
|
||||
+ (FavoritesState.tracks-search != ""
|
||||
? " / " + FavoritesState.tracks.length
|
||||
: "")
|
||||
+ " " + @tr("tracks");
|
||||
color: Theme.text-muted;
|
||||
font-size: Typography.legal;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
ExpandableSearch {
|
||||
@@ -521,18 +510,6 @@ export component FavoritesView inherits Rectangle {
|
||||
if FavoritesState.active-tab == "albums"
|
||||
&& FavoritesState.albums.length > 0: HorizontalLayout {
|
||||
spacing: 8px;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Text {
|
||||
text: FavoritesState.albums-shown
|
||||
+ (FavoritesState.albums-search != ""
|
||||
? " / " + FavoritesState.albums.length
|
||||
: "")
|
||||
+ " " + @tr("albums");
|
||||
color: Theme.text-muted;
|
||||
font-size: Typography.legal;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
ExpandableSearch {
|
||||
@@ -606,30 +583,19 @@ export component FavoritesView inherits Rectangle {
|
||||
vertical-stretch: 1;
|
||||
clip: true;
|
||||
|
||||
flick := Flickable {
|
||||
interactive: !DragState.active;
|
||||
viewport-width: self.width;
|
||||
viewport-height: page.preferred-height;
|
||||
|
||||
page := VerticalLayout {
|
||||
width: parent.width;
|
||||
padding-left: 32px;
|
||||
padding-right: 32px;
|
||||
padding-top: 16px;
|
||||
padding-bottom: 100px;
|
||||
spacing: 0px;
|
||||
alignment: start;
|
||||
|
||||
if FavoritesState.loading: HorizontalLayout {
|
||||
// Loading (any tab).
|
||||
if FavoritesState.loading: VerticalLayout {
|
||||
alignment: center;
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
LoadingSpinner { size: 36px; }
|
||||
}
|
||||
}
|
||||
|
||||
// Load error + retry.
|
||||
// Load error + retry (any tab).
|
||||
if !FavoritesState.loading && FavoritesState.load-error != "": VerticalLayout {
|
||||
alignment: center;
|
||||
spacing: 10px;
|
||||
Rectangle { height: 24px; }
|
||||
Text {
|
||||
text: @tr("Couldn't load favorites.");
|
||||
color: Theme.text-primary;
|
||||
@@ -669,9 +635,12 @@ export component FavoritesView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Tracks tab ---------------------------------------
|
||||
// --- Tracks tab — virtualized self-scrolling list --------------
|
||||
if !FavoritesState.loading && FavoritesState.load-error == ""
|
||||
&& FavoritesState.active-tab == "tracks": VerticalLayout {
|
||||
padding-left: 32px;
|
||||
padding-right: 32px;
|
||||
padding-top: 16px;
|
||||
spacing: 0px;
|
||||
|
||||
// Bulk action bar — visible in multi-select edit mode.
|
||||
@@ -696,17 +665,22 @@ export component FavoritesView inherits Rectangle {
|
||||
color: Theme.text-muted;
|
||||
font-size: Typography.body;
|
||||
}
|
||||
// Search filtered everything out.
|
||||
if FavoritesState.tracks.length > 0
|
||||
&& FavoritesState.tracks-visible.length == 0: Text {
|
||||
text: @tr("No tracks match your search.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Typography.body;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
vertical-stretch: 1;
|
||||
track-list := ListView {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
vertical-scrollbar-policy: ScrollBarPolicy.always-off;
|
||||
for track[i] in FavoritesState.tracks-visible: VerticalLayout {
|
||||
spacing: 0px;
|
||||
// Group header rows when grouping by album / artist
|
||||
// (a new header each time the group key changes).
|
||||
// Group header rows when grouping by album / artist.
|
||||
if FavoritesState.tracks-group-mode == "album" && track.album != ""
|
||||
&& (i == 0 || FavoritesState.tracks-visible[i - 1].album != track.album): Rectangle {
|
||||
height: 32px;
|
||||
@@ -758,10 +732,36 @@ export component FavoritesView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
ListScrollbar {
|
||||
x: parent.width - self.width - 4px;
|
||||
width: 14px;
|
||||
height: 100%;
|
||||
viewport-height: track-list.viewport-height;
|
||||
visible-height: track-list.visible-height;
|
||||
viewport-y <=> track-list.viewport-y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Albums tab ---------------------------------------
|
||||
// --- Albums / Artists / Playlists / Labels — scrolling ---------
|
||||
if !FavoritesState.loading && FavoritesState.load-error == ""
|
||||
&& FavoritesState.active-tab == "albums": VerticalLayout {
|
||||
&& FavoritesState.active-tab != "tracks": Rectangle {
|
||||
other-flick := Flickable {
|
||||
interactive: !DragState.active;
|
||||
viewport-width: self.width;
|
||||
viewport-height: other-page.preferred-height;
|
||||
|
||||
other-page := VerticalLayout {
|
||||
width: parent.width;
|
||||
padding-left: 32px;
|
||||
padding-right: 32px;
|
||||
padding-top: 16px;
|
||||
padding-bottom: 100px;
|
||||
spacing: 0px;
|
||||
alignment: start;
|
||||
|
||||
// --- Albums tab ---
|
||||
if FavoritesState.active-tab == "albums": VerticalLayout {
|
||||
spacing: 0px;
|
||||
if FavoritesState.albums.length == 0: Text {
|
||||
text: @tr("No favorite albums yet.");
|
||||
@@ -796,9 +796,8 @@ export component FavoritesView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Artists tab --------------------------------------
|
||||
if !FavoritesState.loading && FavoritesState.load-error == ""
|
||||
&& FavoritesState.active-tab == "artists": artists-grid := Rectangle {
|
||||
// --- Artists tab ---
|
||||
if FavoritesState.active-tab == "artists": artists-grid := Rectangle {
|
||||
property <int> columns: Math.max(
|
||||
1,
|
||||
Math.floor((self.width + root.gap) / (root.artist-w + root.gap)));
|
||||
@@ -819,9 +818,8 @@ export component FavoritesView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Playlists tab ------------------------------------
|
||||
if !FavoritesState.loading && FavoritesState.load-error == ""
|
||||
&& FavoritesState.active-tab == "playlists": playlists-grid := Rectangle {
|
||||
// --- Playlists tab ---
|
||||
if FavoritesState.active-tab == "playlists": playlists-grid := Rectangle {
|
||||
property <length> pl-w: 180px;
|
||||
property <length> pl-h: 234px;
|
||||
property <int> columns: Math.max(
|
||||
@@ -844,9 +842,8 @@ export component FavoritesView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Labels tab ---------------------------------------
|
||||
if !FavoritesState.loading && FavoritesState.load-error == ""
|
||||
&& FavoritesState.active-tab == "labels": VerticalLayout {
|
||||
// --- Labels tab ---
|
||||
if FavoritesState.active-tab == "labels": VerticalLayout {
|
||||
spacing: 0px;
|
||||
if FavoritesState.labels.length == 0: Text {
|
||||
text: @tr("No favorite labels yet.");
|
||||
@@ -861,15 +858,14 @@ export component FavoritesView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scrollbar in the right gutter of the content area.
|
||||
ListScrollbar {
|
||||
x: parent.width - self.width - 4px;
|
||||
width: 14px;
|
||||
height: 100%;
|
||||
viewport-height: flick.viewport-height;
|
||||
visible-height: flick.height;
|
||||
viewport-y <=> flick.viewport-y;
|
||||
viewport-height: other-flick.viewport-height;
|
||||
visible-height: other-flick.height;
|
||||
viewport-y <=> other-flick.viewport-y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user