feat(discover): polish Qobuz Playlists cards with contain covers and category filter
Single-cover Discover playlist cards now letterbox the cover with image-fit: contain over its dominant colour (computed host-side from the decoded cover), matching Tauri, and show the first tag as an accent category subtag. Add a multi-select category filter dropdown (sm toolbar variant, no pills per ADR-008) that re-filters the cached playlists row client-side; an empty selection shows everything. Raise the playlists cap from 18 to 100 so the filter operates on a full set. cc
This commit is contained in:
9 files changed
+561
-27
No files matched your search
@@ -702,6 +702,11 @@ fn apply_artwork(
|
||||
let model = home.get_playlists();
|
||||
if let Some(mut item) = model.row_data(idx) {
|
||||
item.cover1 = image; // single cover → slot 0
|
||||
// Single-cover Discover cards letterbox a contain-fit cover with
|
||||
// its dominant colour (1:1 with Tauri's PlaylistCardLite). The
|
||||
// decoded pixels are in hand here, so compute it once on apply.
|
||||
item.dominant_color =
|
||||
crate::immersive::dominant_cover_color(pixels, width, height);
|
||||
model.set_row_data(idx, item);
|
||||
}
|
||||
}
|
||||
|
||||
+180
-13
@@ -18,8 +18,8 @@ use slint::{ComponentHandle, ModelRc, SharedString, VecModel};
|
||||
|
||||
use crate::artwork::{ArtworkJob, ArtworkTarget};
|
||||
use crate::{
|
||||
AlbumCardItem, AppWindow, DiscoverSection, DiscoverState, HomeState, SearchPlaylistItem,
|
||||
SectionDescriptor, SlimItem,
|
||||
AlbumCardItem, AppWindow, DiscoverSection, DiscoverState, HomeState, PlaylistTagItem,
|
||||
SearchPlaylistItem, SectionDescriptor, SlimItem,
|
||||
};
|
||||
|
||||
/// Plain, `Send` home data produced on the worker thread.
|
||||
@@ -34,6 +34,9 @@ pub struct HomeData {
|
||||
pub playlists: Vec<PlaylistCardData>,
|
||||
/// Qobuz playlists row — editorPicks tab (same data, separate cache slot).
|
||||
pub editor_playlists: Vec<PlaylistCardData>,
|
||||
/// Category tags for the Qobuz Playlists multi-select filter: (slug,
|
||||
/// localized name). Empty when the index carries no `playlists_tags`.
|
||||
pub playlist_tags: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
@@ -49,6 +52,24 @@ struct TabSections {
|
||||
editor: Vec<SectionData>,
|
||||
home_playlists: Vec<PlaylistCardData>,
|
||||
editor_playlists: Vec<PlaylistCardData>,
|
||||
/// Slugs of the currently-selected category tags (Qobuz Playlists filter).
|
||||
/// Empty = show all. Client-side; survives a tab switch.
|
||||
selected_tags: Vec<String>,
|
||||
}
|
||||
|
||||
/// Keep only the playlists whose tag slugs intersect `selected` (union of the
|
||||
/// selected tags). An empty selection passes everything through.
|
||||
fn filter_playlists<'a>(
|
||||
playlists: &'a [PlaylistCardData],
|
||||
selected: &[String],
|
||||
) -> Vec<&'a PlaylistCardData> {
|
||||
if selected.is_empty() {
|
||||
return playlists.iter().collect();
|
||||
}
|
||||
playlists
|
||||
.iter()
|
||||
.filter(|p| p.tags.iter().any(|slug| selected.iter().any(|s| s == slug)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -101,6 +122,11 @@ pub struct PlaylistCardData {
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
pub artwork_url: String, // rectangle || covers[0] || ""
|
||||
/// First tag's localized name — the UPPERCASE accent subtag on the card
|
||||
/// ("" = the playlist carries no tags).
|
||||
pub category: String,
|
||||
/// All tag slugs — the material for the client-side category filter (C).
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
/// A compact ranked item for the slim grid sections.
|
||||
@@ -241,15 +267,28 @@ where
|
||||
.collect();
|
||||
|
||||
// Qobuz Playlists row — both the Home and Editor's Picks tabs draw from
|
||||
// the SAME `containers.playlists` (one fetch); capped at 18 (Tauri's
|
||||
// fetchDiscoverIndex(18, …)). Re-filtering on genre change is free:
|
||||
// reload_home re-fetches the index, so no extra plumbing is needed.
|
||||
// the SAME `containers.playlists` (one fetch). Capped at 100 (raised from
|
||||
// Tauri's 18) so the client-side category filter has material to work with;
|
||||
// the carousel still pages, and the un-filtered view shows the same first
|
||||
// cards. Each card carries its tag slugs for the filter.
|
||||
let playlist_items: Vec<DiscoverPlaylist> =
|
||||
containers.playlists.map(|c| c.data.items).unwrap_or_default();
|
||||
let editor_playlists: Vec<PlaylistCardData> =
|
||||
playlist_items.iter().cloned().take(18).map(map_playlist).collect();
|
||||
playlist_items.iter().cloned().take(100).map(map_playlist).collect();
|
||||
let playlists: Vec<PlaylistCardData> =
|
||||
playlist_items.into_iter().take(18).map(map_playlist).collect();
|
||||
playlist_items.into_iter().take(100).map(map_playlist).collect();
|
||||
|
||||
// Category tags for the multi-select filter (slug + localized name).
|
||||
let playlist_tags: Vec<(String, String)> = containers
|
||||
.playlists_tags
|
||||
.map(|c| {
|
||||
c.data
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|tag| (tag.slug, tag.name))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(HomeData {
|
||||
sections,
|
||||
@@ -259,6 +298,7 @@ where
|
||||
recent_albums,
|
||||
playlists,
|
||||
editor_playlists,
|
||||
playlist_tags,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -378,10 +418,28 @@ fn map_playlist(p: DiscoverPlaylist) -> PlaylistCardData {
|
||||
.rectangle
|
||||
.or_else(|| p.image.covers.and_then(|c| c.into_iter().next()))
|
||||
.unwrap_or_default();
|
||||
// First tag → the UPPERCASE accent subtag; all tag slugs → the filter
|
||||
// material. DiscoverPlaylist.tags is Option<Vec<PlaylistTag{id,slug,name}>>.
|
||||
// Uppercased here (Slint has no text-transform; same convention as the
|
||||
// MIXTAPE/COLLECTION eyebrow tags). The name is already localized by the
|
||||
// API response.
|
||||
let category = p
|
||||
.tags
|
||||
.as_ref()
|
||||
.and_then(|t| t.first())
|
||||
.map(|t| t.name.to_uppercase())
|
||||
.unwrap_or_default();
|
||||
let tags = p
|
||||
.tags
|
||||
.as_ref()
|
||||
.map(|t| t.iter().map(|tag| tag.slug.clone()).collect())
|
||||
.unwrap_or_default();
|
||||
PlaylistCardData {
|
||||
id: p.id.to_string(),
|
||||
title: p.name,
|
||||
artwork_url,
|
||||
category,
|
||||
tags,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,6 +596,11 @@ pub(crate) fn playlist_to_item(p: &PlaylistCardData) -> SearchPlaylistItem {
|
||||
cover2: slint::Image::default(),
|
||||
cover3: slint::Image::default(),
|
||||
cover4: slint::Image::default(),
|
||||
category: p.category.clone().into(),
|
||||
// Neutral dark letterbox until the cover decodes and the artwork
|
||||
// pipeline writes the real dominant colour (mirrors immersive::
|
||||
// dominant_cover_color's own fallback).
|
||||
dominant_color: slint::Color::from_rgb_u8(30, 30, 34),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -720,8 +783,10 @@ pub fn rerender_active_tab(window: &AppWindow, prefs: &DiscoverPrefs) -> Vec<Art
|
||||
dstate.set_home_sections(ModelRc::new(VecModel::from(home)));
|
||||
dstate.set_editor_sections(ModelRc::new(VecModel::from(editor_list)));
|
||||
|
||||
// Re-push the active tab's Qobuz Playlists row + build the album-section
|
||||
// artwork jobs from the same cached data (one borrow of the cache).
|
||||
// Re-push the active tab's Qobuz Playlists row (category-filtered) + build
|
||||
// the album-section artwork jobs from the same cached data (one borrow of
|
||||
// the cache). The playlist artwork jobs are built from the SAME filtered
|
||||
// slice, so their `idx` aligns with the pushed (filtered) row.
|
||||
let hstate = window.global::<HomeState>();
|
||||
let (pls, jobs) = TAB_SECTIONS.with(|cell| {
|
||||
let cache = cell.borrow();
|
||||
@@ -730,15 +795,102 @@ pub fn rerender_active_tab(window: &AppWindow, prefs: &DiscoverPrefs) -> Vec<Art
|
||||
} else {
|
||||
(&cache.home, &cache.home_playlists)
|
||||
};
|
||||
let filtered: Vec<PlaylistCardData> = filter_playlists(pls, &cache.selected_tags)
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
let mut jobs = discover_section_artwork_jobs(&active_list, album_cache, editor);
|
||||
jobs.extend(playlist_artwork_jobs(pls));
|
||||
(pls.iter().map(playlist_to_item).collect::<Vec<_>>(), jobs)
|
||||
jobs.extend(playlist_artwork_jobs(&filtered));
|
||||
(
|
||||
filtered.iter().map(playlist_to_item).collect::<Vec<_>>(),
|
||||
jobs,
|
||||
)
|
||||
});
|
||||
hstate.set_playlists(ModelRc::new(VecModel::from(pls)));
|
||||
|
||||
jobs
|
||||
}
|
||||
|
||||
/// Re-push the active tab's Qobuz Playlists row filtered by `selected_tags`,
|
||||
/// and return the artwork jobs for the (filtered) row. Shared by the toggle /
|
||||
/// clear callbacks: the selection is already updated in the cache. For You has
|
||||
/// no playlists row, so it returns no jobs.
|
||||
fn rerender_playlists_filtered(window: &AppWindow) -> Vec<ArtworkJob> {
|
||||
let active = window.global::<DiscoverState>().get_active_tab().to_string();
|
||||
if active == "forYou" {
|
||||
return Vec::new();
|
||||
}
|
||||
let editor = active == "editorPicks";
|
||||
let hstate = window.global::<HomeState>();
|
||||
let (pls, jobs) = TAB_SECTIONS.with(|cell| {
|
||||
let cache = cell.borrow();
|
||||
let source = if editor {
|
||||
&cache.editor_playlists
|
||||
} else {
|
||||
&cache.home_playlists
|
||||
};
|
||||
let filtered: Vec<PlaylistCardData> = filter_playlists(source, &cache.selected_tags)
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
let jobs = playlist_artwork_jobs(&filtered);
|
||||
(
|
||||
filtered.iter().map(playlist_to_item).collect::<Vec<_>>(),
|
||||
jobs,
|
||||
)
|
||||
});
|
||||
hstate.set_playlists(ModelRc::new(VecModel::from(pls)));
|
||||
jobs
|
||||
}
|
||||
|
||||
/// Toggle one category tag (by slug) in the Qobuz Playlists filter, re-filter
|
||||
/// the cached row, and return the artwork jobs for the new (filtered) row. Also
|
||||
/// updates the `playlist-tags[i].selected` flags + `playlist-tag-count` so the
|
||||
/// dropdown reflects the selection.
|
||||
pub fn toggle_playlist_tag(window: &AppWindow, slug: &str) -> Vec<ArtworkJob> {
|
||||
let count = TAB_SECTIONS.with(|cell| {
|
||||
let mut cache = cell.borrow_mut();
|
||||
if let Some(pos) = cache.selected_tags.iter().position(|s| s == slug) {
|
||||
cache.selected_tags.remove(pos);
|
||||
} else {
|
||||
cache.selected_tags.push(slug.to_string());
|
||||
}
|
||||
cache.selected_tags.len() as i32
|
||||
});
|
||||
sync_tag_selection(window, count);
|
||||
rerender_playlists_filtered(window)
|
||||
}
|
||||
|
||||
/// Clear every selected category tag (show all playlists). Returns the artwork
|
||||
/// jobs for the now-unfiltered row.
|
||||
pub fn clear_playlist_tags(window: &AppWindow) -> Vec<ArtworkJob> {
|
||||
TAB_SECTIONS.with(|cell| cell.borrow_mut().selected_tags.clear());
|
||||
sync_tag_selection(window, 0);
|
||||
rerender_playlists_filtered(window)
|
||||
}
|
||||
|
||||
/// Mirror the cached selection onto `HomeState.playlist-tags[i].selected` and
|
||||
/// publish the selected count. Reads the selection from the cache so the two
|
||||
/// never drift.
|
||||
fn sync_tag_selection(window: &AppWindow, count: i32) {
|
||||
use slint::Model;
|
||||
// Snapshot the selection so the cache borrow is released before any Slint
|
||||
// model mutation (which can synchronously re-enter Rust closures).
|
||||
let selected: Vec<String> =
|
||||
TAB_SECTIONS.with(|cell| cell.borrow().selected_tags.clone());
|
||||
let model = window.global::<HomeState>().get_playlist_tags();
|
||||
for i in 0..model.row_count() {
|
||||
if let Some(mut item) = model.row_data(i) {
|
||||
let is_sel = selected.iter().any(|s| s.as_str() == item.slug.as_str());
|
||||
if item.selected != is_sel {
|
||||
item.selected = is_sel;
|
||||
model.set_row_data(i, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
window.global::<HomeState>().set_playlist_tag_count(count);
|
||||
}
|
||||
|
||||
/// Switch the visible Discover tab ("home" | "editorPicks" | "forYou"). Writes
|
||||
/// the active tab into BOTH HomeState (Slice-3 pill bindings) and DiscoverState
|
||||
/// (the prefs-driven render loop + the configurator target — single source of
|
||||
@@ -769,13 +921,15 @@ pub fn apply_home(window: &AppWindow, data: HomeData) {
|
||||
let sections: Vec<DiscoverSection> = build_sections(&data.sections);
|
||||
|
||||
// Cache the Home + Editor's Picks section sets for instant tab
|
||||
// switching (For You has its own dedicated state/view).
|
||||
// switching (For You has its own dedicated state/view). A fresh index
|
||||
// load resets the category-tag selection (the tag set may have changed).
|
||||
TAB_SECTIONS.with(|cell| {
|
||||
*cell.borrow_mut() = TabSections {
|
||||
home: data.sections.clone(),
|
||||
editor: data.editor_sections.clone(),
|
||||
home_playlists: data.playlists.clone(),
|
||||
editor_playlists: data.editor_playlists.clone(),
|
||||
selected_tags: Vec::new(),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -799,9 +953,20 @@ pub fn apply_home(window: &AppWindow, data: HomeData) {
|
||||
data.recent_albums.into_iter().map(card_to_item).collect();
|
||||
|
||||
// Push the HOME tab's Qobuz Playlists row (apply_home runs for the
|
||||
// default Home tab; a tab switch swaps it via select_tab).
|
||||
// default Home tab; a tab switch swaps it via select_tab). The selection
|
||||
// was just reset, so the unfiltered full set is shown.
|
||||
let home_playlists: Vec<SearchPlaylistItem> =
|
||||
data.playlists.iter().map(playlist_to_item).collect();
|
||||
// Category tags for the multi-select filter — all start unselected.
|
||||
let tag_items: Vec<PlaylistTagItem> = data
|
||||
.playlist_tags
|
||||
.iter()
|
||||
.map(|(slug, name)| PlaylistTagItem {
|
||||
slug: slug.clone().into(),
|
||||
name: name.clone().into(),
|
||||
selected: false,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let state = window.global::<HomeState>();
|
||||
state.set_sections(ModelRc::new(VecModel::from(sections)));
|
||||
@@ -809,6 +974,8 @@ pub fn apply_home(window: &AppWindow, data: HomeData) {
|
||||
state.set_recent(ModelRc::new(VecModel::from(recent)));
|
||||
state.set_recent_albums(ModelRc::new(VecModel::from(recent_albums)));
|
||||
state.set_playlists(ModelRc::new(VecModel::from(home_playlists)));
|
||||
state.set_playlist_tags(ModelRc::new(VecModel::from(tag_items)));
|
||||
state.set_playlist_tag_count(0);
|
||||
|
||||
// Push the prefs-driven descriptor lists now that the section cache is
|
||||
// populated, so the Home/Editor render loop reflects the fresh data (the
|
||||
|
||||
@@ -145,6 +145,67 @@ pub fn spectrum_colors(pixels: &[u8], width: u32, height: u32) -> (Color, Color)
|
||||
)
|
||||
}
|
||||
|
||||
/// Dominant swatch of a cover, for the single-cover playlist card letterbox.
|
||||
///
|
||||
/// Mirrors Tauri's `extractPalette().dominant`: the card uses `image-fit:
|
||||
/// contain`, so the gaps around a non-square cover are filled with the cover's
|
||||
/// most-abundant colour instead of theme grey. We downscale to 16x16, bin the
|
||||
/// pixels by quantised colour (one vote per pixel = coverage, NOT saturation),
|
||||
/// and average the winning bin's actual pixels back to an opaque swatch — so a
|
||||
/// dark/metallic cover resolves to the muted tone you actually see, not an
|
||||
/// amplified speck of an unseen highlight. Transparent pixels are skipped; an
|
||||
/// effectively-empty cover falls back to a neutral dark surface.
|
||||
pub fn dominant_cover_color(pixels: &[u8], width: u32, height: u32) -> Color {
|
||||
// Neutral dark fallback (close to Tauri's `--bg-tertiary`), used when the
|
||||
// buffer is unusable or carries no opaque pixels.
|
||||
let fallback = Color::from_rgb_u8(30, 30, 34);
|
||||
let Some(src) = RgbaImage::from_raw(width, height, pixels.to_vec()) else {
|
||||
return fallback;
|
||||
};
|
||||
let tiny = imageops::resize(&src, 16, 16, imageops::FilterType::Triangle);
|
||||
|
||||
// Quantise each opaque pixel into a coarse 4x4x4 RGB bucket (shift 6 bits ->
|
||||
// 64 buckets) and tally coverage + accumulate the exact channel sums so the
|
||||
// winner can be averaged back to its true tone.
|
||||
const BUCKETS: usize = 64; // 4 * 4 * 4
|
||||
let mut count = [0u32; BUCKETS];
|
||||
let mut sum_r = [0u32; BUCKETS];
|
||||
let mut sum_g = [0u32; BUCKETS];
|
||||
let mut sum_b = [0u32; BUCKETS];
|
||||
let mut opaque = 0u32;
|
||||
|
||||
for px in tiny.pixels() {
|
||||
if px[3] < 16 {
|
||||
continue; // skip (near-)transparent pixels
|
||||
}
|
||||
let bucket =
|
||||
((px[0] >> 6) as usize) * 16 + ((px[1] >> 6) as usize) * 4 + ((px[2] >> 6) as usize);
|
||||
count[bucket] += 1;
|
||||
sum_r[bucket] += px[0] as u32;
|
||||
sum_g[bucket] += px[1] as u32;
|
||||
sum_b[bucket] += px[2] as u32;
|
||||
opaque += 1;
|
||||
}
|
||||
|
||||
if opaque == 0 {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
// Most-abundant bucket = the perceived dominant colour.
|
||||
let mut best = 0usize;
|
||||
for i in 1..BUCKETS {
|
||||
if count[i] > count[best] {
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
let n = count[best].max(1);
|
||||
Color::from_rgb_u8(
|
||||
(sum_r[best] / n) as u8,
|
||||
(sum_g[best] / n) as u8,
|
||||
(sum_b[best] / n) as u8,
|
||||
)
|
||||
}
|
||||
|
||||
/// RGB(0..255) -> HSL with H in [0,360), S and L in [0,1].
|
||||
fn rgb_to_hsl(r: u8, g: u8, b: u8) -> (f32, f32, f32) {
|
||||
let r = r as f32 / 255.0;
|
||||
|
||||
@@ -7854,6 +7854,34 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
});
|
||||
}
|
||||
|
||||
// Qobuz Playlists category filter (multi-select, client-side). Toggling /
|
||||
// clearing a tag re-filters the cached playlists row and re-fires the
|
||||
// artwork for the new (filtered) positions — no re-fetch.
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let image_cache = image_cache.clone();
|
||||
window
|
||||
.global::<HomeActions>()
|
||||
.on_toggle_playlist_tag(move |slug| {
|
||||
if let Some(w) = weak.upgrade() {
|
||||
let jobs = home::toggle_playlist_tag(&w, slug.as_str());
|
||||
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let image_cache = image_cache.clone();
|
||||
window
|
||||
.global::<HomeActions>()
|
||||
.on_clear_playlist_tags(move || {
|
||||
if let Some(w) = weak.upgrade() {
|
||||
let jobs = home::clear_playlist_tags(&w);
|
||||
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Discover section configurator (Slice 5) — gear opens the modal; toggle /
|
||||
// move / reset mutate the per-user prefs, persist, and re-render the active
|
||||
// tab from the cache (no refetch). The mutation handlers re-fire artwork for
|
||||
|
||||
@@ -12,6 +12,7 @@ import { HomeState, HomeActions, DiscoverState, DiscoverActions, GenreFilterStat
|
||||
import { Carousel } from "Carousel.slint";
|
||||
import { SlimCarousel } from "SlimCarousel.slint";
|
||||
import { PlaylistCarousel } from "PlaylistCarousel.slint";
|
||||
import { PlaylistTagFilter } from "PlaylistTagFilter.slint";
|
||||
import { HomeSkeleton } from "HomeSkeleton.slint";
|
||||
import { ForYouView } from "ForYouView.slint";
|
||||
import { GenreFilterPopup } from "GenreFilterPopup.slint";
|
||||
@@ -325,13 +326,48 @@ export component HomeView inherits Rectangle {
|
||||
}
|
||||
|
||||
// Qobuz Playlists row — body=open, overlay=play (1:1 Tauri).
|
||||
if desc.id == "qobuzPlaylists" && HomeState.playlists.length > 0: PlaylistCarousel {
|
||||
title: @tr("Qobuz Playlists");
|
||||
playlists: HomeState.playlists;
|
||||
body-opens: true;
|
||||
show-view-all: false;
|
||||
media-action(kind, id, action) => {
|
||||
root.media-action(kind, id, action);
|
||||
// A category multi-select dropdown (ADR-008: no pills) sits
|
||||
// on the title line and filters the row client-side. Mounted
|
||||
// when the row has playlists OR there are category tags to
|
||||
// offer (so a zero-result filter can still be cleared).
|
||||
if desc.id == "qobuzPlaylists"
|
||||
&& (HomeState.playlists.length > 0 || HomeState.playlist-tags.length > 0): VerticalLayout {
|
||||
spacing: 12px;
|
||||
|
||||
// Title + filter dropdown on one line (the carousel
|
||||
// below renders its own paging controls, no title).
|
||||
HorizontalLayout {
|
||||
spacing: 12px;
|
||||
Text {
|
||||
text: @tr("Qobuz Playlists");
|
||||
color: Theme.text-primary;
|
||||
font-size: 18px;
|
||||
font-weight: Typography.semibold;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
if HomeState.playlist-tags.length > 0: VerticalLayout {
|
||||
alignment: center;
|
||||
PlaylistTagFilter { }
|
||||
}
|
||||
}
|
||||
|
||||
if HomeState.playlists.length > 0: PlaylistCarousel {
|
||||
// Title shown on the header row above, not here.
|
||||
title: "";
|
||||
playlists: HomeState.playlists;
|
||||
body-opens: true;
|
||||
show-view-all: false;
|
||||
media-action(kind, id, action) => {
|
||||
root.media-action(kind, id, action);
|
||||
}
|
||||
}
|
||||
|
||||
// Empty-result hint when a filter excludes everything.
|
||||
if HomeState.playlists.length == 0: Text {
|
||||
text: @tr("No playlists match the selected categories.");
|
||||
color: Theme.text-muted;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +174,13 @@ export component PlaylistCard inherits Rectangle {
|
||||
|
||||
Rectangle { height: 6px; }
|
||||
|
||||
// --- Title / subtitle --------------------------------------------
|
||||
// --- Title / subtitle line ---------------------------------------
|
||||
// The second line is the playlist's category tag (Discover cards) OR,
|
||||
// when there is no tag, the muted subtitle (owner / track count — used
|
||||
// by the Search + Favorites grids). The category is an UPPERCASE accent
|
||||
// eyebrow (uppercased in Rust; Slint has no text-transform), styled like
|
||||
// the QbzSelect "BP"/section-header accent-caps. Mutually exclusive so
|
||||
// the slot never doubles up.
|
||||
VerticalLayout {
|
||||
height: 40px;
|
||||
spacing: 2px;
|
||||
@@ -188,7 +194,17 @@ export component PlaylistCard inherits Rectangle {
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
if root.playlist.category != "": Text {
|
||||
text: root.playlist.category;
|
||||
height: 16px;
|
||||
color: Theme.accent;
|
||||
font-size: 11px;
|
||||
font-weight: Typography.semibold;
|
||||
letter-spacing: 0.5px;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
if root.playlist.category == "": Text {
|
||||
text: root.playlist.subtitle;
|
||||
height: 16px;
|
||||
color: Theme.text-muted;
|
||||
|
||||
@@ -29,12 +29,23 @@ export component PlaylistCollage inherits Rectangle {
|
||||
tint: Theme.text-muted;
|
||||
}
|
||||
|
||||
// 1 — full bleed.
|
||||
if root.n == 1: Image {
|
||||
// 1 — Discover cards: contain-fit over a dominant-colour letterbox.
|
||||
// Discover playlist covers are often non-square (rectangle / portrait);
|
||||
// cropping butchers them, so the full image is shown and the gaps are
|
||||
// filled with the cover's dominant colour (1:1 with Tauri's
|
||||
// PlaylistCardLite). A TRANSPARENT dominant-colour is the sentinel for
|
||||
// the other surfaces (Search / Favorites / Label) that opt OUT — they
|
||||
// keep the legacy cover-fit. The 2/3/4 mosaics below always stay `cover`.
|
||||
if root.n == 1: Rectangle {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
source: root.playlist.cover1;
|
||||
image-fit: cover;
|
||||
background: root.playlist.dominant-color;
|
||||
Image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
source: root.playlist.cover1;
|
||||
image-fit: root.playlist.dominant-color == Colors.transparent ? cover : contain;
|
||||
}
|
||||
}
|
||||
|
||||
// 2 — side by side halves.
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
// Qobuz Playlists category filter — a compact multi-select dropdown that
|
||||
// replaces the old WebPlayer category pills (ADR-008: no pills). The button
|
||||
// shows "Filter by category" (or "N selected") and opens a checkbox list of
|
||||
// the discover-index `playlists_tags`. Toggling a tag re-filters the cached
|
||||
// playlists row client-side (union of selected tags); an empty selection
|
||||
// shows everything. Tag NAMES are pre-localized by the response; the chrome
|
||||
// ("Filter by category", "All", "Clear") uses @tr literals.
|
||||
|
||||
import { Theme } from "../foundation/semantic-colors.slint";
|
||||
import { Typography } from "../foundation/typography.slint";
|
||||
import { Radius } from "../foundation/radius.slint";
|
||||
import { HomeState, HomeActions, PlaylistTagItem } from "../state.slint";
|
||||
import { QbzIcon } from "../primitives/QbzIcon.slint";
|
||||
|
||||
// One checkbox row in the open list: a square check + the localized tag name.
|
||||
component TagRow inherits Rectangle {
|
||||
in property <PlaylistTagItem> tag;
|
||||
callback toggle(string);
|
||||
|
||||
height: 32px;
|
||||
background: ta.has-hover ? Theme.surface-hover : transparent;
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
spacing: 8px;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 4px;
|
||||
border-width: 1.5px;
|
||||
border-color: root.tag.selected ? Theme.accent : Theme.border-muted;
|
||||
background: root.tag.selected ? Theme.accent : transparent;
|
||||
QbzIcon {
|
||||
visible: root.tag.selected;
|
||||
source: @image-url("../assets/icons/check.svg");
|
||||
width: 11px;
|
||||
height: 11px;
|
||||
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
|
||||
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
|
||||
tint: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: root.tag.name;
|
||||
color: root.tag.selected ? Theme.text-primary : Theme.text-secondary;
|
||||
font-size: 12px;
|
||||
font-weight: root.tag.selected ? Typography.medium : Typography.regular;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
|
||||
ta := TouchArea {
|
||||
mouse-cursor: pointer;
|
||||
clicked => {
|
||||
root.toggle(root.tag.slug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component PlaylistTagFilter inherits Rectangle {
|
||||
// Collapsed control: a 34px settings-style dropdown button.
|
||||
private property <length> control-width: 220px;
|
||||
private property <length> max-list-height: 320px;
|
||||
|
||||
width: root.control-width;
|
||||
// sm variant — matches QbzSelect { sm: true } used by the toolbar
|
||||
// selects (favorites Group / Sort): 30px tall, 6px radius, no outline.
|
||||
height: 30px;
|
||||
border-radius: 6px;
|
||||
border-width: 0px;
|
||||
background: ta.has-hover ? Theme.surface-hover : Theme.surface-elevated;
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: 10px;
|
||||
padding-right: 8px;
|
||||
spacing: 8px;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
QbzIcon {
|
||||
source: @image-url("../assets/icons/list-filter.svg");
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
tint: Theme.text-muted;
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: HomeState.playlist-tag-count > 0
|
||||
? @tr("{} selected", HomeState.playlist-tag-count)
|
||||
: @tr("Filter by category");
|
||||
color: HomeState.playlist-tag-count > 0 ? Theme.text-primary : Theme.text-secondary;
|
||||
font-size: 12px;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
QbzIcon {
|
||||
source: @image-url("../assets/icons/chevron-down.svg");
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
tint: Theme.text-muted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ta := TouchArea {
|
||||
mouse-cursor: pointer;
|
||||
clicked => {
|
||||
popup.show();
|
||||
}
|
||||
}
|
||||
|
||||
popup := PopupWindow {
|
||||
x: 0px;
|
||||
y: root.height + 4px;
|
||||
width: root.control-width;
|
||||
// List (capped + scrolling) + the 32px "All categories" footer + the
|
||||
// 10px vertical padding of the inner column. Reading the capped list
|
||||
// height (not the child rows) keeps this loop-free.
|
||||
height: Math.min(list-col.preferred-height, root.max-list-height) + 32px + 10px;
|
||||
|
||||
Rectangle {
|
||||
background: Theme.surface-main;
|
||||
border-radius: Radius.sm;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-muted;
|
||||
drop-shadow-blur: 20px;
|
||||
drop-shadow-color: #00000080;
|
||||
drop-shadow-offset-y: 5px;
|
||||
|
||||
VerticalLayout {
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
|
||||
Flickable {
|
||||
height: Math.min(list-col.preferred-height, root.max-list-height);
|
||||
viewport-width: self.width;
|
||||
viewport-height: list-col.preferred-height;
|
||||
|
||||
list-col := VerticalLayout {
|
||||
for tag in HomeState.playlist-tags: TagRow {
|
||||
tag: tag;
|
||||
toggle(slug) => {
|
||||
HomeActions.toggle-playlist-tag(slug);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// "Clear / show all" footer — disabled (dimmed) when nothing
|
||||
// is selected.
|
||||
clear-row := Rectangle {
|
||||
height: 32px;
|
||||
background: clear-ta.has-hover && HomeState.playlist-tag-count > 0
|
||||
? Theme.surface-hover
|
||||
: transparent;
|
||||
opacity: HomeState.playlist-tag-count > 0 ? 1.0 : 0.5;
|
||||
Text {
|
||||
text: @tr("All categories");
|
||||
color: Theme.text-secondary;
|
||||
font-size: 12px;
|
||||
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
|
||||
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
|
||||
}
|
||||
clear-ta := TouchArea {
|
||||
mouse-cursor: HomeState.playlist-tag-count > 0 ? pointer : default;
|
||||
clicked => {
|
||||
if (HomeState.playlist-tag-count > 0) {
|
||||
HomeActions.clear-playlist-tags();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,21 @@ export struct SearchPlaylistItem {
|
||||
cover2: image,
|
||||
cover3: image,
|
||||
cover4: image,
|
||||
// First tag name (uppercased accent subtag under the title; "" = none).
|
||||
// Only the single-cover Discover playlist cards populate it.
|
||||
category: string,
|
||||
// Dominant colour of the single cover, filling the contain-fit letterbox
|
||||
// on Discover playlist cards (default neutral dark; replaced once the
|
||||
// cover decodes). Mosaic cards ignore it.
|
||||
dominant-color: color,
|
||||
}
|
||||
|
||||
// One selectable category tag for the Qobuz Playlists multi-select filter.
|
||||
// `name` is pre-localized by the discover-index response.
|
||||
export struct PlaylistTagItem {
|
||||
slug: string,
|
||||
name: string,
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
// Discover / Home screen state.
|
||||
@@ -96,6 +111,11 @@ export global HomeState {
|
||||
// Qobuz Playlists row (Home + Editor's Picks). Single-cover cards; the
|
||||
// active tab's set is swapped in by crate::home::select_tab.
|
||||
in property <[SearchPlaylistItem]> playlists: [];
|
||||
// Category tags for the Qobuz Playlists multi-select filter (from the
|
||||
// discover-index `playlists_tags`). Empty when the response carries none.
|
||||
in property <[PlaylistTagItem]> playlist-tags: [];
|
||||
// Number of currently-selected category tags (0 = show all).
|
||||
in property <int> playlist-tag-count: 0;
|
||||
in property <bool> loading: false;
|
||||
// Active Discover tab: "home" | "editorPicks" | "forYou". The
|
||||
// three tabs draw from the same fetch; switching swaps which
|
||||
@@ -103,9 +123,15 @@ export global HomeState {
|
||||
in-out property <string> active-tab: "home";
|
||||
}
|
||||
|
||||
// Discover tab switching. Wired in main.rs to crate::home::select_tab.
|
||||
// Discover tab switching + the Qobuz Playlists category filter. Wired in
|
||||
// main.rs to crate::home.
|
||||
export global HomeActions {
|
||||
callback select-tab(string);
|
||||
// Toggle one category tag (by slug) in/out of the playlists filter —
|
||||
// client-side, re-filters the cached row. Empty selection = show all.
|
||||
callback toggle-playlist-tag(string);
|
||||
// Clear all selected category tags (back to showing every playlist).
|
||||
callback clear-playlist-tags();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user