fix(slint): album view layout and a working track search
Four album-view corrections from review: - Explicit badge: the title row now uses `alignment: start`, so the E badge sits right after the track name instead of being stretched out to a fake column position. - Label/awards sidebar: dropped `alignment: start` on the track/sidebar row — it had defeated the track list's stretch and left the sidebar floating mid-row with dead space. The list now stretches and the 254px sidebar is flush right; it rides the content region inward when a main sidebar opens. - Track search: now a real client-side filter — a TextInput drives the AlbumActions.search global callback; album.rs keeps the unfiltered list and filter_tracks() matches title/artist case-insensitively. - Description modal: the Flickable is vertical-stretch bounded so long text scrolls, and strip_html keeps paragraph breaks as newlines. cc
This commit is contained in:
5 files changed
+108
-13
No files matched your search
@@ -4,6 +4,7 @@
|
||||
//! on the worker thread, and applies it to the `AlbumState` global on the
|
||||
//! Slint event loop.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
use qbz_app::shell::AppRuntime;
|
||||
@@ -13,6 +14,13 @@ use slint::{ComponentHandle, ModelRc, VecModel};
|
||||
|
||||
use crate::{AlbumState, AlbumTrackItem, AppWindow};
|
||||
|
||||
thread_local! {
|
||||
/// The current album's full, unfiltered track list — kept so the
|
||||
/// track search can filter against it without a re-fetch. UI thread
|
||||
/// only, hence `thread_local`.
|
||||
static FULL_TRACKS: RefCell<Vec<AlbumTrackItem>> = RefCell::new(Vec::new());
|
||||
}
|
||||
|
||||
/// Plain, `Send` album data produced on the worker thread.
|
||||
pub struct AlbumData {
|
||||
pub id: String,
|
||||
@@ -144,11 +152,22 @@ fn quality_detail(bit_depth: Option<u32>, sample_rate: Option<f64>) -> String {
|
||||
format!("{depth}-bit / {rate} kHz")
|
||||
}
|
||||
|
||||
/// Crude HTML strip for Qobuz album descriptions (tags + a few entities).
|
||||
/// Crude HTML strip for Qobuz album descriptions. Break and paragraph
|
||||
/// tags become newlines first so paragraph structure survives; remaining
|
||||
/// tags are dropped and a few entities decoded.
|
||||
fn strip_html(input: &str) -> String {
|
||||
let normalized = input
|
||||
.replace("<br>", "\n")
|
||||
.replace("<br/>", "\n")
|
||||
.replace("<br />", "\n")
|
||||
.replace("<BR>", "\n")
|
||||
.replace("<BR/>", "\n")
|
||||
.replace("</p>", "\n\n")
|
||||
.replace("</P>", "\n\n");
|
||||
|
||||
let mut out = String::new();
|
||||
let mut in_tag = false;
|
||||
for ch in input.chars() {
|
||||
for ch in normalized.chars() {
|
||||
match ch {
|
||||
'<' => in_tag = true,
|
||||
'>' => in_tag = false,
|
||||
@@ -156,12 +175,17 @@ fn strip_html(input: &str) -> String {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
out.replace("&", "&")
|
||||
|
||||
let mut out = out
|
||||
.replace("&", "&")
|
||||
.replace("'", "'")
|
||||
.replace(""", "\"")
|
||||
.replace(" ", " ")
|
||||
.trim()
|
||||
.to_string()
|
||||
.replace(" ", " ");
|
||||
// Collapse runs of blank lines left by stacked tags.
|
||||
while out.contains("\n\n\n") {
|
||||
out = out.replace("\n\n\n", "\n\n");
|
||||
}
|
||||
out.trim().to_string()
|
||||
}
|
||||
|
||||
fn map_track(track: Track) -> TrackData {
|
||||
@@ -235,12 +259,37 @@ pub fn apply_album(window: &AppWindow, data: AlbumData) {
|
||||
state.set_description(data.description.into());
|
||||
state.set_label(data.label.into());
|
||||
state.set_awards(ModelRc::new(VecModel::from(awards)));
|
||||
|
||||
// Keep the unfiltered list for the track search, then show it all.
|
||||
FULL_TRACKS.with(|cell| *cell.borrow_mut() = tracks.clone());
|
||||
state.set_tracks(ModelRc::new(VecModel::from(tracks)));
|
||||
}
|
||||
|
||||
/// Filter the visible track list by `query` (case-insensitive match on
|
||||
/// title or artist), against the unfiltered list kept in `FULL_TRACKS`.
|
||||
/// Runs on the Slint event loop.
|
||||
pub fn filter_tracks(window: &AppWindow, query: &str) {
|
||||
let needle = query.trim().to_lowercase();
|
||||
let filtered: Vec<AlbumTrackItem> = FULL_TRACKS.with(|cell| {
|
||||
cell.borrow()
|
||||
.iter()
|
||||
.filter(|track| {
|
||||
needle.is_empty()
|
||||
|| track.title.as_str().to_lowercase().contains(&needle)
|
||||
|| track.artist.as_str().to_lowercase().contains(&needle)
|
||||
})
|
||||
.cloned()
|
||||
.collect()
|
||||
});
|
||||
window
|
||||
.global::<AlbumState>()
|
||||
.set_tracks(ModelRc::new(VecModel::from(filtered)));
|
||||
}
|
||||
|
||||
/// Clear album state and show an empty track list (used when opening a new
|
||||
/// album so the previous one does not flash).
|
||||
pub fn reset_album(window: &AppWindow) {
|
||||
FULL_TRACKS.with(|cell| cell.borrow_mut().clear());
|
||||
let state = window.global::<AlbumState>();
|
||||
state.set_tracks(ModelRc::new(VecModel::from(Vec::<AlbumTrackItem>::new())));
|
||||
state.set_artwork(slint::Image::default());
|
||||
|
||||
@@ -412,6 +412,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
log::info!("[qbz-slint] media-action: kind={kind} id={id} action={action}");
|
||||
});
|
||||
|
||||
// Album track search — client-side filter, no backend round-trip.
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
window
|
||||
.global::<AlbumActions>()
|
||||
.on_search(move |query| {
|
||||
if let Some(w) = weak.upgrade() {
|
||||
album::filter_tracks(&w, query.as_str());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.on_close_app(|| {
|
||||
log::info!("[qbz-slint] closing");
|
||||
let _ = slint::quit_event_loop();
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Theme } from "../foundation/semantic-colors.slint";
|
||||
import { Typography } from "../foundation/typography.slint";
|
||||
import { Radius } from "../foundation/radius.slint";
|
||||
import { Spacing } from "../foundation/spacing.slint";
|
||||
import { AlbumState, AlbumTrackItem, NavState, ContentView } from "../state.slint";
|
||||
import { AlbumState, AlbumTrackItem, AlbumActions, NavState, ContentView } from "../state.slint";
|
||||
import { QbzIcon } from "../primitives/QbzIcon.slint";
|
||||
import { ContextMenu } from "../primitives/ContextMenu.slint";
|
||||
import { ContextMenuItem } from "../primitives/ContextMenuItem.slint";
|
||||
@@ -83,7 +83,11 @@ component TrackRow inherits Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
spacing: 2px;
|
||||
|
||||
// alignment: start packs the title and the explicit badge at
|
||||
// their natural sizes, so the badge sits right after the name
|
||||
// instead of being stretched out to a column position.
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
spacing: 6px;
|
||||
Text {
|
||||
text: root.track.title;
|
||||
@@ -93,10 +97,11 @@ component TrackRow inherits Rectangle {
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
if root.track.explicit: Rectangle {
|
||||
if root.track.explicit: VerticalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: 3px;
|
||||
background: Theme.surface-elevated;
|
||||
Text {
|
||||
@@ -109,6 +114,7 @@ component TrackRow inherits Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: root.track.artist;
|
||||
visible: root.track.artist != "";
|
||||
@@ -347,7 +353,6 @@ export component AlbumPageView inherits Rectangle {
|
||||
// --- Album header ------------------------------------------------
|
||||
HorizontalLayout {
|
||||
spacing: 32px;
|
||||
alignment: start;
|
||||
|
||||
Rectangle {
|
||||
width: 224px;
|
||||
@@ -498,9 +503,14 @@ export component AlbumPageView inherits Rectangle {
|
||||
Rectangle { height: 8px; }
|
||||
|
||||
// --- Track list + label/awards sidebar --------------------------
|
||||
// No `alignment: start` here: it would defeat the track list's
|
||||
// horizontal-stretch and leave the sidebar floating mid-row
|
||||
// with dead space to its right. The track list stretches and
|
||||
// the 254px sidebar is pushed flush to the right edge; when a
|
||||
// main right sidebar opens, the whole content region narrows
|
||||
// and the sidebar rides along with it.
|
||||
HorizontalLayout {
|
||||
spacing: 32px;
|
||||
alignment: start;
|
||||
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
@@ -547,12 +557,27 @@ export component AlbumPageView inherits Rectangle {
|
||||
tint: Theme.text-muted;
|
||||
}
|
||||
}
|
||||
// Functional client-side filter.
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
track-search := TextInput {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: Theme.text-primary;
|
||||
font-size: 13px;
|
||||
vertical-alignment: center;
|
||||
single-line: true;
|
||||
edited => {
|
||||
AlbumActions.search(self.text);
|
||||
}
|
||||
}
|
||||
Text {
|
||||
visible: track-search.text == "";
|
||||
text: @tr("Search tracks...");
|
||||
color: Theme.text-muted;
|
||||
font-size: 13px;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -723,7 +748,10 @@ export component AlbumPageView inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// vertical-stretch bounds the Flickable to the leftover
|
||||
// panel height so a long description actually scrolls.
|
||||
Flickable {
|
||||
vertical-stretch: 1;
|
||||
viewport-width: self.width;
|
||||
viewport-height: desc-text.preferred-height;
|
||||
desc-text := Text {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { LoginScreen } from "login/LoginScreen.slint";
|
||||
import { AppShell } from "shell/AppShell.slint";
|
||||
|
||||
// Re-export the state globals so the Rust layer can populate them.
|
||||
export { HomeState, AlbumState, ArtistState, NavState, SessionState, SettingsState } from "state.slint";
|
||||
export { HomeState, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions } from "state.slint";
|
||||
|
||||
// Which top-level screen is shown. The app starts on `splash` while it
|
||||
// restores a saved session, then resolves to `shell` or `login`.
|
||||
|
||||
@@ -73,6 +73,12 @@ export global AlbumState {
|
||||
in property <bool> loading: false;
|
||||
}
|
||||
|
||||
// Album-view actions wired to Rust callbacks.
|
||||
export global AlbumActions {
|
||||
// Filter the visible track list by a query (client-side).
|
||||
callback search(string);
|
||||
}
|
||||
|
||||
// Which content view the shell shows.
|
||||
export enum ContentView { home, album, artist, settings }
|
||||
|
||||
|
||||
Reference in new issue
Block a user