Covers and card elements now scale with the viewport instead of the library: the shared AlbumGrid gains opt-in windowing (row band = visible rows +/- one viewport, computed in .slint, row-granular change events), cards outside the band render as same-footprint placeholders (scroll geometry unchanged), and the Rust side dispatches artwork only for the band, evicting covers outside a retention span back to the placeholder. - New id-keyed ArtworkTarget::LocalAlbumById (replaces the index-keyed LocalAlbumCard): immune to derive re-sorts between dispatch and apply; reloads still drop stale covers via the generation guard. The enum loses Copy (String variant). - In-flight dedupe set freed on apply AND on fetch failure, cleared on generation bumps. - Flat list view and grouped mode keep the pre-windowing full dispatch (they don't fire window events); switching grid->list re-dispatches covers the window may have evicted. - Windowing is off by default in the shared grid: Discover, Labels and Favorites are untouched (phase 2). A 2,000-album library drops from ~540 MB of resident cover RGBA to a viewport-sized working set, and scrolling repaints ~40 mounted cards instead of the whole collection. cc
249 lines
11 KiB
Plaintext
249 lines
11 KiB
Plaintext
// Album collection content — renders a flat grid, a flat list, or
|
|
// group-by sections (each a title + grid). The surrounding view owns the
|
|
// toolbar and the loading / empty / load-more states; this component is
|
|
// purely the rendered collection, so the grid column math and the list
|
|
// header+rows live in one place. Shared by Discover Browse, Label
|
|
// Releases, and Favorites albums.
|
|
|
|
import { Theme } from "../foundation/semantic-colors.slint";
|
|
import { Typography } from "../foundation/typography.slint";
|
|
import { AlbumCardItem, DiscoverSection } from "../state.slint";
|
|
import { AlbumCard } from "AlbumCard.slint";
|
|
import { AlbumListRow, AlbumListHeader } from "../primitives/AlbumListRow.slint";
|
|
|
|
// Wrapping album grid over a model — column math in one place, shared by
|
|
// the flat grid and each group-by section.
|
|
component AlbumGrid inherits Rectangle {
|
|
in property <[AlbumCardItem]> albums;
|
|
in property <length> card-width: 200px;
|
|
in property <length> card-height: 246px;
|
|
in property <length> card-gap: 24px;
|
|
in property <bool> show-favorite: true;
|
|
in property <bool> show-source-badge: false;
|
|
in property <bool> select-mode: false;
|
|
// --- Viewport windowing (opt-in; default OFF = identical to before) ---
|
|
// With `windowed` on, only cards within ~one viewport of the visible band
|
|
// mount a real AlbumCard; the rest are same-footprint placeholders, so
|
|
// the height formula below (the scroll geometry) never changes.
|
|
// `visible-top`/`visible-height` arrive in the surrounding Flickable's
|
|
// CONTENT coordinates; `content-offset` is this grid's approximate y
|
|
// inside that content — small errors are absorbed by the margin.
|
|
in property <bool> windowed: false;
|
|
in property <length> visible-top: 0px;
|
|
in property <length> visible-height: 0px;
|
|
in property <length> content-offset: 0px;
|
|
callback open-album(string);
|
|
callback open-artist(string);
|
|
callback media-action(string, string, string);
|
|
// Fired (windowed only) when the row band changes — [first, last] item
|
|
// indices, prefetch margin included. The consumer dispatches artwork.
|
|
callback window-changed(int /* first index */, int /* last index */);
|
|
|
|
property <int> columns: Math.max(
|
|
1,
|
|
Math.floor((self.width + root.card-gap) / (root.card-width + root.card-gap)));
|
|
property <int> rows: Math.ceil(root.albums.length / self.columns);
|
|
height: self.rows > 0
|
|
? self.rows * root.card-height + Math.max(0, self.rows - 1) * root.card-gap
|
|
: 0px;
|
|
|
|
// Row band = visible rows ± one full viewport. Row-granular ints, so the
|
|
// `changed` handlers only fire when a row boundary is crossed (~every
|
|
// 270px of scroll), not per scrolled pixel.
|
|
property <length> row-stride: root.card-height + root.card-gap;
|
|
property <length> local-top: root.visible-top - root.content-offset;
|
|
property <int> first-window-row: root.windowed
|
|
? Math.max(0, Math.floor((root.local-top - root.visible-height) / root.row-stride))
|
|
: 0;
|
|
property <int> last-window-row: root.windowed
|
|
? Math.max(0, Math.floor((root.local-top + 2 * root.visible-height) / root.row-stride))
|
|
: 0;
|
|
changed first-window-row => { root.notify-window(); }
|
|
changed last-window-row => { root.notify-window(); }
|
|
// Column count changes on first layout and on window resize — the band's
|
|
// ITEM indices depend on it, so re-notify.
|
|
changed columns => { root.notify-window(); }
|
|
init => { root.notify-window(); }
|
|
function notify-window() {
|
|
if (root.windowed) {
|
|
root.window-changed(
|
|
root.first-window-row * root.columns,
|
|
(root.last-window-row + 1) * root.columns - 1);
|
|
}
|
|
}
|
|
|
|
for album[i] in root.albums: card-slot := Rectangle {
|
|
x: Math.mod(i, root.columns) * (root.card-width + root.card-gap);
|
|
y: Math.floor(i / root.columns) * (root.card-height + root.card-gap);
|
|
width: root.card-width;
|
|
height: root.card-height;
|
|
property <bool> in-window: !root.windowed
|
|
|| (Math.floor(i / root.columns) >= root.first-window-row
|
|
&& Math.floor(i / root.columns) <= root.last-window-row);
|
|
// Placeholder tile while the real card is unmounted (fast scroll).
|
|
border-radius: 8px;
|
|
background: card-slot.in-window ? transparent : Theme.surface-elevated;
|
|
if card-slot.in-window: AlbumCard {
|
|
width: root.card-width;
|
|
height: root.card-height;
|
|
album: album;
|
|
show-favorite: root.show-favorite;
|
|
show-source-badge: root.show-source-badge;
|
|
select-mode: root.select-mode;
|
|
clicked(id) => {
|
|
root.open-album(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
if (kind == "artist") {
|
|
root.open-artist(id);
|
|
} else {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export component AlbumCollectionView inherits VerticalLayout {
|
|
in property <[AlbumCardItem]> albums; // flat set (grid/list)
|
|
in property <[DiscoverSection]> grouped; // group-by sections
|
|
in property <bool> is-grouped: false;
|
|
in property <string> view-mode: "grid"; // "grid" | "list"
|
|
in property <bool> show-source: false;
|
|
// Forwarded to AlbumCard — hide the favorite heart in non-favoritable
|
|
// contexts (Local Library albums).
|
|
in property <bool> show-favorite: true;
|
|
// Forwarded to AlbumCard — show the always-visible source badge on the
|
|
// grid card art (Local Library: local | qobuz-offline | plex).
|
|
in property <bool> show-source-badge: false;
|
|
// Forwarded to AlbumCard / AlbumListRow — checkbox + toggle-on-click
|
|
// (Local Library albums multi-select). Default false everywhere else.
|
|
in property <bool> select-mode: false;
|
|
in property <length> card-width: 200px;
|
|
in property <length> card-height: 246px;
|
|
in property <length> card-gap: 24px;
|
|
in property <length> list-row-gap: 4px;
|
|
// Viewport windowing — forwarded to the FLAT grid only (grouped sections
|
|
// keep full mounts; their per-section offsets are unknown here). OFF by
|
|
// default so Discover Browse / Labels / Favorites are untouched.
|
|
in property <bool> windowed: false;
|
|
in property <length> visible-top: 0px;
|
|
in property <length> visible-height: 0px;
|
|
in property <length> content-offset: 0px;
|
|
callback window-changed(int /* first index */, int /* last index */);
|
|
callback open-album(string);
|
|
callback open-artist(string);
|
|
callback media-action(string, string, string);
|
|
|
|
spacing: 0px;
|
|
|
|
// --- Grouped (sections) — each section follows the grid/list mode --
|
|
if root.is-grouped && root.grouped.length > 0: VerticalLayout {
|
|
spacing: 0px;
|
|
// In list mode the column header sits once above all sections.
|
|
if root.view-mode == "list": AlbumListHeader {
|
|
show-source: root.show-source;
|
|
}
|
|
for section[s] in root.grouped: VerticalLayout {
|
|
spacing: 12px;
|
|
if s > 0: Rectangle { height: 24px; }
|
|
Text {
|
|
text: section.title;
|
|
color: Theme.text-primary;
|
|
font-size: Typography.heading;
|
|
font-weight: Typography.semibold;
|
|
}
|
|
// List view: rows for this section.
|
|
if root.view-mode == "list": VerticalLayout {
|
|
spacing: root.list-row-gap;
|
|
for album[i] in section.albums: AlbumListRow {
|
|
album: album;
|
|
index: i;
|
|
show-source: root.show-source;
|
|
select-mode: root.select-mode;
|
|
clicked(id) => {
|
|
root.open-album(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
if (kind == "artist") {
|
|
root.open-artist(id);
|
|
} else {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Grid view: a card grid for this section.
|
|
if root.view-mode != "list": AlbumGrid {
|
|
albums: section.albums;
|
|
show-favorite: root.show-favorite;
|
|
show-source-badge: root.show-source-badge;
|
|
select-mode: root.select-mode;
|
|
card-width: root.card-width;
|
|
card-height: root.card-height;
|
|
card-gap: root.card-gap;
|
|
open-album(id) => {
|
|
root.open-album(id);
|
|
}
|
|
open-artist(id) => {
|
|
root.open-artist(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- Flat grid -----------------------------------------------------
|
|
if !root.is-grouped && root.view-mode == "grid" && root.albums.length > 0: AlbumGrid {
|
|
albums: root.albums;
|
|
show-favorite: root.show-favorite;
|
|
show-source-badge: root.show-source-badge;
|
|
select-mode: root.select-mode;
|
|
card-width: root.card-width;
|
|
card-height: root.card-height;
|
|
card-gap: root.card-gap;
|
|
windowed: root.windowed;
|
|
visible-top: root.visible-top;
|
|
visible-height: root.visible-height;
|
|
content-offset: root.content-offset;
|
|
window-changed(first, last) => {
|
|
root.window-changed(first, last);
|
|
}
|
|
open-album(id) => {
|
|
root.open-album(id);
|
|
}
|
|
open-artist(id) => {
|
|
root.open-artist(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
|
|
// --- Flat list -----------------------------------------------------
|
|
if !root.is-grouped && root.view-mode == "list" && root.albums.length > 0: VerticalLayout {
|
|
spacing: root.list-row-gap;
|
|
AlbumListHeader {
|
|
show-source: root.show-source;
|
|
}
|
|
for album[i] in root.albums: AlbumListRow {
|
|
album: album;
|
|
index: i;
|
|
show-source: root.show-source;
|
|
select-mode: root.select-mode;
|
|
clicked(id) => {
|
|
root.open-album(id);
|
|
}
|
|
media-action(kind, id, action) => {
|
|
if (kind == "artist") {
|
|
root.open-artist(id);
|
|
} else {
|
|
root.media-action(kind, id, action);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|