forge
Explore
Log in

Don't you dare go Hollow

The scrollbar is only there while there is somewhere to go

Browse files at this commit

dd77ab098a61bce21a33947f37ee101d7d60cb9aAhmet Kaan GümüşParent: 4bd886f
  • feat
    • the scrollbar is only there while there is somewhere to go
Show full message
✨ feat(timeline): the scrollbar is only there while there is somewhere to go

Zoomed out to the whole timeline the horizontal strip was furniture for
a view that cannot move: a dim full-width thumb under the lanes, holding
its row whether anyone could use it or not. The strip now vanishes at
the fit -- and its row goes with it, out of every budget at once. The
budget grew a door: timeline_fixed_h(scroll) answers the region
(timeline_h), the fold the lanes are laid out against and the seam's
drag floor together, so the three cannot disagree about whether the
strip is there, and the lanes keep exactly the room they had at either
side of the zoom that crosses the line. The share stays sized for the
taller, strip-bearing floor -- the one the clamp would otherwise
overrule at the 640x360 floor.

The lane stack gets its own bar too, over the beds' right edge -- over
and not beside, because a gutter would take its width off the bed and
the ruler above would stop pointing at the moment the lanes are drawn
at. The thumb is the visible share of the rows, read straight off the
column's own scroll handle -- box, fold and how far down it has been
taken are all the handle's to know, so nothing about the stack is a
second truth -- and a drag is followed on the root like every gesture
that outlives its strip. Names and beds are one column, so they move
together; the wheel over the strip scrolls the stack a notch's share of
what it is showing, and with the whole stack on screen there is no
strip at all.
crates/app/src/interact.rsmodified+6 -4
@@ -221,10 +221,12 @@ pub(crate) const SNAP_PX: f64 = 5.;
221221 /// own seek strip, which is the idiom it sits under.
222222 pub(crate) const SCROLL_THUMB_MIN: f32 = 24.;
223223
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.;
224+/// The thickness of a scrollbar strip's hit area, in the one dimension the
225+/// strip spans: the height of the horizontal one under the lanes, the width
226+/// of the vertical one on the beds' right edge. The bar inside it looks 6 px,
227+/// and the strip that takes the press is thicker for the ruler strip's
228+/// reason -- a hand must be able to find it without aiming (WCAG 2.5.8).
229+pub(crate) const SCROLL_HIT: f32 = 14.;
228230
229231 /// Where a held key would land, which is the whole of what auto-repeat has to
230232 /// know. [`Player::repeat_scope`] answers it from the same state the handler
crates/app/src/layout.rsmodified+28 -16
@@ -389,20 +389,27 @@ impl Splits {
389389 /// region rather than a sliver. Neither end is passable -- a panel dragged to
390390 /// nothing is a panel nobody can get back, and a picture squeezed out by two
391391 /// side columns is the same loss on the other side of the window.
392-pub(crate) fn split_bounds(split: Split, lanes: usize, window: Size<Pixels>) -> (f32, f32) {
392+pub(crate) fn split_bounds(
393+ split: Split,
394+ lanes: usize,
395+ window: Size<Pixels>,
396+ scroll: bool,
397+) -> (f32, f32) {
393398 let (w, h) = (f32::from(window.width), f32::from(window.height));
394399 match split {
395400 Split::Library => (LIBRARY_MIN_W, w * SIDE_MAX_FRAC),
396401 Split::Inspector => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC),
397- // One whole lane under the chrome: a timeline shorter than that is a
398- // ruler with nothing beneath it. A second track pays for the line that
399- // says the rest are below the fold as well -- at this height only one
400- // row fits, so that line is *always* drawn there, and it is drawn
401- // inside the region ([`Player::timeline`]). Left out of the floor it
402- // comes off the lane's own pixels, and the one lane the floor promises
403- // is a header cut in half.
402+ // One whole lane under the chrome, the scrollbar strip's row included
403+ // while there is one to draw ([`timeline_fixed_h`]): a timeline
404+ // shorter than that is a ruler with nothing beneath it. A second
405+ // track pays for the line that says the rest are below the fold as
406+ // well -- at this height only one row fits, so that line is *always*
407+ // drawn there, and it is drawn inside the region
408+ // ([`Player::timeline`]). Left out of the floor it comes off the
409+ // lane's own pixels, and the one lane the floor promises is a header
410+ // cut in half.
404411 Split::Timeline => (
405- TIMELINE_FIXED_H
412+ timeline_fixed_h(scroll)
406413 + LANE_H
407414 + match lanes > 1 {
408415 true => LABEL_H + 8.,
@@ -413,22 +420,19 @@ pub(crate) fn split_bounds(split: Split, lanes: usize, window: Size<Pixels>) ->
413420 }
414421 }
415422
416-/// How big the panel at this seam is drawn: what the hand dragged it to, held
417-/// inside the window *being drawn now* -- the window is resizable, and a width
418-/// set at 1920 px is not a width at 640 -- or the share the untouched layout
419-/// gives it.
420423 pub(crate) fn split_size(
421424 split: Split,
422425 set: Option<f32>,
423426 lanes: usize,
424427 window: Size<Pixels>,
428+ scroll: bool,
425429 ) -> f32 {
426430 let (w, h) = (f32::from(window.width), f32::from(window.height));
427- let (min, max) = split_bounds(split, lanes, window);
431+ let (min, max) = split_bounds(split, lanes, window, scroll);
428432 let default = match split {
429433 Split::Library => library_w(w),
430434 Split::Inspector => inspector_w(w),
431- Split::Timeline => timeline_h(lanes).min(h * TIMELINE_SHARE),
435+ Split::Timeline => timeline_h(lanes, scroll).min(h * TIMELINE_SHARE),
432436 };
433437 // The floor wins a window too small to honour both ends: a panel at its
434438 // floor is still a panel, and `clamp` panics outright on a ceiling under
@@ -463,6 +467,14 @@ impl Player {
463467 .session
464468 .as_ref()
465469 .map_or(2, |session| session.lanes().len());
466- split_size(split, self.splits.get(split), lanes, window)
470+ // Whether the time axis has anywhere to go: the scrollbar strip is
471+ // drawn only while it does, and the region's furniture -- and its
472+ // floor -- carry the strip's row only while it is. One door
473+ // ([`timeline_fixed_h`]) answers the region, the fold and the floor
474+ // together, so the three cannot disagree about whether the strip is
475+ // there.
476+ let view = self.view();
477+ let scroll = view.duration > view.span();
478+ split_size(split, self.splits.get(split), lanes, window, scroll)
467479 }
468480 }
crates/app/src/main.rsmodified+7 -0
@@ -110,6 +110,12 @@ struct Player {
110110 /// A thumb in the hand: how far into the thumb the press landed, in
111111 /// track pixels. `None` with no drag in flight.
112112 scroll_drag: Option<f32>,
113+ /// A thumb of the lane stack's own scrollbar in the hand: how far into
114+ /// the thumb the press landed, in track pixels. `None` with no drag in
115+ /// flight. The stack's box itself is read straight off the scroll handle
116+ /// each frame, so unlike the time axis's strip it needs no probe of its
117+ /// own.
118+ lanes_drag: Option<f32>,
113119 /// How wide a second of timeline is drawn, and from which moment. Held here
114120 /// and nowhere else: every frame-to-pixel answer in the panel comes out of
115121 /// it, so the boxes, the playhead and the pointer cannot disagree.
@@ -656,6 +662,7 @@ fn main() {
656662 ruler: Rc::default(),
657663 scroll_track: Rc::default(),
658664 scroll_drag: None,
665+ lanes_drag: None,
659666 // draws: the title bar and the header name it while its
660667 // header is still being read.
661668 name: name.clone(),
crates/app/src/player/timeline_edit.rsmodified+15 -0
@@ -1312,6 +1312,17 @@ impl Player {
13121312 }
13131313 return;
13141314 }
1315+ // The lane stack's own thumb, on exactly the same terms: the pointer
1316+ // leaves the strip on the first move, so the root carries the gesture
1317+ // -- and a hand holding the stack is not holding anything on it
1318+ // either.
1319+ if self.lanes_drag.is_some() {
1320+ match event.pressed_button {
1321+ Some(MouseButton::Left) => self.lanes_drag_to(event.position.y, cx),
1322+ _ => self.lanes_drag = None,
1323+ }
1324+ return;
1325+ }
13151326 // A divider is answered before every gesture below it: it is pressed on
13161327 // a strip of its own that nothing else is under, so neither can swallow
13171328 // the other -- a seam over the timeline never scrubs, and a scrub is
@@ -1417,6 +1428,10 @@ impl Player {
14171428 self.scroll_drag_to(event.position.x, cx);
14181429 return;
14191430 }
1431+ if self.lanes_drag.take().is_some() {
1432+ self.lanes_drag_to(event.position.y, cx);
1433+ return;
1434+ }
14201435 if let Some(split) = self.split_drag.take() {
14211436 self.drag_split(split, event.position, window, cx);
14221437 return;
crates/app/src/player/view.rsmodified+78 -0
@@ -299,6 +299,84 @@ impl Player {
299299 cx.notify();
300300 }
301301
302+ /// The lane stack's own scroll, as one number: how far down the column
303+ /// has been taken, clamped to what it can show. The names and the beds
304+ /// are one column (`id("lanes")`), so one offset moves them together and
305+ /// this is the whole of the stack's scrolling -- the wheel over the names
306+ /// and the thumb on the strip both land here.
307+ fn lanes_taken(&self, to: f32) -> f32 {
308+ let max = f32::from(self.lanes_scroll.max_offset().height);
309+ to.clamp(0., max)
310+ }
311+
312+ /// A press on the lane stack's scrollbar: on the thumb, the drag begins
313+ /// from wherever in it the hand landed; beside it, the stack jumps so the
314+ /// thumb's middle is at the press and the drag carries on from there --
315+ /// the time axis's own terms ([`Self::scroll_press`]), turned through a
316+ /// right angle.
317+ pub(crate) fn lanes_press(&mut self, y: Pixels, cx: &mut Context<Self>) {
318+ let track = f32::from(self.lanes_scroll.bounds().size.height);
319+ let max = f32::from(self.lanes_scroll.max_offset().height);
320+ if track <= 0. || max <= 0. {
321+ return;
322+ }
323+ let scrolled = -f32::from(self.lanes_scroll.offset().y);
324+ let (thumb_y, thumb_h) = lanes_thumb(track, track + max, track, scrolled);
325+ let at = px_down(y, self.lanes_scroll.bounds());
326+ let grab = match (thumb_y..thumb_y + thumb_h).contains(&at) {
327+ true => at - thumb_y,
328+ // Beside the thumb: jump so its middle is under the pointer, at
329+ // the press's own share of the stack. The thumb is clamped inside
330+ // the track by [`lanes_thumb`], so the grab this leaves is always
331+ // a real place inside it.
332+ false => {
333+ let to = self.lanes_taken(
334+ (at - thumb_h / 2.).max(0.) / (track - thumb_h).max(1.) * max,
335+ );
336+ self.lanes_scroll
337+ .set_offset(point(self.lanes_scroll.offset().x, px(-to)));
338+ thumb_h / 2.
339+ }
340+ };
341+ self.lanes_drag = Some(grab);
342+ cx.notify();
343+ }
344+
345+ /// A sample of the lane thumb's drag: the stack is taken to where the
346+ /// thumb's grabbed point sits under the pointer, clamped by the same
347+ /// `max_offset` the column's own wheel answers to. No reseek, no repaint
348+ /// of anything outside the column -- the view is not moving.
349+ pub(crate) fn lanes_drag_to(&mut self, y: Pixels, cx: &mut Context<Self>) {
350+ let Some(grab) = self.lanes_drag else {
351+ return;
352+ };
353+ let track = f32::from(self.lanes_scroll.bounds().size.height);
354+ let max = f32::from(self.lanes_scroll.max_offset().height);
355+ let (_, thumb_h) = lanes_thumb(track, track + max, track, 0.);
356+ let at = px_down(y, self.lanes_scroll.bounds());
357+ let to = self.lanes_taken((at - grab).max(0.) / (track - thumb_h).max(1.) * max);
358+ self.lanes_scroll
359+ .set_offset(point(self.lanes_scroll.offset().x, px(-to)));
360+ cx.notify();
361+ }
362+
363+ /// One notch of the wheel over the lane stack's strip: the stack moves a
364+ /// share of what it is showing, the same share the time axis gives a
365+ /// notch of its own -- the strip is the names' scroll surface, and this
366+ /// is what a wheel there did already.
367+ pub(crate) fn lanes_wheel(&mut self, notches: f32, cx: &mut Context<Self>) {
368+ let track = f32::from(self.lanes_scroll.bounds().size.height);
369+ let max = f32::from(self.lanes_scroll.max_offset().height);
370+ if track <= 0. || max <= 0. {
371+ return;
372+ }
373+ let scrolled = -f32::from(self.lanes_scroll.offset().y);
374+ let to = self.lanes_taken(scrolled - notches * track * SCROLL_NOTCH_SHARE);
375+ self.lanes_scroll
376+ .set_offset(point(self.lanes_scroll.offset().x, px(-to)));
377+ cx.notify();
378+ }
379+
302380 /// One notch of the wheel anywhere over the timeline -- the ruler or a
303381 /// lane's bed alike, since a hand aims at the clip it is working on and not
304382 /// at the strip above it. Ctrl zooms about the pointer, bare scrolls the
crates/app/src/tests/layout.rsmodified+115 -24
@@ -63,12 +63,17 @@ fn no_colour_is_written_outside_the_theme() {
6363 /// being scrolled, or it is an instruction nobody can carry out.
6464 #[test]
6565 fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() {
66- // The timeline is a region and not the window: its chrome and one whole
67- // lane fit the share it may take at the floor.
66+ use crate::timeline_fixed_h;
67+
68+ // 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 the
70+ // zoom can leave in it -- and one whole lane fit the share it may take
71+ // at the floor.
6872 let floor = 360. * TIMELINE_SHARE;
6973 assert!(
70- TIMELINE_FIXED_H + LANE_H <= floor,
71- "{TIMELINE_FIXED_H} px of chrome and a lane will not fit {floor} px"
74+ timeline_fixed_h(true) + LANE_H <= floor,
75+ "{} px of chrome and a lane will not fit {floor} px",
76+ timeline_fixed_h(true)
7277 );
7378 // What is left over is measured in whole lanes, at least one.
7479 assert_eq!(lanes_shown(LANE_H), 1);
@@ -289,6 +294,82 @@ fn the_scroll_thumb_is_the_visible_share_at_its_own_place() {
289294 assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.);
290295 }
291296
297+/// 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 its
299+/// height -- out of every budget at once (the region, the box the lanes are
300+/// laid out against, and the seam's floor), or the lanes would gain or lose a
301+/// strip's row at the zoom boundary without the strip to show for it.
302+#[test]
303+fn the_scroll_strip_row_comes_and_goes_with_the_zoom() {
304+ use crate::{SCROLL_HIT, Split, lanes_h, split_size, timeline_fixed_h, timeline_h};
305+ use gpui::{px, size};
306+
307+ // The strip's row, and only the strip's row, is what the two faces differ
308+ // by -- the gap above it and its own hit height.
309+ assert_eq!(
310+ timeline_fixed_h(true) - timeline_fixed_h(false),
311+ 8. + SCROLL_HIT
312+ );
313+ let window = size(px(1280.), px(720.));
314+ for scroll in [false, true] {
315+ // Whatever the strip is doing, the lanes keep exactly the room they
316+ // had: the region grows by the strip's row when it appears, by
317+ // exactly the row the lanes would otherwise lose to it.
318+ assert_eq!(timeline_h(2, scroll) - timeline_fixed_h(scroll), lanes_h(2));
319+ assert_eq!(
320+ timeline_h(6, scroll) - timeline_fixed_h(scroll),
321+ lanes_h(6)
322+ );
323+ // ...and the floor keeps a whole lane standing under the line, on
324+ // either face of the zoom boundary.
325+ let floor = split_size(Split::Timeline, Some(0.), 2, window, scroll);
326+ let box_h = floor - timeline_fixed_h(scroll);
327+ assert!(2 > lanes_shown(box_h), "no line to pay for at the floor");
328+ assert!(
329+ box_h - LABEL_H - 8. >= LANE_H,
330+ "the floor leaves {} px for a {LANE_H} px lane",
331+ box_h - LABEL_H - 8.
332+ );
333+ // The two floors land the lanes in the same place: whichever face
334+ // the zoom is on, a timeline held at its floor shows the same whole
335+ // lane under the same line -- the strip's row comes and goes with
336+ // the floor, not out of the lane. (A size dragged into the interior
337+ // stays the hand's across the boundary, and the lanes are simply
338+ // given the row back.)
339+ assert_eq!(box_h, LANE_H + LABEL_H + 8.);
340+ }
341+ // The share covers the taller floor, strip in -- the one the clamp would
342+ // otherwise overrule at the 640x360 floor, saying the panel takes less of
343+ // a short window than it does.
344+ assert!(
345+ timeline_fixed_h(true) + LANE_H + LABEL_H + 8. <= 360. * TIMELINE_SHARE,
346+ "the strip-bearing floor will not fit the share"
347+ );
348+}
349+
350+/// The lane stack's thumb: the visible share of the rows at their own place
351+/// on the track, the time axis's own thumb turned through a right angle.
352+#[test]
353+fn the_lane_thumb_is_the_visible_share_of_the_stack() {
354+ use crate::lanes_thumb;
355+ use crate::SCROLL_THUMB_MIN;
356+
357+ // Whole stack on screen: the track fills and there is nothing to scroll.
358+ assert_eq!(lanes_thumb(200., 104., 200., 0.), (0., 200.));
359+ assert_eq!(lanes_thumb(200., 0., 0., 0.), (0., 200.));
360+ // Half the stack visible, taken halfway down: a half-height thumb at the
361+ // halfway mark.
362+ assert_eq!(lanes_thumb(200., 400., 200., 100.), (50., 100.));
363+ assert_eq!(lanes_thumb(200., 400., 200., 0.), (0., 100.));
364+ // The floor height: however tall the stack, the thumb stays holdable --
365+ // and the clamp keeps it on the track, not the caller.
366+ let (y, h) = lanes_thumb(200., 2000., 200., 1800.);
367+ assert_eq!(h, SCROLL_THUMB_MIN);
368+ assert_eq!(y, 200. - SCROLL_THUMB_MIN);
369+ assert_eq!(lanes_thumb(200., 2000., 200., 0.).0, 0.);
370+ assert_eq!(lanes_thumb(200., 1_000_000., 200., 0.).0, 0.);
371+}
372+
292373 /// A caption's box wears the rate its window plays at, derived off the
293374 /// placement itself: unity placements -- including odd widths whose frames
294375 /// came off `frames_of_us` rounding -- do not badge, and a re-rate does, with
@@ -1341,36 +1422,44 @@ fn the_volume_slider_lands_where_it_paints() {
13411422 fn a_dragged_divider_stops_before_either_panel_disappears() {
13421423 use crate::ui::theme::INSPECTOR_MIN_W;
13431424 use crate::{
1344- SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w,
1345- split_drag_size, split_size, timeline_h,
1425+ SIDE_MAX_FRAC, SPLIT_W, SCROLL_HIT, SCROLL_THUMB_MIN, Split, TIMELINE_MAX_SHARE,
1426+ TOOLBAR_H, inspector_w, lanes_thumb, library_w, split_drag_size, split_size,
1427+ timeline_fixed_h, timeline_h,
13461428 };
13471429 use gpui::{point, px, size};
13481430
13491431 let window = size(px(1280.), px(720.));
1350- // Untouched, every region is still the share the window gives it.
1351- assert_eq!(split_size(Split::Library, None, 2, window), library_w(1280.));
1432+ // Untouched, every region is still the share the window gives it. The
1433+ // timeline's answer is stated for both of its faces: the timeline fits
1434+ // the bed with nothing to scroll to, and zoomed in past that line the
1435+ // strip's row joins the furniture.
1436+ assert_eq!(split_size(Split::Library, None, 2, window, false), library_w(1280.));
13521437 assert_eq!(
1353- split_size(Split::Inspector, None, 2, window),
1438+ split_size(Split::Inspector, None, 2, window, false),
13541439 inspector_w(1280.)
13551440 );
13561441 assert_eq!(
1357- split_size(Split::Timeline, None, 2, window),
1358- timeline_h(2).min(720. * TIMELINE_SHARE)
1442+ split_size(Split::Timeline, None, 2, window, false),
1443+ timeline_h(2, false).min(720. * TIMELINE_SHARE)
1444+ );
1445+ assert_eq!(
1446+ split_size(Split::Timeline, None, 2, window, true),
1447+ timeline_h(2, true).min(720. * TIMELINE_SHARE)
13591448 );
13601449 // Dragged, it is what the hand asked for...
1361- assert_eq!(split_size(Split::Library, Some(300.), 2, window), 300.);
1362- assert_eq!(split_size(Split::Timeline, Some(300.), 2, window), 300.);
1450+ assert_eq!(split_size(Split::Library, Some(300.), 2, window, false), 300.);
1451+ assert_eq!(split_size(Split::Timeline, Some(300.), 2, window, false), 300.);
13631452 // ...and never past either end of it.
13641453 assert_eq!(
1365- split_size(Split::Library, Some(0.), 2, window),
1454+ split_size(Split::Library, Some(0.), 2, window, false),
13661455 LIBRARY_MIN_W
13671456 );
13681457 assert_eq!(
1369- split_size(Split::Library, Some(9000.), 2, window),
1458+ split_size(Split::Library, Some(9000.), 2, window, false),
13701459 1280. * SIDE_MAX_FRAC
13711460 );
13721461 assert_eq!(
1373- split_size(Split::Inspector, Some(-40.), 2, window),
1462+ split_size(Split::Inspector, Some(-40.), 2, window, false),
13741463 INSPECTOR_MIN_W
13751464 );
13761465 // The timeline's own floor is a floor with a whole lane *drawn* in it. At
@@ -1378,12 +1467,14 @@ fn a_dragged_divider_stops_before_either_panel_disappears() {
13781467 // saying the rest are below is drawn too -- out of the region's pixels,
13791468 // not out of the lane's. Left unbudgeted the header came out 27 px of its
13801469 // 48 and the track's name, its subtitle dot and its × were cut in half.
1381- let floor = split_size(Split::Timeline, Some(0.), 2, window);
1382- assert_eq!(floor, TIMELINE_FIXED_H + LANE_H + LABEL_H + 8.);
1470+ // Stated for the strip-bearing face, the taller of the two -- that is the
1471+ // one the clamp has to hold at the 640x360 floor.
1472+ let floor = split_size(Split::Timeline, Some(0.), 2, window, true);
1473+ assert_eq!(floor, timeline_fixed_h(true) + LANE_H + LABEL_H + 8.);
13831474 // The same arithmetic the timeline lays the column out with
13841475 // ([`Player::timeline`]): what the affordance costs comes off the box, and
13851476 // a whole lane is still standing under it.
1386- let lanes_box = floor - TIMELINE_FIXED_H;
1477+ let lanes_box = floor - timeline_fixed_h(true);
13871478 assert!(2 > lanes_shown(lanes_box), "no line to pay for at the floor");
13881479 assert!(
13891480 lanes_box - LABEL_H - 8. >= LANE_H,
@@ -1393,16 +1484,16 @@ fn a_dragged_divider_stops_before_either_panel_disappears() {
13931484 // A lone track has nothing below it and pays nothing for the line -- the
13941485 // floor is a floor, not a reserved corridor.
13951486 assert_eq!(
1396- split_size(Split::Timeline, Some(0.), 1, window),
1397- TIMELINE_FIXED_H + LANE_H
1487+ split_size(Split::Timeline, Some(0.), 1, window, true),
1488+ timeline_fixed_h(true) + LANE_H
13981489 );
13991490 // A size dragged with one track and kept while a second arrives is raised
14001491 // to the new floor as it is read, not silently drawn under it.
1401- assert_eq!(split_size(Split::Timeline, Some(126.), 2, window), floor);
1492+ assert_eq!(split_size(Split::Timeline, Some(126.), 2, window, true), floor);
14021493 // And the floor still fits the share the shortest window gives the region.
14031494 assert!(floor <= 360. * TIMELINE_SHARE, "{floor} px will not fit");
14041495 assert_eq!(
1405- split_size(Split::Timeline, Some(9000.), 2, window),
1496+ split_size(Split::Timeline, Some(9000.), 2, window, true),
14061497 720. * TIMELINE_MAX_SHARE
14071498 );
14081499 // A window too narrow to honour both ends keeps the floor rather than
@@ -1410,7 +1501,7 @@ fn a_dragged_divider_stops_before_either_panel_disappears() {
14101501 // does.
14111502 let narrow = size(px(600.), px(360.));
14121503 assert_eq!(
1413- split_size(Split::Inspector, Some(9000.), 2, narrow),
1504+ split_size(Split::Inspector, Some(9000.), 2, narrow, false),
14141505 INSPECTOR_MIN_W
14151506 );
14161507
crates/app/src/timeline_math.rsmodified+21 -0
@@ -204,6 +204,21 @@ pub(crate) fn scroll_thumb(
204204 (x as f32, width as f32)
205205 }
206206
207+/// The lane stack's thumb over a track `h` px tall: `(y, height)` of the box
208+/// standing for the visible share of a stack `content` px tall in a box
209+/// `box_h` px tall, taken down by `scrolled` px -- the time axis's
210+/// [`scroll_thumb`] turned through a right angle, and on the same terms:
211+/// full track when the whole stack is on screen, never shorter than
212+/// [`SCROLL_THUMB_MIN`] when it is not, and never off the track either way.
213+pub(crate) fn lanes_thumb(track: f32, content: f32, box_h: f32, scrolled: f32) -> (f32, f32) {
214+ if track <= 0. || content <= 0. || box_h >= content {
215+ return (0., track.max(0.));
216+ }
217+ let height = (track * box_h / content).clamp(SCROLL_THUMB_MIN, track);
218+ let y = (scrolled / (content - box_h) * (track - height)).clamp(0., track - height);
219+ (y, height)
220+}
221+
207222 impl Selection {
208223 pub(crate) fn len(&self) -> usize {
209224 self.picks.len()
@@ -479,6 +494,12 @@ pub(crate) fn px_along(x: Pixels, bounds: Bounds<Pixels>) -> f32 {
479494 f32::from(x - bounds.left()).clamp(0., f32::from(bounds.size.width).max(0.))
480495 }
481496
497+/// [`px_along`] turned through a right angle, for the lane stack's scrollbar:
498+/// how far down its track a press landed.
499+pub(crate) fn px_down(y: Pixels, bounds: Bounds<Pixels>) -> f32 {
500+ f32::from(y - bounds.top()).clamp(0., f32::from(bounds.size.height).max(0.))
501+}
502+
482503 /// One turn of the wheel as a single number, positive for a turn *up*, in
483504 /// whatever units the device sends (a mouse counts lines, a touchpad pixels).
484505 /// A tilt wheel's own axis counts as the same gesture: it is the sideways
crates/app/src/ui/timeline.rsmodified+174 -81
@@ -82,25 +82,43 @@ impl Player {
8282 // What the lane count asks for against its share of the window -- or
8383 // what a hand dragged the seam above to, which wins both
8484 // ([`Player::split_px`]).
85+ //
86+ // The scrollbar's geometry comes off the very view the wheel and the
87+ // zoom write: `settled` is what those paths clamp to, so the thumb
88+ // never disagrees with where the panel actually is. And with the whole
89+ // timeline on the bed there is no strip at all -- nor a row reserved
90+ // for one: the region, this box and the seam's floor all carry the
91+ // strip's pixels or none of them do ([`timeline_fixed_h`]), so the
92+ // lanes keep exactly the room they had at either side of the zoom
93+ // that crosses the line.
94+ let view = self.view();
95+ let scrollable = view.duration > view.span();
8596 let region_h = self.split_px(Split::Timeline, viewport);
86- let lanes_box = (region_h - TIMELINE_FIXED_H).max(LANE_H);
97+ let lanes_box = (region_h - timeline_fixed_h(scrollable)).max(LANE_H);
8798 let overflows = lanes.len() > lanes_shown(lanes_box);
8899 let lanes_box = match overflows {
89100 true => (lanes_box - LABEL_H - 8.).max(LANE_H),
90101 false => lanes_box,
91102 };
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();
97103 let (thumb_x, thumb_w) =
98104 scroll_thumb(view.bed, view.duration, view.scale.start.max(0.), view.span());
99105 // Live, not a count of the lanes: the column reports where it has been
100106 // taken to, so the line empties itself as the last track comes up
101- // instead of insisting there is still something below.
107+ // instead of insisting there is still something below. The stack's own
108+ // strip below reads the same number, so a thumb dragged there and a
109+ // count the affordance lets go of cannot disagree.
102110 let scrolled = -f32::from(self.lanes_scroll.offset().y);
103111 let below = rows_below(lanes.len(), lanes_box, scrolled);
112+ // The stack's own scrollbar: the thumb is the visible share of the
113+ // lane rows, read straight off the column's own scroll state -- the
114+ // box, the fold and how far down it has been taken are all the
115+ // handle's to know, so nothing here is a second truth about any of
116+ // them.
117+ let stack = self.lanes_scroll.bounds();
118+ let track_h = f32::from(stack.size.height);
119+ let stack_max = f32::from(self.lanes_scroll.max_offset().height);
120+ let (stack_y, stack_thumb_h) =
121+ lanes_thumb(track_h, track_h + stack_max, track_h, scrolled);
104122 div()
105123 .flex_none()
106124 // Never more than its share of a short window: the lane column
@@ -219,93 +237,168 @@ impl Player {
219237 // column, so a project with more lanes than the panel is tall
220238 // scrolls its tracks instead of pushing the picture off the window.
221239 // The gap is the panel's own, so two lanes lay out exactly as they
222- // did when they were two children of it.
240+ // did when they were two children of it. The column sits in a
241+ // relative box so the stack's own scrollbar can lie *over* the
242+ // beds' right edge: a gutter beside them would take its width off
243+ // the bed, and the ruler above would stop pointing at the moment
244+ // the lanes are drawn at.
223245 .child(
224246 div()
225- .id("lanes")
226- // Takes whatever the region has left and scrolls inside it:
227- // at the 640x360 floor the region is capped
228- // ([`TIMELINE_SHARE`]) and a fixed column would be clipped
229- // by it rather than scrolled.
230247 .flex_1()
231248 .min_h(px(0.))
232- .flex()
233- .flex_col()
234- .gap(px(8.))
235249 .max_h(px(lanes_h(LANES_MAX)))
236- .overflow_y_scroll()
237- .track_scroll(&self.lanes_scroll)
238- .children(rows),
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+ .relative()
250251 .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)))
252+ .flex_col()
255253 .child(
256254 div()
257- .id("timeline-scroll")
255+ .id("lanes")
256+ // Takes whatever the region has left and scrolls
257+ // inside it: at the 640x360 floor the region is
258+ // capped ([`TIMELINE_SHARE`]) and a fixed column
259+ // would be clipped by it rather than scrolled.
258260 .flex_1()
259- .min_w(px(0.))
260- .h(px(SCROLL_HIT_H))
261+ .min_h(px(0.))
262+ .w_full()
261263 .flex()
262264 .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())
265+ .gap(px(8.))
266+ .overflow_y_scroll()
267+ .track_scroll(&self.lanes_scroll)
268+ .children(rows),
269+ )
270+ // The lane stack's own scrollbar, drawn only while the
271+ // stack overflows -- the same state the affordance below
272+ // announces -- and never while the whole stack is on
273+ // screen, where a full-height thumb would say nothing the
274+ // lanes themselves do not. It costs the lanes nothing,
275+ // being over the bed rather than out of it, and it is its
276+ // own mouse region: a press there never reaches a clip.
277+ .when(overflows, |d| {
278+ d.child(
279+ div()
280+ .id("lanes-scroll")
281+ .absolute()
282+ .top_0()
283+ .right_0()
284+ .bottom_0()
285+ .w(px(SCROLL_HIT))
286+ .rounded(px(3.))
287+ .cursor_pointer()
288+ .hover(|s| s.bg(rgb(BG_HOVER_DIM())))
289+ .tooltip(|_, cx| {
290+ cx.new(|_| {
291+ Tip("Scroll the tracks — drag the thumb or click to \
292+ jump; the wheel scrolls them"
293+ .into())
294+ })
295+ .into()
272296 })
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- ),
297+ .on_scroll_wheel(cx.listener(
298+ |this, event: &ScrollWheelEvent, _, cx| {
299+ this.lanes_wheel(wheel_delta(event), cx);
300+ },
301+ ))
302+ .on_mouse_down(
303+ MouseButton::Left,
304+ cx.listener(|this, event: &MouseDownEvent, _, cx| {
305+ this.lanes_press(event.position.y, cx);
306+ }),
307+ )
308+ .child(
309+ div()
310+ .absolute()
311+ .top_0()
312+ .bottom_0()
313+ .left(px((SCROLL_HIT - 6.) / 2.))
314+ .w(px(6.))
315+ .rounded(px(3.))
316+ .bg(rgb(BG_RAISED()))
317+ .child(
318+ div()
319+ .absolute()
320+ .top(px(stack_y))
321+ .h(px(stack_thumb_h))
322+ .w_full()
323+ .rounded(px(3.))
324+ .bg(rgb(ACCENT_PRIMARY())),
325+ ),
326+ ),
327+ )
328+ }),
308329 )
330+ // The timeline's own scrollbar: the time axis is the one dimension
331+ // the panel scrolls with no bar of its own, and until f69ba33 only
332+ // the wheel and the keys reached it. The thumb is the visible share
333+ // of the drawn duration and sits where that share is -- read off
334+ // the very `Scale` every box is drawn through, so a wheel notch, a
335+ // zoom about the pointer and the follow of the playhead all move
336+ // it, because they all move the one state. The row exists only
337+ // while there is somewhere to scroll to: zoomed out to the whole
338+ // timeline the strip is not drawn and no pixels are held for it
339+ // ([`timeline_fixed_h`]) -- a bar for a view that cannot move is a
340+ // bar teaching nothing.
341+ .when(scrollable, |d| {
342+ d.child(
343+ div()
344+ .flex_none()
345+ .flex()
346+ .gap(px(HEADER_GAP))
347+ // Under the lane headers like the ruler is above them, so
348+ // the thumb and the bed it stands for line up.
349+ .child(div().flex_none().w(px(HEADER_W)))
350+ .child(
351+ div()
352+ .id("timeline-scroll")
353+ .flex_1()
354+ .min_w(px(0.))
355+ .h(px(SCROLL_HIT))
356+ .flex()
357+ .flex_col()
358+ .justify_center()
359+ .rounded(px(3.))
360+ .cursor_pointer()
361+ .hover(|s| s.bg(rgb(BG_HOVER_DIM())))
362+ .tooltip(|_, cx| {
363+ cx.new(|_| {
364+ Tip("Scroll the timeline — drag the thumb or click to \
365+ jump; wheel scrolls, ctrl+wheel zooms"
366+ .into())
367+ })
368+ .into()
369+ })
370+ .on_scroll_wheel(cx.listener(
371+ |this, event: &ScrollWheelEvent, _, cx| {
372+ this.timeline_wheel(event, cx);
373+ },
374+ ))
375+ .on_mouse_down(
376+ MouseButton::Left,
377+ cx.listener(|this, event: &MouseDownEvent, _, cx| {
378+ this.scroll_press(event.position.x, cx);
379+ }),
380+ )
381+ .child(
382+ div()
383+ .w_full()
384+ .h(px(6.))
385+ .rounded(px(3.))
386+ .bg(rgb(BG_RAISED()))
387+ .child(bounds_probe(self.scroll_track.clone()))
388+ .child(
389+ div()
390+ .h_full()
391+ .rounded(px(3.))
392+ .left(px(thumb_x))
393+ .absolute()
394+ .top_0()
395+ .w(px(thumb_w))
396+ .bg(rgb(ACCENT_PRIMARY())),
397+ ),
398+ ),
399+ ),
400+ )
401+ })
309402 // "It scrolls" is not "it can be found": when the region is too
310403 // short for every track -- which is what the 640x360 floor does to a
311404 // three-track project -- the lanes below the fold say so, in the one