Place the timeline marker where the pointer actually is
The marker was drawn from a bucket index while a click reported a fraction of the track. Those are different quantities: bars each occupy one equal slot whatever span of time they cover, and the index snapped to the containing bucket's start edge, so the marker landed at the top of whichever slot held the instant — close enough to pass on a dense uniform axis, plainly wrong on a sparse one, and never under the click. Send the fraction instead, computed as the exact inverse of the interpolation the scrub handler applies, and position the marker from it. Marker and click are now the same quantity by construction. Scrolling the grid also left the marker behind: only an explicit scrub ever wrote the position, so the axis claimed to say "when you are" and stopped being true the moment the wheel moved. Map the first visible row back to a capture time and move the marker with it. That runs on every scroll event rather than behind the window-reload guard, which fires a few times per screenful and would make the marker advance in jerks. Only the marker moves, not the bars: rebuilding those means a GROUP BY aggregate over the library, far too much for a flick, and they do not change as the grid scrolls anyway. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -214,7 +214,7 @@ export component AppWindow inherits Window {
|
||||
in property <int> library-sweep-total: 0;
|
||||
|
||||
in property <int> library-current-bucket: 0;
|
||||
in property <int> library-current-index: -1;
|
||||
in property <float> library-current-fraction: -1;
|
||||
in property <bool> library-timeline-anchored: false;
|
||||
|
||||
callback library-scrub-fraction(float);
|
||||
@@ -468,7 +468,7 @@ export component AppWindow inherits Window {
|
||||
sweep-total: root.library-sweep-total;
|
||||
|
||||
current-bucket: root.library-current-bucket;
|
||||
current-bucket-index: root.library-current-index;
|
||||
current-bucket-fraction: root.library-current-fraction;
|
||||
timeline-anchored: root.library-timeline-anchored;
|
||||
|
||||
scrub-fraction(f) => { root.library-scrub-fraction(f); }
|
||||
|
||||
+16
-10
@@ -52,10 +52,15 @@ export component Timeline inherits Rectangle {
|
||||
/// The bucket the grid is currently showing, highlighted so the position is
|
||||
/// visible when the grid is moved by scrolling instead.
|
||||
in property <int> current-start: 0;
|
||||
/// Index of that bucket among `bars`, supplied by Rust. Slint has no array
|
||||
/// search, and a component that quietly returned the wrong index would put
|
||||
/// the marker in a plausible but false position.
|
||||
in property <int> current-index: -1;
|
||||
/// Where the grid sits along the visible span, 0..1, supplied by Rust.
|
||||
///
|
||||
/// **A fraction, not a bucket index.** The marker has to be placed by the
|
||||
/// same quantity a click produces: `fraction-at` maps a y to a fraction of
|
||||
/// the track and Rust interpolates an instant from it, so positioning the
|
||||
/// marker from a bar index instead put it wherever that bucket's *slot*
|
||||
/// happened to fall — never under the pointer. Negative means "not
|
||||
/// anchored".
|
||||
in property <float> current-fraction: -1;
|
||||
/// True once the user has taken control. Until then the marker rests at the
|
||||
/// middle rather than pinning to either end, which would imply a selection
|
||||
/// that has not been made.
|
||||
@@ -147,8 +152,8 @@ export component Timeline inherits Rectangle {
|
||||
height: 1px;
|
||||
background: Theme.active;
|
||||
opacity: root.anchored ? 1.0 : 0.35;
|
||||
y: root.anchored && root.current-index >= 0
|
||||
? root.track-top + root.current-index * root.slot
|
||||
y: root.anchored && root.current-fraction >= 0
|
||||
? root.track-top + clamp(root.current-fraction, 0.0, 1.0) * root.track-height
|
||||
: root.track-top + root.track-height / 2;
|
||||
}
|
||||
|
||||
@@ -502,10 +507,11 @@ export component LibraryGrid inherits Rectangle {
|
||||
in property <int> scroll-to: 0;
|
||||
in property <int> scroll-token: 0;
|
||||
|
||||
/// Which bucket the grid currently sits in, and where that is among the
|
||||
/// bars. Slint cannot search an array, so Rust supplies both.
|
||||
/// Which bucket the grid currently sits in, and how far along the visible
|
||||
/// span that is. Rust supplies both: it owns the span, so only it can turn
|
||||
/// an instant into the fraction that places the marker.
|
||||
in property <int> current-bucket: 0;
|
||||
in property <int> current-bucket-index: -1;
|
||||
in property <float> current-bucket-fraction: -1;
|
||||
/// False until the user has moved the timeline themselves, so the marker
|
||||
/// rests at the middle rather than implying a choice not yet made.
|
||||
in property <bool> timeline-anchored: false;
|
||||
@@ -917,7 +923,7 @@ export component LibraryGrid inherits Rectangle {
|
||||
bars: root.timeline;
|
||||
range-label: root.timeline-label;
|
||||
current-start: root.current-bucket;
|
||||
current-index: root.current-bucket-index;
|
||||
current-fraction: root.current-bucket-fraction;
|
||||
anchored: root.timeline-anchored;
|
||||
|
||||
scrub-to(f) => { root.scrub-fraction(f); }
|
||||
|
||||
Reference in New Issue
Block a user