forge
Explore
Log in

Don't you dare go Hollow

The strips are their own mouse regions, and a jump is a proportion

Browse files at this commit

640189f86dd67e379e4cced70200f14c36cf3937Ahmet Kaan GümüşParent: 475f10c
  • fix
    • the strips are their own mouse regions, and a jump is a proportion
Show full message
🐛 fix(timeline): the strips are their own mouse regions, and a jump is a proportion

The lane stack's strip lay over the beds as painted pixels and as
nothing else: a press fell through to the clip beneath it -- selected
it, started its drag, opened its menu -- and a notch over it scrolled
the stack twice, once by the strip's own handler and once by the
column's native scroll behind it. The strip now occludes: gpui's hit
test stops at it, so nothing under it hears a button or a wheel, and
the wheel it answers with is the column's own unit (pixel_delta, a
line a notch) so a notch there moves the stack exactly as far as a
notch over the names does. An occluder is also deaf itself to the root
that follows every drag, so the thumb's two listeners ride on the strip
exactly as drag_scrim's do -- a vertical thumb drag never leaves the
strip's own 14 px, and a drag that does is picked up by the root's
copies without a seam. The time axis's strip takes the press and the
wheel for the same reason: its row sits over nothing today, but a
gesture it drew was not its to share.

The time axis's click-beside-the-thumb jump was worked out in pixels at
the view's own pps, which lands at span-over-duration of the target --
the first drag sample, read through the track's proportion like every
other, then snapped the view to where the hand had not put it. The jump
now goes through that same proportion, so the thumb centres on the
press, at its own width and at its floor width alike, and the drag that
carries on from the press lands exactly where the jump left the view.
crates/app/src/player/view.rsmodified+25 -20
@@ -252,20 +252,25 @@ impl Player {
252 let at = px_along(x, self.scroll_track.get());252 let at = px_along(x, self.scroll_track.get());
253 let grab = match (thumb_x..thumb_x + thumb_w).contains(&at) {253 let grab = match (thumb_x..thumb_x + thumb_w).contains(&at) {
254 true => at - thumb_x,254 true => at - thumb_x,
255- // Beside the thumb: jump so its middle is under the pointer. The255+ // Beside the thumb: jump so its middle is under the pointer --
256- // thumb is clamped inside the track by [`scroll_thumb`], so the256+ // by the track's own proportion, the very mapping a drag sample
257- // grab it leaves is always a real place inside it.257+ // is read through below, so the first move of the drag that
258+ // follows lands exactly where the jump left the view and the
259+ // thumb never snaps under the hand (a jump worked out in pixels
260+ // at the view's own pps landed at span-over-duration of the
261+ // target and the snap was the drag correcting it). The thumb is
262+ // clamped inside the track by [`scroll_thumb`], so the grab this
263+ // leaves is always a real place inside it -- at the thumb's floor
264+ // width as much as anywhere else.
258 false => {265 false => {
259- let view = View {266+ let start = f64::from((at - thumb_w / 2.).max(0.))
260- scale: Scale {267+ / f64::from(view.bed.max(1.))
261- start: (view.scale.start.max(0.)268+ * view.duration;
262- + f64::from(at - thumb_x - thumb_w / 2.) / view.scale.pps)269+ self.scale = View {
263- .max(0.),270+ scale: Scale { start, ..view.scale },
264- ..view.scale
265- },
266 ..view271 ..view
267- };272+ }
268- self.scale = view.settled();273+ .settled();
269 thumb_w / 2.274 thumb_w / 2.
270 }275 }
271 };276 };
@@ -360,18 +365,18 @@ impl Player {
360 cx.notify();365 cx.notify();
361 }366 }
362 367
363- /// One notch of the wheel over the lane stack's strip: the stack moves a368+ /// The wheel over the lane stack's strip, in the pixels gpui's own scroll
364- /// share of what it is showing, the same share the time axis gives a369+ /// of the column would move it (`pixel_delta` -- a line a notch, not a
365- /// notch of its own -- the strip is the names' scroll surface, and this370+ /// share of anything): the strip stops the wheel before the column behind
366- /// is what a wheel there did already.371+ /// it sees it, so this is the notch's one path and it moves the stack
367- pub(crate) fn lanes_wheel(&mut self, notches: f32, cx: &mut Context<Self>) {372+ /// exactly as far as the names' own surface does.
368- let track = f32::from(self.lanes_scroll.bounds().size.height);373+ pub(crate) fn lanes_wheel(&mut self, dy: f32, cx: &mut Context<Self>) {
369 let max = f32::from(self.lanes_scroll.max_offset().height);374 let max = f32::from(self.lanes_scroll.max_offset().height);
370- if track <= 0. || max <= 0. {375+ if max <= 0. {
371 return;376 return;
372 }377 }
373 let scrolled = -f32::from(self.lanes_scroll.offset().y);378 let scrolled = -f32::from(self.lanes_scroll.offset().y);
374- let to = self.lanes_taken(scrolled - notches * track * SCROLL_NOTCH_SHARE);379+ let to = self.lanes_taken(scrolled - dy);
375 self.lanes_scroll380 self.lanes_scroll
376 .set_offset(point(self.lanes_scroll.offset().x, px(-to)));381 .set_offset(point(self.lanes_scroll.offset().x, px(-to)));
377 cx.notify();382 cx.notify();
crates/app/src/tests/layout.rsmodified+37 -4
@@ -63,7 +63,6 @@ fn no_colour_is_written_outside_the_theme() {
63 /// being scrolled, or it is an instruction nobody can carry out.63 /// being scrolled, or it is an instruction nobody can carry out.
64 #[test]64 #[test]
65 fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() {65 fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() {
66- use crate::timeline_fixed_h;
67 66
68 // The timeline is a region and not the window: its chrome -- the67 // The timeline is a region and not the window: its chrome -- the
69 // scrollbar strip's row included, which is the larger of the two the68 // 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() {
294 assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.);293 assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.);
295 }294 }
296 295
296+/// A press beside the time axis's thumb jumps so the thumb's middle is under
297+/// the pointer, and the drag that carries on from the press must land exactly
298+/// where the jump left the view: both are read through the track's own
299+/// proportion (a jump worked out in pixels at the view's pps used to land at
300+/// span-over-duration of the target, and the snap on the first move was the
301+/// drag correcting it). The equality below is the no-snap invariant, at the
302+/// thumb's own width and at its floor width alike.
303+#[test]
304+fn a_beside_thumb_press_jumps_by_the_tracks_own_proportion() {
305+ use crate::scroll_thumb;
306+
307+ let bed = 400.;
308+ // The mapping both halves of the gesture share: a place on the track is
309+ // that share of the drawn duration.
310+ let jump = |at: f32, thumb_w: f32| (at - thumb_w / 2.).max(0.) / bed;
311+ for (duration, span) in [(100_f32, 20_f32), (1_000_000_f32, 100_f32)] {
312+ let (_, thumb_w) = scroll_thumb(bed, f64::from(duration), 0., f64::from(span));
313+ let at = 3. * bed / 4.;
314+ let start = jump(at, thumb_w) * duration;
315+ // The jump centres the thumb on the press (the far end of a million
316+ // seconds is the clamp's to hold, so the pin is measured from the
317+ // thumb the track actually shows).
318+ let (x, w) = scroll_thumb(bed, f64::from(duration), f64::from(start), f64::from(span));
319+ let centre = (x + w / 2.).min(bed - w / 2.);
320+ assert!(
321+ (centre - at.min(bed - w / 2.)).abs() < 1.,
322+ "thumb centre {centre} not at the press {at}"
323+ );
324+ // The drag's first sample from that press -- the grabbed middle, the
325+ // same track proportion -- is the same start, whatever the width.
326+ let grab = thumb_w / 2.;
327+ assert_eq!(jump(at, 2. * grab) * duration, start);
328+ }
329+}
330+
297 /// The strip's row is furniture only while there is somewhere to scroll to:331 /// The strip's row is furniture only while there is somewhere to scroll to:
298 /// zoomed out to the whole timeline the strip is not drawn and neither is its332 /// zoomed out to the whole timeline the strip is not drawn and neither is its
299 /// height -- out of every budget at once (the region, the box the lanes are333 /// 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() {
1422 fn a_dragged_divider_stops_before_either_panel_disappears() {1456 fn a_dragged_divider_stops_before_either_panel_disappears() {
1423 use crate::ui::theme::INSPECTOR_MIN_W;1457 use crate::ui::theme::INSPECTOR_MIN_W;
1424 use crate::{1458 use crate::{
1425- SIDE_MAX_FRAC, SPLIT_W, SCROLL_HIT, SCROLL_THUMB_MIN, Split, TIMELINE_MAX_SHARE,1459+ SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w,
1426- TOOLBAR_H, inspector_w, lanes_thumb, library_w, split_drag_size, split_size,1460+ split_drag_size, split_size, timeline_fixed_h, timeline_h,
1427- timeline_fixed_h, timeline_h,
1428 };1461 };
1429 use gpui::{point, px, size};1462 use gpui::{point, px, size};
1430 1463
crates/app/src/tests/mod.rsmodified+1 -1
@@ -32,7 +32,7 @@ use super::{
32 LATE_RESYNC, RESYNC_GAP, should_resync,32 LATE_RESYNC, RESYNC_GAP, should_resync,
33 retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped,33 retarget, row_enable, row_items, scrub_due, secs_label, show_label, silence_rate, size_label, snap_cue, snap_marks, snapped,
34 SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport,34 SUB_PLAN_CHARS, source_tint, span_partner, speed_at, sub_pick_after_removal, subtitle_plan, summary_head, summary_tail, timecode, transport,
35- EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, TIMELINE_FIXED_H, TIMELINE_SHARE, lanes_shown,35+ EXPORT_DONE, NOTICES_MAX, STATUS_ERROR, TIMELINE_SHARE, lanes_shown, timeline_fixed_h,
36 px_below, rows_below, STATUS_SUCCESS, STATUS_WARNING, notice_tone,36 px_below, rows_below, STATUS_SUCCESS, STATUS_WARNING, notice_tone,
37 proxies_to_start, push_notice, typed, unseen_paths, unseen_sources,37 proxies_to_start, push_notice, typed, unseen_paths, unseen_sources,
38 whole_take, window_title,38 whole_take, window_title,
crates/app/src/ui/timeline.rsmodified+43 -2
@@ -294,17 +294,51 @@ impl Player {
294 })294 })
295 .into()295 .into()
296 })296 })
297+ // The strip is its own mouse region, and it
298+ // says so with an occluder: gpui's hit test
299+ // stops here, so the clip a press lands on
300+ // top of -- and the column's own native
301+ // scroll, and the bed's time wheel behind
302+ // that -- never hear anything through it.
303+ // Occluding is also why the two drag
304+ // listeners ride here and not only on the
305+ // root: an occluder deafens the root to
306+ // everything under it ([`drag_scrim`]'s
307+ // lesson), and this thumb's drag runs along
308+ // the strip's own 14 px -- the pointer never
309+ // leaves the one place the root cannot hear.
310+ // A drag that does leave it is picked up by
311+ // the root's own copies, without a seam.
312+ .occlude()
297 .on_scroll_wheel(cx.listener(313 .on_scroll_wheel(cx.listener(
298- |this, event: &ScrollWheelEvent, _, cx| {314+ |this, event: &ScrollWheelEvent, window, cx| {
299- this.lanes_wheel(wheel_delta(event), cx);315+ cx.stop_propagation();
316+ let line = window.line_height();
317+ let dy =
318+ f32::from(event.delta.pixel_delta(line).y);
319+ this.lanes_wheel(dy, cx);
300 },320 },
301 ))321 ))
302 .on_mouse_down(322 .on_mouse_down(
303 MouseButton::Left,323 MouseButton::Left,
304 cx.listener(|this, event: &MouseDownEvent, _, cx| {324 cx.listener(|this, event: &MouseDownEvent, _, cx| {
325+ cx.stop_propagation();
305 this.lanes_press(event.position.y, cx);326 this.lanes_press(event.position.y, cx);
306 }),327 }),
307 )328 )
329+ // A right press is a clip's menu anywhere
330+ // else on the bed; over the strip it is
331+ // nothing, and the clip beneath must not
332+ // answer it through the strip.
333+ .on_mouse_down(
334+ MouseButton::Right,
335+ |_: &MouseDownEvent, _, cx| cx.stop_propagation(),
336+ )
337+ .on_mouse_move(cx.listener(Player::drag_move))
338+ .on_mouse_up(
339+ MouseButton::Left,
340+ cx.listener(Player::drag_release),
341+ )
308 .child(342 .child(
309 div()343 div()
310 .absolute()344 .absolute()
@@ -367,14 +401,21 @@ impl Player {
367 })401 })
368 .into()402 .into()
369 })403 })
404+ // Both consumed here for the vertical strip's
405+ // reason: the row sits over nothing today, but
406+ // a press or a notch that fell through it
407+ // would be a gesture the strip drew and the
408+ // panel answered.
370 .on_scroll_wheel(cx.listener(409 .on_scroll_wheel(cx.listener(
371 |this, event: &ScrollWheelEvent, _, cx| {410 |this, event: &ScrollWheelEvent, _, cx| {
411+ cx.stop_propagation();
372 this.timeline_wheel(event, cx);412 this.timeline_wheel(event, cx);
373 },413 },
374 ))414 ))
375 .on_mouse_down(415 .on_mouse_down(
376 MouseButton::Left,416 MouseButton::Left,
377 cx.listener(|this, event: &MouseDownEvent, _, cx| {417 cx.listener(|this, event: &MouseDownEvent, _, cx| {
418+ cx.stop_propagation();
378 this.scroll_press(event.position.x, cx);419 this.scroll_press(event.position.x, cx);
379 }),420 }),
380 )421 )