Files
qbz/crates/qbz-slint/ui/immersive/AlbumReactivePanel.slint
T
vicrodh 786301a2e4 fix(slint): responsive album art in immersive Album Reactive so metadata never clips
The art was sized min(52vh, 460px) with only an 88px bottom pad, so on shorter
windows the art-block + metadata overflowed and the quality badge was clipped
under the floating player bar.

- base-art now derives from available height: it sizes the whole group
  (art*1.25 growth + 40px spacing + ~160px info + 132px player clearance) to
  fit viewport-height, with a viewport-width*0.55 cap for narrow windows,
  clamped to 180..460px.
- padding-bottom 88 -> 132 (clears the 90px player + 24px margin + gap);
  spacing 60 -> 40. Reserve constant kept in sync with base-art.

The Static panel (S3) will reuse this same responsive sizing.

cc
2026-06-13 08:17:14 -06:00

261 lines
11 KiB
Plaintext

// Album Reactive foreground — a faithful port of the Tauri
// `src/lib/components/immersive/panels/AlbumReactivePanel.svelte` (387 lines).
//
// Every reactive element maps 1:1 to the Svelte source:
// globalEnergy = avg(energy[0..5]) (Svelte init() line 116)
// bassEnergy = avg(energy[0], energy[1]) (Svelte init() line 117)
// artScale = 1 + globalEnergy * 0.25 (Svelte $derived line 165)
// glowSpread = 15 + bassEnergy * 200 (px) (Svelte $derived line 166)
// glowOpacity = min(0.1 + globalEnergy*1.5,1)(Svelte $derived line 167)
// glowColor = ImmersiveState.glow-color (Svelte extractGlowColor;
// the Rust crate::immersive::glow_color is the SAME algorithm,
// published to ImmersiveState.glow-color from playback.rs)
//
// Energy smoothing: the Svelte panel runs an asymmetric EMA (fast attack 0.9,
// slower decay 0.4) on the raw bands. The raw averaged bands are bound here and
// the visual settle is reproduced by 100ms property `animate`s — matching the
// Svelte CSS `transition: transform/box-shadow/opacity 100ms ease`. (Exact EMA
// parity is a Rust-side follow-up, flagged in the handoff risks; it must NOT
// touch the audio path.)
//
// Glow fidelity gap (known, flagged): CSS box-shadow has blur AND spread; Slint
// drop-shadow has blur only. We use glowSpread as the blur radius — the halo
// reads slightly tighter than Tauri but blur+opacity dominate the look.
//
// `parent` is NEVER read in the root binding (Slint gotcha); viewport dims are
// passed in as properties. `opacity:` is NEVER set on the root (it corrupts
// absolute positioning); the fade lives on the player/ModeBar chrome instead.
import { QualityBadgeFull } from "../primitives/QualityBadgeFull.slint";
import { NowPlayingState, VisualizerState, ImmersiveState } from "../state.slint";
// Four-bar "now playing" equalizer. A continuous loop driven by the global
// animation-tick() (pull-based) — NOT a Timer (a Timer does not reliably drive
// continuous animation). Each bar phase-offset mirrors the Svelte
// animation-delay / per-bar base height (lines 311-314).
component EqualizerBars inherits Rectangle {
in property <color> tint: #7c3aed;
width: 18px;
height: 14px;
// 0.8s loop (Svelte `equalize 0.8s`): tick ms -> phase 0..1.
property <float> t: Math.mod(animation-tick() / 1ms, 800.0) / 800.0;
// scaleY 0.3..1.0 sweep (Svelte keyframes 0/100% -> 0.3, 50% -> 1.0).
function wave(phase: float) -> float {
// triangle-ish sweep peaking at the half-phase, like ease-in-out.
return 0.3 + 0.7 * (0.5 - 0.5 * Math.cos((Math.mod(self.t + phase, 1.0)) * 6.283185 * 1rad));
}
HorizontalLayout {
alignment: start;
spacing: 2px;
// bar 1: delay 0.0, base 60%
Rectangle {
width: 3px;
y: parent.height - self.height;
height: parent.height * 0.6 * root.wave(0.0);
border-radius: 1px;
background: root.tint;
}
// bar 2: delay 0.2, base 100%
Rectangle {
width: 3px;
y: parent.height - self.height;
height: parent.height * 1.0 * root.wave(0.25);
border-radius: 1px;
background: root.tint;
}
// bar 3: delay 0.1, base 40%
Rectangle {
width: 3px;
y: parent.height - self.height;
height: parent.height * 0.4 * root.wave(0.125);
border-radius: 1px;
background: root.tint;
}
// bar 4: delay 0.3, base 80%
Rectangle {
width: 3px;
y: parent.height - self.height;
height: parent.height * 0.8 * root.wave(0.375);
border-radius: 1px;
background: root.tint;
}
}
}
export component AlbumReactivePanel inherits Rectangle {
in property <length> viewport-width: 1280px;
in property <length> viewport-height: 720px;
// --- Reactive scalars (faithful to AlbumReactivePanel.svelte) ----------
// Raw averaged energy bands (5 = sub-bass..air). VisualizerState.energy is
// published by the Rust 30fps drain while Immersive is open.
property <float> global-energy:
(VisualizerState.energy.length >= 5
? (VisualizerState.energy[0] + VisualizerState.energy[1]
+ VisualizerState.energy[2] + VisualizerState.energy[3]
+ VisualizerState.energy[4]) / 5.0
: 0.0);
property <float> bass-energy:
(VisualizerState.energy.length >= 2
? (VisualizerState.energy[0] + VisualizerState.energy[1]) / 2.0
: 0.0);
// artScale = 1 + globalEnergy * 0.25 (Svelte line 165)
property <float> art-scale: 1.0 + root.global-energy * 0.25;
// glowSpread = 15 + bassEnergy * 200 (px) (Svelte line 166) -> blur radius
property <length> glow-spread: (15.0 + root.bass-energy * 200.0) * 1px;
// glowOpacity = min(0.1 + globalEnergy * 1.5, 1) (Svelte line 167)
property <float> glow-opacity: Math.min(0.1 + root.global-energy * 1.5, 1.0);
// Base art box. Tauri uses `min(52vh, 460px)`, but the Slint group must also
// leave room for the metadata block + the floating player, or the quality
// badge gets clipped under the bar. So size the art so the WHOLE group
// (art*1.25 growth + spacing + info) fits the viewport height, with a width
// cap for narrow windows. Reserve = pad-top(52) + spacing(40) + info(~160) +
// player clearance(132) = 384px. Clamped to a sane 180..460px range.
property <length> base-art: Math.max(180px,
Math.min(Math.min((root.viewport-height - 384px) / 1.25, root.viewport-width * 0.55), 460px));
// Reactive size = base * artScale. The glow layer and the art share this
// exact size/position so the halo stays glued to the art edge (per risk).
property <length> art-size: root.base-art * root.art-scale;
width: root.viewport-width;
height: root.viewport-height;
background: transparent;
// Vertical stack: artwork block, then the track-info block. Matches the
// Svelte column (.album-reactive-panel: flex column, centered, gap 20px,
// track-info margin-top 40px). Centered as a group in the viewport.
VerticalLayout {
x: 0px;
y: 0px;
width: root.viewport-width;
height: root.viewport-height;
// Reserve top for the ModeBar and bottom for the floating player bar
// (90px + 24px margin + gap). base-art's reserve constant (384px) is kept
// in sync with these (pad-top 52 + spacing 40 + info ~160 + pad-bottom 132).
padding-top: 52px;
padding-bottom: 132px;
alignment: center;
spacing: 40px;
// --- Artwork + glow ------------------------------------------------
artwork-block := Rectangle {
// Sized to the largest reactive footprint so growth doesn't clip.
height: root.base-art * 1.25;
horizontal-stretch: 1;
// Glow halo: a same-size, same-position Rectangle behind the art,
// tinted with the album-derived glow color and a reactive
// drop-shadow blur. (CSS box-shadow blur+spread -> blur only.)
glow := Rectangle {
width: root.art-size;
height: root.art-size;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
border-radius: 8px;
background: ImmersiveState.glow-color;
opacity: root.glow-opacity;
drop-shadow-blur: root.glow-spread;
drop-shadow-color: ImmersiveState.glow-color;
animate width, height, x, y { duration: 100ms; easing: ease; }
animate opacity, drop-shadow-blur { duration: 100ms; easing: ease; }
}
// Artwork. Grows from center via reactive width/height (Slint has no
// transform:scale on a clipped Image). Static drop shadows mirror
// the Svelte .artwork-container box-shadow.
art := Rectangle {
width: root.art-size;
height: root.art-size;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
border-radius: 8px;
clip: true;
drop-shadow-blur: 32px;
drop-shadow-color: #00000080;
drop-shadow-offset-y: 8px;
animate width, height, x, y { duration: 100ms; easing: ease; }
Image {
source: NowPlayingState.artwork-large.width > 0
? NowPlayingState.artwork-large
: NowPlayingState.artwork;
image-fit: cover;
width: parent.width;
height: parent.height;
}
}
}
// --- Track info ----------------------------------------------------
info-block := VerticalLayout {
alignment: center;
spacing: 6px;
// "Now Playing" indicator: equalizer bars + label. Shown only while
// playing (Svelte {#if isPlaying}).
if NowPlayingState.playing: HorizontalLayout {
alignment: center;
spacing: 8px;
padding-bottom: 8px;
VerticalLayout {
alignment: center;
EqualizerBars {
tint: #7c3aed;
}
}
Text {
text: @tr("Now Playing");
color: #7c3aed;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.5px;
vertical-alignment: center;
}
}
// Track title.
Text {
text: NowPlayingState.title;
color: #ffffff;
font-size: 28px;
font-weight: 700;
horizontal-alignment: center;
overflow: elide;
}
// Artist.
Text {
text: NowPlayingState.artist;
color: #ffffffb3;
font-size: 18px;
horizontal-alignment: center;
overflow: elide;
}
// Album (italic, dimmer). Shown only when present (Svelte {#if album}).
if NowPlayingState.album != "": Text {
text: NowPlayingState.album;
color: #ffffff80;
font-size: 14px;
font-italic: true;
horizontal-alignment: center;
overflow: elide;
}
// Quality badge (Svelte QualityBadgeStatic). Centered under the text.
HorizontalLayout {
alignment: center;
padding-top: 12px;
QualityBadgeFull {
tier: NowPlayingState.quality-tier;
detail: NowPlayingState.quality-detail;
}
}
}
}
}