diff --git a/crates/app/src/player/view.rs b/crates/app/src/player/view.rs index c05c3dc..c60e0ae 100644 --- a/crates/app/src/player/view.rs +++ b/crates/app/src/player/view.rs @@ -252,20 +252,25 @@ impl Player { let at = px_along(x, self.scroll_track.get()); let grab = match (thumb_x..thumb_x + thumb_w).contains(&at) { true => at - thumb_x, - // Beside the thumb: jump so its middle is under the pointer. The - // thumb is clamped inside the track by [`scroll_thumb`], so the - // grab it leaves is always a real place inside it. + // Beside the thumb: jump so its middle is under the pointer -- + // by the track's own proportion, the very mapping a drag sample + // is read through below, so the first move of the drag that + // follows lands exactly where the jump left the view and the + // thumb never snaps under the hand (a jump worked out in pixels + // at the view's own pps landed at span-over-duration of the + // target and the snap was the drag correcting it). The thumb is + // clamped inside the track by [`scroll_thumb`], so the grab this + // leaves is always a real place inside it -- at the thumb's floor + // width as much as anywhere else. false => { - let view = View { - scale: Scale { - start: (view.scale.start.max(0.) - + f64::from(at - thumb_x - thumb_w / 2.) / view.scale.pps) - .max(0.), - ..view.scale - }, + let start = f64::from((at - thumb_w / 2.).max(0.)) + / f64::from(view.bed.max(1.)) + * view.duration; + self.scale = View { + scale: Scale { start, ..view.scale }, ..view - }; - self.scale = view.settled(); + } + .settled(); thumb_w / 2. } }; @@ -360,18 +365,18 @@ impl Player { cx.notify(); } - /// One notch of the wheel over the lane stack's strip: the stack moves a - /// share of what it is showing, the same share the time axis gives a - /// notch of its own -- the strip is the names' scroll surface, and this - /// is what a wheel there did already. - pub(crate) fn lanes_wheel(&mut self, notches: f32, cx: &mut Context) { - let track = f32::from(self.lanes_scroll.bounds().size.height); + /// The wheel over the lane stack's strip, in the pixels gpui's own scroll + /// of the column would move it (`pixel_delta` -- a line a notch, not a + /// share of anything): the strip stops the wheel before the column behind + /// it sees it, so this is the notch's one path and it moves the stack + /// exactly as far as the names' own surface does. + pub(crate) fn lanes_wheel(&mut self, dy: f32, cx: &mut Context) { let max = f32::from(self.lanes_scroll.max_offset().height); - if track <= 0. || max <= 0. { + if max <= 0. { return; } let scrolled = -f32::from(self.lanes_scroll.offset().y); - let to = self.lanes_taken(scrolled - notches * track * SCROLL_NOTCH_SHARE); + let to = self.lanes_taken(scrolled - dy); self.lanes_scroll .set_offset(point(self.lanes_scroll.offset().x, px(-to))); cx.notify(); diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 0c93335..2ded42c 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -63,7 +63,6 @@ fn no_colour_is_written_outside_the_theme() { /// being scrolled, or it is an instruction nobody can carry out. #[test] fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() { - use crate::timeline_fixed_h; // The timeline is a region and not the window: its chrome -- the // scrollbar strip's row included, which is the larger of the two the @@ -294,6 +293,41 @@ fn the_scroll_thumb_is_the_visible_share_at_its_own_place() { assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.); } +/// A press beside the time axis's thumb jumps so the thumb's middle is under +/// the pointer, and the drag that carries on from the press must land exactly +/// where the jump left the view: both are read through the track's own +/// proportion (a jump worked out in pixels at the view's pps used to land at +/// span-over-duration of the target, and the snap on the first move was the +/// drag correcting it). The equality below is the no-snap invariant, at the +/// thumb's own width and at its floor width alike. +#[test] +fn a_beside_thumb_press_jumps_by_the_tracks_own_proportion() { + use crate::scroll_thumb; + + let bed = 400.; + // The mapping both halves of the gesture share: a place on the track is + // that share of the drawn duration. + let jump = |at: f32, thumb_w: f32| (at - thumb_w / 2.).max(0.) / bed; + for (duration, span) in [(100_f32, 20_f32), (1_000_000_f32, 100_f32)] { + let (_, thumb_w) = scroll_thumb(bed, f64::from(duration), 0., f64::from(span)); + let at = 3. * bed / 4.; + let start = jump(at, thumb_w) * duration; + // The jump centres the thumb on the press (the far end of a million + // seconds is the clamp's to hold, so the pin is measured from the + // thumb the track actually shows). + let (x, w) = scroll_thumb(bed, f64::from(duration), f64::from(start), f64::from(span)); + let centre = (x + w / 2.).min(bed - w / 2.); + assert!( + (centre - at.min(bed - w / 2.)).abs() < 1., + "thumb centre {centre} not at the press {at}" + ); + // The drag's first sample from that press -- the grabbed middle, the + // same track proportion -- is the same start, whatever the width. + let grab = thumb_w / 2.; + assert_eq!(jump(at, 2. * grab) * duration, start); + } +} + /// The strip's row is furniture only while there is somewhere to scroll to: /// zoomed out to the whole timeline the strip is not drawn and neither is its /// height -- out of every budget at once (the region, the box the lanes are @@ -1422,9 +1456,8 @@ fn the_volume_slider_lands_where_it_paints() { fn a_dragged_divider_stops_before_either_panel_disappears() { use crate::ui::theme::INSPECTOR_MIN_W; use crate::{ - SIDE_MAX_FRAC, SPLIT_W, SCROLL_HIT, SCROLL_THUMB_MIN, Split, TIMELINE_MAX_SHARE, - TOOLBAR_H, inspector_w, lanes_thumb, library_w, split_drag_size, split_size, - timeline_fixed_h, timeline_h, + SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w, + split_drag_size, split_size, timeline_fixed_h, timeline_h, }; use gpui::{point, px, size}; diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 685d755..cef1de3 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -32,7 +32,7 @@ use super::{ LATE_RESYNC, RESYNC_GAP, should_resync, retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped, SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport, - EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, TIMELINE_FIXED_H, TIMELINE_SHARE, lanes_shown, + EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, TIMELINE_SHARE, lanes_shown, timeline_fixed_h, px_below, rows_below, STATUS_SUCCESS, STATUS_WARNING, notice_tone, proxies_to_start, push_notice, typed, unseen_paths, unseen_sources, whole_take, window_title, diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 10d824a..ade71ab 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -294,17 +294,51 @@ impl Player { }) .into() }) + // The strip is its own mouse region, and it + // says so with an occluder: gpui's hit test + // stops here, so the clip a press lands on + // top of -- and the column's own native + // scroll, and the bed's time wheel behind + // that -- never hear anything through it. + // Occluding is also why the two drag + // listeners ride here and not only on the + // root: an occluder deafens the root to + // everything under it ([`drag_scrim`]'s + // lesson), and this thumb's drag runs along + // the strip's own 14 px -- the pointer never + // leaves the one place the root cannot hear. + // A drag that does leave it is picked up by + // the root's own copies, without a seam. + .occlude() .on_scroll_wheel(cx.listener( - |this, event: &ScrollWheelEvent, _, cx| { - this.lanes_wheel(wheel_delta(event), cx); + |this, event: &ScrollWheelEvent, window, cx| { + cx.stop_propagation(); + let line = window.line_height(); + let dy = + f32::from(event.delta.pixel_delta(line).y); + this.lanes_wheel(dy, cx); }, )) .on_mouse_down( MouseButton::Left, cx.listener(|this, event: &MouseDownEvent, _, cx| { + cx.stop_propagation(); this.lanes_press(event.position.y, cx); }), ) + // A right press is a clip's menu anywhere + // else on the bed; over the strip it is + // nothing, and the clip beneath must not + // answer it through the strip. + .on_mouse_down( + MouseButton::Right, + |_: &MouseDownEvent, _, cx| cx.stop_propagation(), + ) + .on_mouse_move(cx.listener(Player::drag_move)) + .on_mouse_up( + MouseButton::Left, + cx.listener(Player::drag_release), + ) .child( div() .absolute() @@ -367,14 +401,21 @@ impl Player { }) .into() }) + // Both consumed here for the vertical strip's + // reason: the row sits over nothing today, but + // a press or a notch that fell through it + // would be a gesture the strip drew and the + // panel answered. .on_scroll_wheel(cx.listener( |this, event: &ScrollWheelEvent, _, cx| { + cx.stop_propagation(); this.timeline_wheel(event, cx); }, )) .on_mouse_down( MouseButton::Left, cx.listener(|this, event: &MouseDownEvent, _, cx| { + cx.stop_propagation(); this.scroll_press(event.position.x, cx); }), )