forge
Explore
Log in

Don't you dare go Hollow

The wheel zooms and scrolls where the clips are

Browse files at this commit

a02176ee6caf70e82e216353353ded61cb63f568Ahmet Kaan GümüşParent: e17cd0a
  • feat
    • the wheel zooms and scrolls where the clips are
Show full message
✨ feat(timeline): the wheel zooms and scrolls where the clips are

Ctrl+wheel anywhere over the timeline -- a lane's bed, a clip's trim
strip, the ruler -- magnifies about the pointer, and a bare wheel slides
the view along it: the mapping every editor shares, on the surface a hand
is already aiming at. Only the 24 px ruler strip answered the wheel
before, and only with ctrl.

Three things had to be true for it to work at all:

- A bare notch is a tenth of what is on the bed (SCROLL_NOTCH_SHARE), so
  one gesture moves the same share of a five second import and of a film;
  View::scrolled clamps it against the content's own length.
- The follow no longer fires on a playhead nobody moved: a view yanked
  back every frame is a hand's own scroll undone before it is seen.
- gpui stops its hit test at an occluder, so the trim strips at a clip's
  ends took the wheel off the bed with them -- a dead strip exactly where
  a hand aims to see a cut closer. They answer with the same call now, and
  the lane column keeps the track names as its own scroll surface.

