Files
qbz/crates/qbz-ui/ui/shell/SidebarNowPlayingDock.slint
T
vicrodh 59409822ab fix(npb-large): lift the cover 2px off the window bottom
The Large now-playing cover sat flush against the window bottom. Lift it 2px and
take those 2px from the cover<->spectrum gap (10 -> 8) so the dock height is
unchanged; the bottom pad applies only while the spectrum is shown so the
off-state height still matches large-dock-height.

cc
2026-06-28 11:00:36 -06:00

252 lines
11 KiB
Plaintext

// Large NPB (mode 3) cover + spectrum dock — the L's vertical arm. Mounted as a
// ROOT overlay by AppShell, pinned flush to the window bottom-left (NOT inside
// the sidebar VL anymore — that floated it above the bar). Layout, bottom-up: a
// square album cover (= the fed width) at the very bottom; ABOVE it a compact
// spectrum band (half the old height, more bars) that the user can hide via a
// top-right toggle on the cover.
//
// Owner refinements (2026-06-21):
// - The cover sits FLUSH to the window bottom-left, equal L/R gutters (the
// AppShell overlay feeds x=16, width=240-32). art-size = root.width.
// - The only cover overlay is ONE top-right eye button toggling the visualizer
// (ShellState.large-visualizer-on). The old [Small,Default] mode switches are
// gone (use the Now-Playing-view menu to leave Large).
// - When the visualizer is OFF the spectrum band collapses (root height shrinks)
// so the sidebar's playlist list reclaims the space.
// - Both toggles persist: the eye fires ("npb-large", _, "viz-toggle") and the
// spectrum click fires ("npb-large", _, "spectrum-cycle"); Rust writes ui_prefs
// and mirrors back into ShellState (Slint never mutates them directly).
// - Shorter band, MORE bars: Bars is a 28-column MIRRORED spectrum; Waveform is
// 48 columns; Energy is the 5 semantic bands.
//
// Visuals reuse the immersive pipeline: VisualizerState (FFT producer; tap gated
// by AppShell's viz-should-run) + the album-derived ImmersiveState.spectrum-
// primary/secondary (repopulated every track in playback.rs). No audio path
// touched.
//
// Slint gotchas honored: `parent` is never read in a root binding (dims via
// root.width); no `opacity:` on a container holding the absolutely-positioned
// bars (it corrupts placement); bar count/visibility is driven only from bound
// model values, never a `changed` handler.
import { Theme } from "../foundation/semantic-colors.slint";
import { Radius } from "../foundation/radius.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { NowPlayingState, VisualizerState, ImmersiveState, ShellState } from "../state.slint";
// One spectrum bar that grows UP from the bottom edge. Amplitude (0..1) is
// already smoothed + clamped in Rust; only a short ease settles the step.
component VBar inherits Rectangle {
in property <length> slot-x;
in property <length> bar-width;
in property <length> area-h;
in property <float> amp;
property <length> bar-h: Math.max(2px, root.amp * root.area-h);
animate bar-h { duration: 90ms; easing: ease; }
x: 0; y: 0; width: 0px; height: 0px;
Rectangle {
x: root.slot-x;
width: root.bar-width;
height: root.bar-h;
y: root.area-h - self.height;
border-radius: 1px;
background: @linear-gradient(0deg,
ImmersiveState.spectrum-primary 0%, ImmersiveState.spectrum-secondary 100%);
}
}
// A centered waveform column: a vertical sliver whose height tracks |sample|,
// mirrored about the band's vertical center.
component WaveCol inherits Rectangle {
in property <length> slot-x;
in property <length> bar-width;
in property <length> area-h;
in property <float> amp; // 0..1 absolute magnitude
property <length> col-h: Math.max(2px, root.amp * root.area-h);
animate col-h { duration: 70ms; easing: ease; }
x: 0; y: 0; width: 0px; height: 0px;
Rectangle {
x: root.slot-x;
width: root.bar-width;
height: root.col-h;
y: (root.area-h - self.height) / 2;
border-radius: 1px;
background: ImmersiveState.spectrum-primary;
}
}
export component SidebarNowPlayingDock inherits Rectangle {
callback media-action(string, string, string);
// Square cover = the dock's (sidebar content) width. Compact spectrum above.
property <length> art-size: root.width;
property <length> spectrum-h: 46px; // half the original 92px (owner: shorter band)
// Reserve cover + (when ON) the spectrum band + gap, plus the top hairline
// pad. MUST equal ShellState.large-dock-height in BOTH toggle states so the
// AppShell overlay (y = root.height - large-dock-height) keeps the cover flush.
height: ShellState.large-visualizer-on
? (root.spectrum-h + 10px + root.art-size + 9px)
: (root.art-size + 9px);
// Bars: 28 MIRRORED columns = 14 active source bins x2 (the 16-bin FFT
// excludes {1,15}; SpectrumPanel parity). More bars than the old straight 14.
property <[int]> active-bins: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
property <length> bar-slot: root.width / 28;
// Waveform: 48 downsampled L columns (indices 0..235 step 5).
property <[int]> wave-indices: [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55,
60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135,
140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 205,
210, 215, 220, 225, 230, 235];
property <length> wave-slot: root.width / 48;
property <length> energy-slot: root.width / 5;
// Top hairline divider between the playlists and the dock.
Rectangle {
x: 0; y: 0;
width: root.width;
height: 1px;
background: Theme.border-subtle;
}
VerticalLayout {
padding-top: 9px;
// Lift the cover 2px off the window bottom (it was flush) and take those
// 2px out of the cover<->spectrum gap (10 -> 8), so the dock height is
// unchanged (9 + spectrum + 8 + art + 2 == 9 + spectrum + 10 + art). The
// bottom pad applies only while the spectrum is shown — otherwise the
// off-state height would no longer match ShellState.large-dock-height.
spacing: 8px;
padding-bottom: ShellState.large-visualizer-on ? 2px : 0px;
// ---- Spectrum band (only while the visualizer is ON) --------------
if ShellState.large-visualizer-on: spectrum := Rectangle {
height: root.spectrum-h;
border-radius: Radius.md;
background: #00000059;
clip: true;
// Mode 0 — Bars (28-column MIRRORED, album-gradient).
if ShellState.large-spectrum-mode == 0: Rectangle {
width: parent.width;
height: parent.height;
// Left half (columns 0..13).
for src[i] in root.active-bins: VBar {
slot-x: i * root.bar-slot + 1px;
bar-width: root.bar-slot - 2px;
area-h: spectrum.height;
amp: VisualizerState.bars.length > src
? Math.max(0.0, Math.min(1.0, VisualizerState.bars[src]))
: 0.0;
}
// Right half (mirror, columns 27..14).
for src[i] in root.active-bins: VBar {
slot-x: (27 - i) * root.bar-slot + 1px;
bar-width: root.bar-slot - 2px;
area-h: spectrum.height;
amp: VisualizerState.bars.length > src
? Math.max(0.0, Math.min(1.0, VisualizerState.bars[src]))
: 0.0;
}
}
// Mode 1 — Waveform (centered, 48 downsampled L columns).
if ShellState.large-spectrum-mode == 1: Rectangle {
width: parent.width;
height: parent.height;
for idx[i] in root.wave-indices: WaveCol {
slot-x: i * root.wave-slot + 1px;
bar-width: root.wave-slot - 2px;
area-h: spectrum.height;
amp: VisualizerState.waveform.length > idx
? Math.min(1.0, Math.abs(VisualizerState.waveform[idx]))
: 0.0;
}
}
// Mode 2 — Energy (5 semantic bands, sub-bass..air).
if ShellState.large-spectrum-mode == 2: Rectangle {
width: parent.width;
height: parent.height;
for band[i] in [0, 1, 2, 3, 4]: VBar {
slot-x: i * root.energy-slot + 3px;
bar-width: root.energy-slot - 6px;
area-h: spectrum.height;
amp: VisualizerState.energy.length > band
? Math.max(0.0, Math.min(1.0, VisualizerState.energy[band]))
: 0.0;
}
}
// Click the band → cycle Bars -> Waveform -> Energy (persisted in Rust).
spectrum-ta := TouchArea {
mouse-cursor: pointer;
clicked => { root.media-action("npb-large", "", "spectrum-cycle"); }
}
}
// ---- Album cover (square) + top-right visualizer toggle -----------
art := Rectangle {
height: root.art-size;
border-radius: Radius.md;
clip: true;
drop-shadow-blur: 24px;
drop-shadow-color: #00000080;
drop-shadow-offset-y: 4px;
background: Theme.surface-main;
if NowPlayingState.has-track
&& (NowPlayingState.artwork-large.width > 0 || NowPlayingState.artwork.width > 0): Image {
source: NowPlayingState.artwork-large.width > 0
? NowPlayingState.artwork-large
: NowPlayingState.artwork;
image-fit: cover;
width: parent.width;
height: parent.height;
}
// Placeholder glyph when no cover yet.
if !(NowPlayingState.artwork-large.width > 0 || NowPlayingState.artwork.width > 0): QbzIcon {
source: @image-url("../assets/icons/music.svg");
width: root.art-size * 0.32;
height: root.art-size * 0.32;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
tint: Theme.text-muted;
}
// Hover tracker over the whole cover — reveals the toggle on hover;
// the toggle ALSO stays visible while the visualizer is OFF so it can
// be turned back on.
cover-ta := TouchArea {
mouse-cursor: default;
}
// Single top-right toggle: show/hide the spectrum band (eye/eye-off).
// Fires the persisted media-action; its own TouchArea wins over cover-ta.
Rectangle {
width: 28px;
height: 28px;
x: parent.width - self.width - 8px;
y: 8px;
border-radius: 8px;
background: vt.has-hover ? #ffffff2e : #00000080;
border-width: 1px;
border-color: #ffffff33;
opacity: (cover-ta.has-hover || vt.has-hover || !ShellState.large-visualizer-on) ? 1.0 : 0.0;
animate opacity { duration: 140ms; }
QbzIcon {
source: ShellState.large-visualizer-on
? @image-url("../assets/icons/eye.svg")
: @image-url("../assets/icons/eye-off.svg");
width: 15px;
height: 15px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: #ffffff;
}
vt := TouchArea {
mouse-cursor: pointer;
clicked => { root.media-action("npb-large", "", "viz-toggle"); }
}
}
}
}
}