Files
qbz/crates/qbz-slint/ui/immersive/CoverflowPanel.slint
T
vicrodh bc22362dc0 feat(slint): immersive responsive sizing + shared track-info block
On large windows the panels left big empty space; on small they were fine.
Make the art/covers grow to fill while keeping small-window behavior.

- AlbumReactivePanel: art cap 460->660, width frac 0.55->0.62 (grows more,
  center-anchored pulse untouched).
- StaticPanel: cap 460->640, width 0.55->0.62 (fills large windows).
- CoverflowPanel: center cover cap 440->560, width 0.42->0.52; wrap the fan +
  track-info in ONE center-aligned VerticalLayout so the composition is
  vertically balanced (kills the "covers clustered at top, empty bottom" look
  on large windows). Persistent-element model / dual repeaters / animated
  scroll / z-order all untouched — only sizing + the wrapping layout changed.
- New shared ImmersiveTrackInfo.slint (Now Playing indicator + EqualizerBars +
  title/artist/album/quality badge), standardized on Static's look; all three
  panels use it, removing three duplicated inline copies (they can't drift).

cc
2026-06-14 04:13:01 -06:00

286 lines
14 KiB
Plaintext

// Coverflow foreground (Immersive mode 2) — a CHEAP classic-CSS / iPhone-2007
// coverflow built on the PERSISTENT-ELEMENT + ANIMATED-SCROLL architecture.
//
// ARCHITECTURE (binding — replaces the old 7 fixed-slot design):
// 1. PERSISTENT covers. The covers are a SINGLE stable, ordered list of the
// whole queue — `QueueState.coverflow-tracks` = [history oldest..newest,
// NOW-PLAYING, upcoming...]. This list + its decoded cover images do NOT
// change on a pure track advance/navigation; only the int
// `QueueState.coverflow-index` (the flat position of NOW) moves. The Rust
// controller rebuilds the model ONLY when the queue CONTENTS change
// (id-sequence diff). So a track advance NEVER rebuilds this Repeater and
// NEVER re-decodes a visible cover.
// 2. ANIMATED SCROLL. A single float `scroll` is bound to `coverflow-index`
// with `animate scroll { 320ms ease-in-out }`. When Rust sets the new int
// index, `scroll` EASES to it and the fan repaints ONLY during the 320ms,
// then idles. NO `animation-tick` (that would force continuous fps = the
// CPU cost we are avoiding); NO Timer.
// 3. TRANSFORM-ONLY layout. Each cover i derives offset = i - scroll;
// x = center + offset*pitch; size = base * scale(|offset|); a per-depth
// black overlay dims by |offset| on an INNER Rectangle (never root
// opacity). Covers with |offset| > 3 are `visible:false` (~7 on screen).
// This is CSS `transform: translateX()+scale()` done with Slint geometry —
// FLAT scaled cards (NO rotateY/skew/perspective/reflection; Slint has no
// 3D and the owner accepted flat).
// 4. NAVIGATION. A side card at flat index i plays that queue position by
// mapping i -> the existing queue-wide play-history / play-coverflow-
// upcoming calls; the subsequent refresh moves `coverflow-index` and
// `scroll` animates to it. The center (offset ~0) is non-interactive.
//
// SLINT GOTCHAS honored: `parent` is NEVER read in any root binding (viewport
// dims + the per-cover stage geometry are passed as props). Everything derives
// from the DATA value `i` and the `scroll` float — NO `changed x/y/width/height`
// watchers on rows (avoids the "Recursion detected" panic). `dim` is on an INNER
// Rectangle, never the slot root opacity. Math.min/max are 2-arg; clamp =
// Math.max(lo, Math.min(hi, x)). The center card is a SEPARATE top-most instance
// (Repeater can't reorder by data) so it paints over its neighbors.
import { NowPlayingState, QueueState } from "../state.slint";
import { ImmersiveTrackInfo } from "ImmersiveTrackInfo.slint";
// One flat coverflow card. ALL geometry is derived from `offset` (= i - scroll)
// + the stage props passed in (NEVER `parent` in the root binding). The card
// position/size/dim are pure functions of `offset`, so when the parent's
// animated `scroll` changes, every card eases to its new transform with NO
// model change and NO source reassignment. `dim` is on an INNER Rectangle.
component CoverCard inherits Rectangle {
in property <image> art;
in property <bool> has-art: false;
in property <float> offset; // signed distance from center (i - scroll)
in property <length> base-art; // depth-0 (center) edge length
in property <length> pitch; // x spacing between adjacent depths
in property <length> stage-cx; // window-x of the center
in property <length> stage-height;
in property <bool> interactive: false;
// Whether THIS card is the one responsible for painting its slot. The fan is
// split into a LEFT Repeater (forward model) and a RIGHT Repeater (reversed
// model) plus a dedicated center card; each repeater card sets this true only
// for its own side's offset window so a slot is never double-drawn (GHOST FIX
// + symmetric Z-ORDER). Defaults true for the standalone center card.
in property <bool> paint-side: true;
callback navigate();
property <float> ao: Math.abs(root.offset);
// Step-down scale: center 1.0 -> ~0.5 at |offset| >= ~2.8. Symmetric: depends
// only on |offset|, so a left and right card at the same |offset| match.
property <float> scale: Math.max(0.5, 1.0 - 0.18 * root.ao);
property <length> slot: root.base-art * root.scale;
// Per-depth black overlay: 0 at center, up to 0.55 outward. Symmetric in |offset|.
property <float> dim: Math.min(0.55, root.ao * 0.18);
// Only ~7 cards near the center paint; the rest are dropped (no texture cost
// from off-screen rows). A card paints only inside the ±3.2 clamp AND when it
// owns its side (paint-side) — the latter hides the center-index Repeater
// copies (ghost) and the opposite half.
visible: root.ao <= 3.2 && root.paint-side;
width: root.slot;
height: root.slot;
// Center the card on (stage-cx + offset*pitch); small upward bias to leave
// room for the song card below.
x: root.stage-cx + root.offset * root.pitch - root.slot / 2;
y: (root.stage-height - root.slot) / 2 - 12px;
border-radius: 8px;
clip: true;
// Static drop-shadow on (near-)center cards only — the attenuation carries
// the depth for the side cards. Never animated.
drop-shadow-blur: root.ao < 0.5 ? 28px : 0px;
drop-shadow-color: #00000066;
drop-shadow-offset-y: root.ao < 0.5 ? 8px : 0px;
// Neutral placeholder when the item exists but its art is unresolved.
Rectangle {
width: parent.width;
height: parent.height;
border-radius: 8px;
background: #ffffff14;
visible: !root.has-art;
}
Image {
source: root.art;
image-fit: cover;
width: parent.width;
height: parent.height;
visible: root.has-art;
}
// Per-depth attenuation on an INNER Rectangle (never the root opacity).
Rectangle {
width: parent.width;
height: parent.height;
border-radius: 8px;
background: #000000;
opacity: root.dim;
}
// Side cards navigate; the center is non-interactive.
if root.interactive && root.ao > 0.5: TouchArea {
mouse-cursor: pointer;
clicked => { root.navigate(); }
}
}
export component CoverflowPanel inherits Rectangle {
in property <length> viewport-width: 1280px;
in property <length> viewport-height: 720px;
width: root.viewport-width;
height: root.viewport-height;
background: transparent;
// --- Geometry --------------------------------------------------------
// Center cover edge (base-art = depth-0 scale). The whole composition
// (fan stage + track-info) is wrapped in ONE centered VerticalLayout below,
// so the reserve is just pad-top(52) + info(~160) + spacing(28) +
// player-clearance(132) = 372px of vertical budget for the FAN stage.
//
// RESPONSIVE: previously capped at ~440px with a 0.42 width fraction, so on a
// LARGE window the covers stayed small clustered at the top (the "tragedy").
// We raise the cap 440 -> 560px and the width fraction 0.42 -> 0.52 so the
// fan scales up to fill the space. The height budget `vh-372` already grows
// with the window. The 160px floor keeps small windows safe (small was good).
property <length> base-art: Math.max(160px,
Math.min(Math.min(root.viewport-height - 372px, root.viewport-width * 0.52), 560px));
// X spacing between adjacent depths (overlapping inward).
property <length> pitch: root.base-art * 0.42;
// --- Animated scroll (the ONLY motion) -------------------------------
// Bound to the int current-index; Rust moving the index eases `scroll` over
// 320ms (repaints only during the transition, then idles).
property <float> scroll: QueueState.coverflow-index;
animate scroll { duration: 320ms; easing: ease-in-out; }
// Center card art prefers the unified large now-playing cover (sharper),
// falling back to the model row's small cover while it resolves.
property <int> center-idx: QueueState.coverflow-index;
property <image> center-art: NowPlayingState.artwork-large.width > 0
? NowPlayingState.artwork-large
: NowPlayingState.artwork;
property <bool> center-has-art: root.center-art.width > 0;
// --- Balanced composition: fan stage + track-info in ONE centered column.
// Previously the fan was pinned to the TOP (y=52) and the track-info to the
// BOTTOM (alignment: end), which on a large window left a huge empty band in
// the middle (the "tragedy"). Wrapping both in a single center-aligned
// VerticalLayout distributes the whole composition through the vertical band
// (between pad-top 52 and the 132px player clearance), so the fan and the
// metadata stay together and vertically centered at any window size.
VerticalLayout {
x: 0px;
y: 0px;
width: root.viewport-width;
height: root.viewport-height;
padding-top: 52px;
padding-bottom: 132px;
alignment: center;
spacing: 28px;
// --- Cover fan stage -------------------------------------------------
fan-stage := Rectangle {
width: root.viewport-width;
// Fixed height holds the center cover footprint (base-art) + headroom; the
// cards center within it via stage-height. NOT stretched (a layout child
// with an explicit height keeps the cards' centering math intact).
height: root.base-art + 56px;
property <length> cx: root.viewport-width / 2;
// Length of the flat model — used to map a reversed-model index back to
// the ORIGINAL flat index on the RIGHT side. Read once here (not `parent`
// in a card root binding, which Slint forbids).
property <int> cf-len: QueueState.coverflow-tracks.length;
// --- LEFT (history) Repeater -------------------------------------
// Iterates the FORWARD model in ascending index, so it paints
// far-left -> near-left: the near-left cover (highest left index) is
// declared last among the left cards => paints ON TOP. Correct as-is.
// Visible only for the history side: offset in (-3.5, -0.5) (strictly
// left of center; the center itself is the dedicated top card).
for item[i] in QueueState.coverflow-tracks: CoverCard {
property <float> off: i - root.scroll;
offset: self.off;
base-art: root.base-art;
pitch: root.pitch;
stage-cx: parent.cx;
stage-height: parent.height;
art: item.artwork;
has-art: item.artwork.width > 0;
// Left side only; hides the center-index card (GHOST FIX: the
// dedicated center card below is the ONLY center cover) and the whole
// right half (the RIGHT Repeater owns it). The strict < -0.5 / > -3.5
// window mirrors the right side's (0.5, 3.5).
paint-side: self.off < -0.5 && self.off > -3.5;
interactive: true;
navigate => {
// i < center-idx -> a history cover. flat history is oldest-first
// while QueueStateFull.history is most-recent-first, so
// hist_index = center-idx - 1 - i.
if (i < root.center-idx) {
QueueState.play-history(root.center-idx - 1 - i);
}
}
}
// --- RIGHT (upcoming) Repeater -----------------------------------
// Iterates the REVERSED model. rev index `j` is original flat index
// `orig = cf-len - 1 - j`, so the loop walks orig = high..low, i.e.
// far-upcoming -> near-upcoming: the near-upcoming cover is declared last
// among the right cards => paints ON TOP (Z-ORDER FIX, symmetric with the
// left). Offset is computed from `orig` so x/scale/dim match the left
// side exactly; at the ±0.5 hand-off a track's left- and right-element
// share the SAME offset (= orig - scroll) -> seamless. Visible only for
// offset in (0.5, 3.5).
for item[j] in QueueState.coverflow-tracks-rev: CoverCard {
property <int> orig: parent.cf-len - 1 - j;
property <float> off: self.orig - root.scroll;
offset: self.off;
base-art: root.base-art;
pitch: root.pitch;
stage-cx: parent.cx;
stage-height: parent.height;
art: item.artwork;
has-art: item.artwork.width > 0;
paint-side: self.off > 0.5 && self.off < 3.5;
interactive: true;
navigate => {
// orig > center-idx -> an upcoming cover.
// up_index = orig - center-idx - 1.
if (self.orig > root.center-idx) {
QueueState.play-coverflow-upcoming(self.orig - root.center-idx - 1);
}
}
}
// CENTER card — drawn LAST so it paints over its neighbors. Bound to the
// current-index row's offset (eases to 0 with `scroll`). Uses the unified
// large cover for sharpness; non-interactive (matches the disabled Tauri
// center button).
CoverCard {
offset: root.center-idx - root.scroll;
base-art: root.base-art;
pitch: root.pitch;
stage-cx: parent.cx;
stage-height: parent.height;
art: root.center-has-art ? root.center-art
: (QueueState.coverflow-tracks.length > root.center-idx
? QueueState.coverflow-tracks[root.center-idx].artwork
: root.center-art);
has-art: root.center-has-art
|| (QueueState.coverflow-tracks.length > root.center-idx
&& QueueState.coverflow-tracks[root.center-idx].artwork.width > 0);
interactive: false;
}
}
// --- Track info (shared, homologated across all 3 panels) ----------
// Sits directly below the fan in the SAME centered column, so the fan +
// metadata read as one balanced group (no more bottom-stranded info).
// Homologated to Static's look/spacing so "Now Playing" no longer bites
// the fan on small windows.
ImmersiveTrackInfo {
equalizer-tint: #7c3aed;
}
}
}