The keys and the buttons zoom exactly as they did.
crates/app/src/main.rsmodified+141 -2
@@ -2084,6 +2084,60 @@ impl Player {
2084 cx.notify();2084 cx.notify();
2085 }2085 }
2086 2086
2087+ /// Slides the view along the timeline by `notches` of the wheel, later in
2088+ /// time for a positive one and [`SCROLL_NOTCH_SHARE`] of the bed each. The
2089+ /// scale is untouched: this is the timeline's scrollbar, and the only thing
2090+ /// on the panel that moves what is on screen without magnifying it.
2091+ fn scroll_view(&mut self, notches: f32, cx: &mut Context<Self>) {
2092+ let view = self.view();
2093+ // Nothing painted yet: there is no bed to measure a notch against, and
2094+ // a start moved against a zero width would be a jump to the head.
2095+ if view.bed <= 0. {
2096+ return;
2097+ }
2098+ self.scale = view.scrolled(notches * view.bed * SCROLL_NOTCH_SHARE);
2099+ cx.notify();
2100+ }
2101+
2102+ /// One notch of the wheel anywhere over the timeline -- the ruler or a
2103+ /// lane's bed alike, since a hand aims at the clip it is working on and not
2104+ /// at the strip above it. Ctrl zooms about the pointer, bare scrolls the
2105+ /// view along: the mapping Premiere, Movavi and CapCut share, and the one
2106+ /// the user named.
2107+ ///
2108+ /// The anchor is measured off the ruler's probe wherever the pointer is,
2109+ /// because that probe *is* the bed's x-to-time mapping ([`HEADER_W`]) and
2110+ /// every lane is drawn through the same one.
2111+ fn timeline_wheel(&mut self, event: &ScrollWheelEvent, cx: &mut Context<Self>) {
2112+ let (dx, dy) = match event.delta {
2113+ ScrollDelta::Lines(d) => (d.x, d.y),
2114+ ScrollDelta::Pixels(d) => (f32::from(d.x), f32::from(d.y)),
2115+ };
2116+ // A tilt wheel's own axis counts as the same gesture: it is the
2117+ // sideways scroll a mouse that has one sends, and this panel's sideways
2118+ // is the only direction it has.
2119+ let d = match dy == 0. {
2120+ true => dx,
2121+ false => dy,
2122+ };
2123+ if d == 0. {
2124+ return;
2125+ }
2126+ let factor = match d > 0. {
2127+ true => ZOOM_STEP,
2128+ false => 1. / ZOOM_STEP,
2129+ };
2130+ match event.modifiers.control {
2131+ true => {
2132+ let anchor = px_along(event.position.x, self.ruler.get());
2133+ self.zoom(factor, Some(anchor), cx);
2134+ }
2135+ // Up is back towards the head of the timeline, the way a wheel up
2136+ // is back towards the top of a page.
2137+ false => self.scroll_view(-d.signum(), cx),
2138+ }
2139+ }
2140+
2087 /// Cycles the *project's* resolution through [`RESOLUTIONS`], starting from2141 /// Cycles the *project's* resolution through [`RESOLUTIONS`], starting from
2088 /// the media's own -- the one size that must stay reachable, since a project2142 /// the media's own -- the one size that must stay reachable, since a project
2089 /// moved off it has no other way back (the resolution is not an undo step).2143 /// moved off it has no other way back (the resolution is not an undo step).
@@ -5713,7 +5767,14 @@ impl Render for Player {
5713 // edit that shortens the timeline moves the far end of the view, and a5767 // edit that shortens the timeline moves the far end of the view, and a
5714 // playhead that has run off the bed pulls the view after it -- which is5768 // playhead that has run off the bed pulls the view after it -- which is
5715 // what makes a zoomed-in timeline scroll while it plays.5769 // what makes a zoomed-in timeline scroll while it plays.
5716- self.scale = self.view().following(position);5770+ // ...but only a playhead that is *going* somewhere pulls it: following
5771+ // is what a moving one does, during playback and through a seek. A view
5772+ // yanked back to a playhead nobody moved is a hand's own scroll undone
5773+ // by the very next frame, which is what made the wheel look dead.
5774+ self.scale = match state.is_playing() || self.seek_since.is_some() {
5775+ true => self.view().following(position),
5776+ false => self.view().settled(),
5777+ };
5717 5778
5718 div()5779 div()
5719 .track_focus(&self.focus)5780 .track_focus(&self.focus)
@@ -8799,6 +8860,13 @@ const TRANSPORT_H: f32 = CONTROL_H + 12.;
8799 /// One press of a zoom key, or one notch of ctrl+wheel.8860 /// One press of a zoom key, or one notch of ctrl+wheel.
8800 const ZOOM_STEP: f32 = 1.25;8861 const ZOOM_STEP: f32 = 1.25;
8801 8862
8863+/// How far one notch of a bare wheel slides the view along, as a share of what
8864+/// is on the bed. A *share* rather than a number of pixels or of seconds: one
8865+/// gesture then moves the same fraction of what is being looked at whether the
8866+/// bed is showing five seconds or five hours, which is the only way a wheel is
8867+/// usable at both ends of the zoom.
8868+const SCROLL_NOTCH_SHARE: f32 = 0.1;
8869+
8802 /// How few frames the bed may be narrowed down to. Past this there is nothing8870 /// How few frames the bed may be narrowed down to. Past this there is nothing
8803 /// left to aim at -- a single frame across a whole window is a wall of colour,8871 /// left to aim at -- a single frame across a whole window is a wall of colour,
8804 /// not an edit surface.8872 /// not an edit surface.
@@ -9017,6 +9085,24 @@ impl View {
9017 .settled()9085 .settled()
9018 }9086 }
9019 9087
9088+ /// Slid along by `by` pixels, later in the timeline for a positive one: the
9089+ /// one move that changes what is on the bed without changing how wide a
9090+ /// second is drawn, which is what a bare wheel does. Clamped by
9091+ /// [`View::settled`] like every other move, so a run at either end stops at
9092+ /// the end rather than scrolling the timeline off the bed -- and the extent
9093+ /// it stops against is the content's own length, never a number.
9094+ fn scrolled(self, by: f32) -> Scale {
9095+ let pps = self.settled().pps;
9096+ View {
9097+ scale: Scale {
9098+ pps,
9099+ start: self.scale.start + f64::from(by) / pps,
9100+ },
9101+ ..self
9102+ }
9103+ .settled()
9104+ }
9105+
9020 /// The whole timeline across the bed. The one place the content's own9106 /// The whole timeline across the bed. The one place the content's own
9021 /// length sets the scale, and the only one -- everywhere else a second is a9107 /// length sets the scale, and the only one -- everywhere else a second is a
9022 /// second -- because this is a user pressing a key that asks for exactly9108 /// second -- because this is a user pressing a key that asks for exactly
@@ -9949,7 +10035,7 @@ mod tests {
9949 FG_SECONDARY, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX,10035 FG_SECONDARY, KEYS_ROW_H, KEYS_ROWS_H, KEYS_W, KeyRow, LABEL_H, LABEL_MIN_W, LANE_H, LANES_MAX,
9950 BG_CANVAS, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H,10036 BG_CANVAS, LIBRARY_MAX_W, LIBRARY_MIN_W, Lane, MENU_ITEMS, MENU_PAD, MENU_ROW_H,
9951 MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MB_FLOOR, MENU_W, NO_FILE, NumberEdit, PANEL_H, ROW_ITEMS, RowCtx, RowItem,10037 MBPS_DIGITS, MBPS_MAX, MBPS_MIN, MB_FLOOR, MENU_W, NO_FILE, NumberEdit, PANEL_H, ROW_ITEMS, RowCtx, RowItem,
9952- Quality, ROW_H, RULER_HIT_H, BG_SELECTED, SILENCE_ROWS,10038+ Quality, ROW_H, RULER_HIT_H, BG_SELECTED, SCROLL_NOTCH_SHARE, SILENCE_ROWS,
9953 SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, BG_RAISED, SWATCH_W, Source, Speed, StreamInfo,10039 SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, BG_RAISED, SWATCH_W, Source, Speed, StreamInfo,
9954 Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, Wave, band_label,10040 Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, Wave, band_label,
9955 bitrate_detail, bitrate_refusal, can_add, cancels_export, clipboard_after_remove, color_snap, commit_mbps,10041 bitrate_detail, bitrate_refusal, can_add, cancels_export, clipboard_after_remove, color_snap, commit_mbps,
@@ -12227,6 +12313,59 @@ mod tests {
12227 assert!(view(wide, 2. * five_hours).zoomed(1. / ZOOM_STEP, 0.).pps < wide.pps);12313 assert!(view(wide, 2. * five_hours).zoomed(1. / ZOOM_STEP, 0.).pps < wide.pps);
12228 }12314 }
12229 12315
12316+ /// The bare wheel's own move: the view slides along the timeline, what is
12317+ /// drawn where slides with it, the scale never changes, and both ends stop
12318+ /// against the content rather than scrolling it off the bed.
12319+ #[test]
12320+ fn a_scroll_slides_the_view_without_zooming_it() {
12321+ let duration = 60.;
12322+ // Zoomed in far enough that there is somewhere to scroll to: 10 s of a
12323+ // 60 s timeline on the bed.
12324+ let start = test_view(
12325+ Scale {
12326+ pps: f64::from(TEST_BED) / 10.,
12327+ start: 0.,
12328+ },
12329+ duration,
12330+ )
12331+ .settled();
12332+ let notch = TEST_BED * SCROLL_NOTCH_SHARE;
12333+ let on = test_view(start, duration).scrolled(notch);
12334+ // A tenth of the bed later, and drawn a tenth of the bed to the left --
12335+ // the two halves of one move.
12336+ assert_eq!(on.pps, start.pps, "a scroll is not a zoom");
12337+ assert!(
12338+ (on.start - (start.start + 1.)).abs() < 1e-9,
12339+ "one notch is a tenth of the 10 s on the bed: {on:?}"
12340+ );
12341+ assert!(
12342+ (f64::from(start.px_at(20.) - on.px_at(20.)) - f64::from(notch)).abs() < 1e-3,
12343+ "and what was drawn moved with it: {on:?}"
12344+ );
12345+ // Back the other way, from the same place, is the same distance.
12346+ let back = test_view(on, duration).scrolled(-notch);
12347+ assert!((back.start - start.start).abs() < 1e-9, "{back:?}");
12348+ // Neither end can be scrolled off: the head stops at zero, and the tail
12349+ // stops with the last frame on the bed -- the clamp is the timeline's
12350+ // own length, not a number.
12351+ let mut scale = start;
12352+ for _ in 0..200 {
12353+ scale = test_view(scale, duration).scrolled(notch);
12354+ }
12355+ assert_eq!(scale.pps, start.pps);
12356+ assert!(
12357+ (scale.start - (duration - 10.)).abs() < 1e-6,
12358+ "the tail stops with the end on the bed: {scale:?}"
12359+ );
12360+ for _ in 0..200 {
12361+ scale = test_view(scale, duration).scrolled(-notch);
12362+ }
12363+ assert_eq!(scale.start, 0., "and the head stops at the head: {scale:?}");
12364+ // A view already showing all of it has nowhere to go.
12365+ let whole = test_view(Scale::default(), duration).fit();
12366+ assert_eq!(test_view(whole, duration).scrolled(notch), whole);
12367+ }
12368+
12230 /// What makes a zoomed timeline follow the playing head: off the bed at12369 /// What makes a zoomed timeline follow the playing head: off the bed at
12231 /// either end pulls the view onto it, and on the bed it never moves -- a12370 /// either end pulls the view onto it, and on the bed it never moves -- a
12232 /// view that jumped every frame would be unreadable.12371 /// view that jumped every frame would be unreadable.
crates/app/src/ui/timeline.rsmodified+41 -23
@@ -201,29 +201,19 @@ impl Player {
201 // The strip carries no text, so the tooltip is the only201 // The strip carries no text, so the tooltip is the only
202 // place it can say what it is.202 // place it can say what it is.
203 .tooltip(|_, cx| {203 .tooltip(|_, cx| {
204- cx.new(|_| Tip("Seek — click or drag; ctrl+wheel zooms".into()))204+ cx.new(|_| {
205- .into()205+ Tip("Seek — click or drag; wheel scrolls, ctrl+wheel zooms"
206+ .into())
207+ })
208+ .into()
206 })209 })
207- // Ctrl+wheel is what every timeline zooms with, and210+ // Ctrl+wheel zooms about the pointer and a bare one
208- // the point held still is the one under the pointer211+ // scrolls the view along -- [`Player::timeline_wheel`],
209- // rather than the playhead. Only with ctrl: a bare212+ // the same answer the lanes below give, because a
210- // wheel here is the window's to scroll, and the213+ // hand does not aim at a strip to zoom a timeline.
211- // controls row above scrolls on exactly that.
212 .on_scroll_wheel(cx.listener(214 .on_scroll_wheel(cx.listener(
213 |this, event: &ScrollWheelEvent, _, cx| {215 |this, event: &ScrollWheelEvent, _, cx| {
214- if !event.modifiers.control {216+ this.timeline_wheel(event, cx);
215- return;
216- }
217- let dy = match event.delta {
218- ScrollDelta::Lines(d) => d.y,
219- ScrollDelta::Pixels(d) => f32::from(d.y),
220- };
221- if dy == 0. {
222- return;
223- }
224- let anchor = px_along(event.position.x, this.ruler.get());
225- let factor = if dy > 0. { ZOOM_STEP } else { 1. / ZOOM_STEP };
226- this.zoom(factor, Some(anchor), cx);
227 },217 },
228 ))218 ))
229 .on_mouse_down(219 .on_mouse_down(
@@ -292,9 +282,12 @@ impl Player {
292 _ => ACCENT_PRIMARY(),282 _ => ACCENT_PRIMARY(),
293 }))283 }))
294 .child(match below {284 .child(match below {
295- 0 => "the last track — scroll up for the rest".to_string(),285+ // Over the track names, not over the beds: a wheel
296- 1 => "1 more track below — scroll the lanes".to_string(),286+ // on a bed moves the *view* along the timeline now,
297- n => format!("{n} more tracks below — scroll the lanes"),287+ // so the column names its own scroll surface.
288+ 0 => "the last track — scroll the names for the rest".to_string(),
289+ 1 => "1 more track below — scroll the track names".to_string(),
290+ n => format!("{n} more tracks below — scroll the track names"),
298 }),291 }),
299 )292 )
300 })293 })
@@ -874,6 +867,18 @@ impl Player {
874 .rounded(px(3.))867 .rounded(px(3.))
875 .bg(rgb(BG_TIMELINE()))868 .bg(rgb(BG_TIMELINE()))
876 .overflow_hidden()869 .overflow_hidden()
870+ // The wheel over the clips themselves, which is where a
871+ // hand already is: ctrl zooms about the pointer, bare
872+ // scrolls the view along ([`Player::timeline_wheel`]).
873+ // Stopped here, because gpui runs the lane *column's* own
874+ // overflow scroll on the same notch (div.rs:2403) and a
875+ // gesture that slid the view sideways and the tracks upward
876+ // at once is two answers to one notch. The track headers
877+ // beside this bed are still the column's scroll surface.
878+ .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| {
879+ cx.stop_propagation();
880+ this.timeline_wheel(event, cx);
881+ }))
877 // A library row let go over a lane is the same insert the882 // A library row let go over a lane is the same insert the
878 // Add button makes, through the same call -- but where the883 // Add button makes, through the same call -- but where the
879 // pointer let it go, not at the playhead: a hand that884 // pointer let it go, not at the playhead: a hand that
@@ -1102,6 +1107,19 @@ impl Player {
1102 },1107 },
1103 ),1108 ),
1104 )1109 )
1110+ // ...and occluding takes the *wheel* off
1111+ // the lane's bed with it (gpui stops the
1112+ // hit test at an occluder, ancestors
1113+ // included), so a notch aimed at a cut --
1114+ // the one place a hand aims when it wants
1115+ // to see a cut closer -- would be a dead
1116+ // strip. The same answer as the bed's.
1117+ .on_scroll_wheel(cx.listener(
1118+ |this, event: &ScrollWheelEvent, _, cx| {
1119+ cx.stop_propagation();
1120+ this.timeline_wheel(event, cx);
1121+ },
1122+ ))
1105 // Occluded, so the box's own right-button1123 // Occluded, so the box's own right-button
1106 // listener never fires here: the menu is1124 // listener never fires here: the menu is
1107 // the same menu, opened by the same call.1125 // the same menu, opened by the same call.
crates/app/src/ui/toolbar.rsmodified+2 -1
@@ -391,7 +391,8 @@ impl Player {
391 BG_RAISED(),391 BG_RAISED(),
392 None,392 None,
393 "+",393 "+",
394- "magnify around the playhead; ctrl+wheel on the ruler zooms at the pointer",394+ "magnify around the playhead; ctrl+wheel over the timeline zooms at the \
395+ pointer, and a bare wheel scrolls it",
395 ActionId::ZoomIn,396 ActionId::ZoomIn,
396 cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)),397 cx.listener(|this, _: &ClickEvent, _, cx| this.zoom(ZOOM_STEP, None, cx)),
397 ))398 ))