Files
qbz/crates/qbz-slint/ui/primitives/ListScrollbar.slint
T
vicrodh e88de3b9ee feat(slint): auto-hide hover-reveal scrollbars (Discover/Home/Blacklist manager)
ListScrollbar gains an auto-hide mode: track and thumb fade in on list hover
or active scroll (900ms idle timer) and out otherwise. Discover and Home derive
hover from the global ShellState pointer over the flickable bounds; the
Blacklist manager swaps std ScrollView for Flickable + ListScrollbar driven by
a per-row hover counter. Resolves the hover-only scrollbar over album cards that
a TouchArea overlay would have broken.

cx
2026-06-17 11:01:41 -06:00

90 lines
3.1 KiB
Plaintext

// Custom vertical scrollbar for a ListView — Slint's built-in one is
// too thin and its thumb has no minimum size, so on a thousands-row
// list it shrinks to a sliver. This sits in its own gutter (not over
// the rows), is thicker, keeps a minimum thumb height, and is
// draggable. Bind `viewport-y` two-way to the ListView and feed it the
// list's viewport/visible heights.
import { Theme } from "../foundation/semantic-colors.slint";
export component ListScrollbar inherits Rectangle {
in property <length> viewport-height;
in property <length> visible-height;
in-out property <length> viewport-y;
in property <bool> auto-hide: false;
in property <bool> hover-active: false;
property <bool> scroll-active: false;
// Only meaningful when the content overflows.
property <length> max-scroll: max(0px, root.viewport-height - root.visible-height);
property <length> thumb-h:
root.viewport-height > 0px
? max(48px, root.visible-height / root.viewport-height * root.height)
: root.height;
property <length> travel: max(0px, root.height - root.thumb-h);
property <bool> shown: !root.auto-hide || root.hover-active || root.scroll-active || bar-ta.has-hover || bar-ta.pressed;
changed viewport-y => {
if (root.auto-hide) {
root.scroll-active = true;
hide-timer.running = false;
hide-timer.running = true;
}
}
width: 14px;
visible: root.max-scroll > 0px;
hide-timer := Timer {
interval: 900ms;
triggered => {
root.scroll-active = false;
self.running = false;
}
}
// Track.
Rectangle {
width: 6px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
height: 100%;
background: #ffffff12;
border-radius: 3px;
opacity: root.shown ? 1.0 : 0.0;
animate opacity { duration: 160ms; }
}
// Thumb.
thumb := Rectangle {
width: bar-ta.has-hover || bar-ta.pressed ? 10px : 8px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
height: root.thumb-h;
y: root.max-scroll > 0px
? (-root.viewport-y / root.max-scroll) * root.travel
: 0px;
border-radius: 5px;
background: bar-ta.has-hover || bar-ta.pressed ? #ffffff77 : #ffffff44;
opacity: root.shown ? 1.0 : 0.0;
animate width { duration: 100ms; }
animate opacity { duration: 160ms; }
}
// Drag / click-to-position over the whole gutter — centers the
// thumb on the pointer.
bar-ta := TouchArea {
mouse-cursor: pointer;
moved => {
if (bar-ta.pressed && root.travel > 0px) {
root.viewport-y = -min(root.max-scroll, max(0px,
(bar-ta.mouse-y - root.thumb-h / 2) / root.travel * root.max-scroll));
}
}
pointer-event(e) => {
if (e.kind == PointerEventKind.down && root.travel > 0px) {
root.viewport-y = -min(root.max-scroll, max(0px,
(bar-ta.mouse-y - root.thumb-h / 2) / root.travel * root.max-scroll));
}
}
}
}