forge
Explore
Log in

Don't you dare go Hollow

A scrollbar under the lanes

Browse files at this commit

c707e9d1d1545ac0b32bf89465ce06eb040b42e4Ahmet Kaan GümüşParent: a3dc07c
  • feat
    • a scrollbar under the lanes
Show full message
✨ feat(timeline): a scrollbar under the lanes

The time axis was the one dimension the panel scrolled with no bar to
scroll it by -- only the wheel and the keys reached it. A strip under
the lanes now carries a thumb that is the visible share of the drawn
duration at its own place on the track: read off the very Scale every
box is drawn through, so a wheel notch, a zoom about the pointer and
the follow of the playhead all move it, because they all move the one
state.

Drag the thumb and the view follows live (the pointer leaves the 6 px
strip at once, so the gesture is followed on the root like a scrub);
press beside it and the view jumps to the press and carries on from
there; the wheel still works over it. The strip is its own mouse
region -- a press there never reaches a lane -- and with nothing to
scroll the thumb fills the track and dims.
crates/app/src/interact.rsmodified+10 -0
@@ -216,6 +216,16 @@ pub(crate) fn swallow(_: &MouseDownEvent, _: &mut Window, cx: &mut App) {
216 /// takes must still be able to leave a gap of a few frames there.216 /// takes must still be able to leave a gap of a few frames there.
217 pub(crate) const SNAP_PX: f64 = 5.;217 pub(crate) const SNAP_PX: f64 = 5.;
218 218
219+/// The scrollbar's thumb never narrows past this, however long the timeline:
220+/// a thumb a pixel wide is a thumb no hand can hold. A quarter of the ruler's
221+/// own seek strip, which is the idiom it sits under.
222+pub(crate) const SCROLL_THUMB_MIN: f32 = 24.;
223+
224+/// The scrollbar track's own hit height: the bar looks 6 px tall, and the
225+/// strip that takes the press is taller for the ruler strip's reason -- a
226+/// hand must be able to find it without aiming (WCAG 2.5.8).
227+pub(crate) const SCROLL_HIT_H: f32 = 14.;
228+
219 /// Where a held key would land, which is the whole of what auto-repeat has to229 /// Where a held key would land, which is the whole of what auto-repeat has to
220 /// know. [`Player::repeat_scope`] answers it from the same state the handler230 /// know. [`Player::repeat_scope`] answers it from the same state the handler
221 /// walks below itself.231 /// walks below itself.
crates/app/src/main.rsmodified+10 -2
@@ -103,6 +103,13 @@ struct Player {
103 /// The ruler's own box, recorded at prepaint: a mouse listener is handed103 /// The ruler's own box, recorded at prepaint: a mouse listener is handed
104 /// the window position and nothing else.104 /// the window position and nothing else.
105 ruler: Rc<Cell<Bounds<Pixels>>>,105 ruler: Rc<Cell<Bounds<Pixels>>>,
106+ /// The scrollbar track's laid-out box, recorded at prepaint like the
107+ /// ruler's: a thumb drag is followed on the root (the pointer leaves the
108+ /// strip at once), and the root has only window coordinates to work with.
109+ scroll_track: Rc<Cell<Bounds<Pixels>>>,
110+ /// A thumb in the hand: how far into the thumb the press landed, in
111+ /// track pixels. `None` with no drag in flight.
112+ scroll_drag: Option<f32>,
106 /// How wide a second of timeline is drawn, and from which moment. Held here113 /// How wide a second of timeline is drawn, and from which moment. Held here
107 /// and nowhere else: every frame-to-pixel answer in the panel comes out of114 /// and nowhere else: every frame-to-pixel answer in the panel comes out of
108 /// it, so the boxes, the playhead and the pointer cannot disagree.115 /// it, so the boxes, the playhead and the pointer cannot disagree.
@@ -646,14 +653,15 @@ fn main() {
646 // Only ever used with a timeline; 30 keeps the empty653 // Only ever used with a timeline; 30 keeps the empty
647 // timecode reading in frames rather than in NaN.654 // timecode reading in frames rather than in NaN.
648 fps: 30.,655 fps: 30.,
649- // The file being opened, from the first frame the window656+ ruler: Rc::default(),
657+ scroll_track: Rc::default(),
658+ scroll_drag: None,
650 // draws: the title bar and the header name it while its659 // draws: the title bar and the header name it while its
651 // header is still being read.660 // header is still being read.
652 name: name.clone(),661 name: name.clone(),
653 image: None,662 image: None,
654 sub_image: None,663 sub_image: None,
655 held: None,664 held: None,
656- ruler: Rc::default(),
657 notice_h: Rc::default(),665 notice_h: Rc::default(),
658 // A second is [`PPS_DEFAULT`] pixels wide until someone666 // A second is [`PPS_DEFAULT`] pixels wide until someone
659 // zooms or asks for the fit: a project opens at a scale, not667 // zooms or asks for the fit: a project opens at a scale, not
crates/app/src/player/timeline_edit.rsmodified+18 -0
@@ -1298,6 +1298,20 @@ impl Player {
1298 window: &mut Window,1298 window: &mut Window,
1299 cx: &mut Context<Self>,1299 cx: &mut Context<Self>,
1300 ) {1300 ) {
1301+ // The scrollbar's thumb first: the pointer leaves the 6 px strip on
1302+ // the first move, so the gesture is followed here for the ruler's own
1303+ // reason -- and it must outrank every other drag, because a hand
1304+ // holding the view is not holding anything on it.
1305+ if self.scroll_drag.is_some() {
1306+ match event.pressed_button {
1307+ Some(MouseButton::Left) => self.scroll_drag_to(event.position.x, cx),
1308+ // A release outside the window never reaches the handler
1309+ // below, so the first button-up move is when we learn the
1310+ // drag is over.
1311+ _ => self.scroll_drag = None,
1312+ }
1313+ return;
1314+ }
1301 // A divider is answered before every gesture below it: it is pressed on1315 // A divider is answered before every gesture below it: it is pressed on
1302 // a strip of its own that nothing else is under, so neither can swallow1316 // a strip of its own that nothing else is under, so neither can swallow
1303 // the other -- a seam over the timeline never scrubs, and a scrub is1317 // the other -- a seam over the timeline never scrubs, and a scrub is
@@ -1399,6 +1413,10 @@ impl Player {
1399 ) {1413 ) {
1400 // The panel is left exactly where the hand let go, for the reason every1414 // The panel is left exactly where the hand let go, for the reason every
1401 // other release here lands one last sample.1415 // other release here lands one last sample.
1416+ if self.scroll_drag.take().is_some() {
1417+ self.scroll_drag_to(event.position.x, cx);
1418+ return;
1419+ }
1402 if let Some(split) = self.split_drag.take() {1420 if let Some(split) = self.split_drag.take() {
1403 self.drag_split(split, event.position, window, cx);1421 self.drag_split(split, event.position, window, cx);
1404 return;1422 return;
crates/app/src/player/view.rsmodified+61 -0
@@ -238,6 +238,67 @@ impl Player {
238 cx.notify();238 cx.notify();
239 }239 }
240 240
241+ /// A press on the scrollbar's track: on the thumb, the drag begins from
242+ /// wherever in it the hand landed; beside it, the view jumps so the
243+ /// thumb's middle is at the press and the drag carries on from there --
244+ /// a click is a jump, and holding it is a jump that keeps going.
245+ pub(crate) fn scroll_press(&mut self, x: Pixels, cx: &mut Context<Self>) {
246+ let view = self.view();
247+ if view.bed <= 0. || view.duration <= 0. {
248+ return;
249+ }
250+ let (thumb_x, thumb_w) =
251+ scroll_thumb(view.bed, view.duration, view.scale.start.max(0.), view.span());
252+ let at = px_along(x, self.scroll_track.get());
253+ let grab = match (thumb_x..thumb_x + thumb_w).contains(&at) {
254+ true => at - thumb_x,
255+ // Beside the thumb: jump so its middle is under the pointer. The
256+ // thumb is clamped inside the track by [`scroll_thumb`], so the
257+ // grab it leaves is always a real place inside it.
258+ false => {
259+ let view = View {
260+ scale: Scale {
261+ start: (view.scale.start.max(0.)
262+ + f64::from(at - thumb_x - thumb_w / 2.) / view.scale.pps)
263+ .max(0.),
264+ ..view.scale
265+ },
266+ ..view
267+ };
268+ self.scale = view.settled();
269+ thumb_w / 2.
270+ }
271+ };
272+ self.scroll_drag = Some(grab);
273+ // The wheel's own claim on the follow: a hand on the scrollbar is
274+ // looking away from the playhead on purpose.
275+ self.panned = true;
276+ cx.notify();
277+ }
278+
279+ /// A sample of a thumb drag: the window starts where the thumb's grabbed
280+ /// point sits under the pointer, clamped by the same `settled` every other
281+ /// scroll answers to. No reseek, no worker -- the view is the only thing
282+ /// moving.
283+ pub(crate) fn scroll_drag_to(&mut self, x: Pixels, cx: &mut Context<Self>) {
284+ let Some(grab) = self.scroll_drag else {
285+ return;
286+ };
287+ let view = self.view();
288+ let at = px_along(x, self.scroll_track.get());
289+ // The thumb's grabbed point under the pointer names the start, in the
290+ // track's own proportion. `settled` owns the ends -- and on a timeline
291+ // so long the thumb sits at its floor width, the last stretch of track
292+ // is the clamp's to hold, exactly as every scrollbar's is.
293+ let start = f64::from((at - grab).max(0.)) / f64::from(view.bed.max(1.)) * view.duration;
294+ self.scale = View {
295+ scale: Scale { start, ..view.scale },
296+ ..view
297+ }
298+ .settled();
299+ cx.notify();
300+ }
301+
241 /// One notch of the wheel anywhere over the timeline -- the ruler or a302 /// One notch of the wheel anywhere over the timeline -- the ruler or a
242 /// lane's bed alike, since a hand aims at the clip it is working on and not303 /// lane's bed alike, since a hand aims at the clip it is working on and not
243 /// at the strip above it. Ctrl zooms about the pointer, bare scrolls the304 /// at the strip above it. Ctrl zooms about the pointer, bare scrolls the
crates/app/src/tests/layout.rsmodified+23 -0
@@ -266,6 +266,29 @@ fn a_lane_row_is_a_fixed_header_and_a_bed_that_can_be_hit() {
266 assert_eq!(lanes_h(2), 2. * LANE_H + 8.);266 assert_eq!(lanes_h(2), 2. * LANE_H + 8.);
267 }267 }
268 268
269+/// The scrollbar's thumb: the visible share of the timeline at its own
270+/// place on the track, full width with nothing to scroll, never narrower than
271+/// a hand can hold, and never off the ends.
272+#[test]
273+fn the_scroll_thumb_is_the_visible_share_at_its_own_place() {
274+ use crate::scroll_thumb;
275+ use crate::SCROLL_THUMB_MIN;
276+
277+ // Nothing to scroll: the strip fills and says so.
278+ assert_eq!(scroll_thumb(400., 10., 0., 12.), (0., 400.));
279+ assert_eq!(scroll_thumb(400., 0., 0., 0.), (0., 400.));
280+ // Half the timeline on the bed: a half-width thumb, halfway along for a
281+ // window starting halfway in.
282+ assert_eq!(scroll_thumb(400., 20., 0., 10.), (0., 200.));
283+ assert_eq!(scroll_thumb(400., 20., 10., 10.), (200., 200.));
284+ // The floor width: however long the timeline, the thumb stays holdable --
285+ // and the clamp keeps it on the track, not the caller.
286+ let (x, w) = scroll_thumb(400., 1_000_000., 999_000., 100.);
287+ assert_eq!(w, SCROLL_THUMB_MIN);
288+ assert_eq!(x, 400. - SCROLL_THUMB_MIN);
289+ assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.);
290+}
291+
269 /// A caption's box wears the rate its window plays at, derived off the292 /// A caption's box wears the rate its window plays at, derived off the
270 /// placement itself: unity placements -- including odd widths whose frames293 /// placement itself: unity placements -- including odd widths whose frames
271 /// came off `frames_of_us` rounding -- do not badge, and a re-rate does, with294 /// came off `frames_of_us` rounding -- do not badge, and a re-rate does, with
crates/app/src/timeline_math.rsmodified+22 -0
@@ -182,6 +182,28 @@ pub(crate) fn caption_rate(sub: SubClip, fps: f64) -> Option<Speed> {
182 ))182 ))
183 }183 }
184 184
185+/// The scrollbar's thumb over a track `w` px wide: `(x, width)` of the box
186+/// standing for the visible share of a timeline `duration` long whose window
187+/// starts at `start` and spans `span`. Full width when nothing is off-screen
188+/// (there is nothing to scroll and the strip says so by filling), never
189+/// narrower than [`SCROLL_THUMB_MIN`] when there is (a thumb a pixel wide is a
190+/// thumb no hand can hold), and never off the track either way -- the clamp,
191+/// not the caller, owns that, because a drag's samples arrive raw.
192+pub(crate) fn scroll_thumb(
193+ w: f32,
194+ duration: f64,
195+ start: f64,
196+ span: f64,
197+) -> (f32, f32) {
198+ if w <= 0. || duration <= 0. || span >= duration {
199+ return (0., w.max(0.));
200+ }
201+ let share = f64::from(w);
202+ let width = ((span / duration) * share).clamp(f64::from(SCROLL_THUMB_MIN), f64::from(w));
203+ let x = (start / duration * share).clamp(0., f64::from(w) - width);
204+ (x as f32, width as f32)
205+}
206+
185 impl Selection {207 impl Selection {
186 pub(crate) fn len(&self) -> usize {208 pub(crate) fn len(&self) -> usize {
187 self.picks.len()209 self.picks.len()
crates/app/src/ui/timeline.rsmodified+76 -0
@@ -89,6 +89,13 @@ impl Player {
89 true => (lanes_box - LABEL_H - 8.).max(LANE_H),89 true => (lanes_box - LABEL_H - 8.).max(LANE_H),
90 false => lanes_box,90 false => lanes_box,
91 };91 };
92+ // The scrollbar's geometry, off the very view the wheel and the zoom
93+ // write: `settled` is what those paths clamp to, so the thumb never
94+ // disagrees with where the panel actually is.
95+ let view = self.view();
96+ let scrollable = view.duration > view.span();
97+ let (thumb_x, thumb_w) =
98+ scroll_thumb(view.bed, view.duration, view.scale.start.max(0.), view.span());
92 // Live, not a count of the lanes: the column reports where it has been99 // Live, not a count of the lanes: the column reports where it has been
93 // taken to, so the line empties itself as the last track comes up100 // taken to, so the line empties itself as the last track comes up
94 // instead of insisting there is still something below.101 // instead of insisting there is still something below.
@@ -230,6 +237,75 @@ impl Player {
230 .track_scroll(&self.lanes_scroll)237 .track_scroll(&self.lanes_scroll)
231 .children(rows),238 .children(rows),
232 )239 )
240+ // The timeline's own scrollbar: the time axis is the one dimension
241+ // the panel scrolls, and until now only the wheel and the keys
242+ // reached it. The thumb is the visible share of the drawn duration
243+ // and sits where that share is -- read off the very `Scale` every
244+ // box is drawn through, so a wheel notch, a zoom about the pointer
245+ // and the follow of the playhead all move it, because they all move
246+ // the one state.
247+ .child(
248+ div()
249+ .flex_none()
250+ .flex()
251+ .gap(px(HEADER_GAP))
252+ // Under the lane headers like the ruler is above them, so
253+ // the thumb and the bed it stands for line up.
254+ .child(div().flex_none().w(px(HEADER_W)))
255+ .child(
256+ div()
257+ .id("timeline-scroll")
258+ .flex_1()
259+ .min_w(px(0.))
260+ .h(px(SCROLL_HIT_H))
261+ .flex()
262+ .flex_col()
263+ .justify_center()
264+ .rounded(px(3.))
265+ .cursor_pointer()
266+ .hover(|s| s.bg(rgb(BG_HOVER_DIM())))
267+ .tooltip(|_, cx| {
268+ cx.new(|_| {
269+ Tip("Scroll the timeline — drag the thumb or click to jump; \
270+ wheel scrolls, ctrl+wheel zooms"
271+ .into())
272+ })
273+ .into()
274+ })
275+ .on_scroll_wheel(cx.listener(
276+ |this, event: &ScrollWheelEvent, _, cx| {
277+ this.timeline_wheel(event, cx);
278+ },
279+ ))
280+ .on_mouse_down(
281+ MouseButton::Left,
282+ cx.listener(|this, event: &MouseDownEvent, _, cx| {
283+ this.scroll_press(event.position.x, cx);
284+ }),
285+ )
286+ .child(
287+ div()
288+ .w_full()
289+ .h(px(6.))
290+ .rounded(px(3.))
291+ .bg(rgb(BG_RAISED()))
292+ .child(bounds_probe(self.scroll_track.clone()))
293+ .child(
294+ div()
295+ .h_full()
296+ .rounded(px(3.))
297+ .left(px(thumb_x))
298+ .absolute()
299+ .top_0()
300+ .w(px(thumb_w))
301+ .bg(rgb(match scrollable {
302+ true => ACCENT_PRIMARY(),
303+ false => FG_SECONDARY(),
304+ })),
305+ ),
306+ ),
307+ ),
308+ )
233 // "It scrolls" is not "it can be found": when the region is too309 // "It scrolls" is not "it can be found": when the region is too
234 // short for every track -- which is what the 640x360 floor does to a310 // short for every track -- which is what the 640x360 floor does to a
235 // three-track project -- the lanes below the fold say so, in the one311 // three-track project -- the lanes below the fold say so, in the one