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.;
221 /// own seek strip, which is the idiom it sits under.221 /// own seek strip, which is the idiom it sits under.
222 pub(crate) const SCROLL_THUMB_MIN: f32 = 24.;222 pub(crate) const SCROLL_THUMB_MIN: f32 = 24.;
223 223
224-/// The scrollbar track's own hit height: the bar looks 6 px tall, and the224+/// The thickness of a scrollbar strip's hit area, in the one dimension the
225-/// strip that takes the press is taller for the ruler strip's reason -- a225+/// strip spans: the height of the horizontal one under the lanes, the width
226-/// hand must be able to find it without aiming (WCAG 2.5.8).226+/// of the vertical one on the beds' right edge. The bar inside it looks 6 px,
227-pub(crate) const SCROLL_HIT_H: f32 = 14.;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.;
228 230
229 /// Where a held key would land, which is the whole of what auto-repeat has to231 /// Where a held key would land, which is the whole of what auto-repeat has to
230 /// know. [`Player::repeat_scope`] answers it from the same state the handler232 /// 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 {
389 /// region rather than a sliver. Neither end is passable -- a panel dragged to389 /// region rather than a sliver. Neither end is passable -- a panel dragged to
390 /// nothing is a panel nobody can get back, and a picture squeezed out by two390 /// nothing is a panel nobody can get back, and a picture squeezed out by two
391 /// side columns is the same loss on the other side of the window.391 /// 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) {
393 let (w, h) = (f32::from(window.width), f32::from(window.height));398 let (w, h) = (f32::from(window.width), f32::from(window.height));
394 match split {399 match split {
395 Split::Library => (LIBRARY_MIN_W, w * SIDE_MAX_FRAC),400 Split::Library => (LIBRARY_MIN_W, w * SIDE_MAX_FRAC),
396 Split::Inspector => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC),401 Split::Inspector => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC),
397- // One whole lane under the chrome: a timeline shorter than that is a402+ // One whole lane under the chrome, the scrollbar strip's row included
398- // ruler with nothing beneath it. A second track pays for the line that403+ // while there is one to draw ([`timeline_fixed_h`]): a timeline
399- // says the rest are below the fold as well -- at this height only one404+ // shorter than that is a ruler with nothing beneath it. A second
400- // row fits, so that line is *always* drawn there, and it is drawn405+ // track pays for the line that says the rest are below the fold as
401- // inside the region ([`Player::timeline`]). Left out of the floor it406+ // well -- at this height only one row fits, so that line is *always*
402- // comes off the lane's own pixels, and the one lane the floor promises407+ // drawn there, and it is drawn inside the region
403- // is a header cut in half.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.
404 Split::Timeline => (411 Split::Timeline => (
405- TIMELINE_FIXED_H412+ timeline_fixed_h(scroll)
406 + LANE_H413 + LANE_H
407 + match lanes > 1 {414 + match lanes > 1 {
408 true => LABEL_H + 8.,415 true => LABEL_H + 8.,
@@ -413,22 +420,19 @@ pub(crate) fn split_bounds(split: Split, lanes: usize, window: Size<Pixels>) ->
413 }420 }
414 }421 }
415 422
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.
420 pub(crate) fn split_size(423 pub(crate) fn split_size(
421 split: Split,424 split: Split,
422 set: Option<f32>,425 set: Option<f32>,
423 lanes: usize,426 lanes: usize,
424 window: Size<Pixels>,427 window: Size<Pixels>,
428+ scroll: bool,
425 ) -> f32 {429 ) -> f32 {
426 let (w, h) = (f32::from(window.width), f32::from(window.height));430 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);
428 let default = match split {432 let default = match split {
429 Split::Library => library_w(w),433 Split::Library => library_w(w),
430 Split::Inspector => inspector_w(w),434 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),
432 };436 };
433 // The floor wins a window too small to honour both ends: a panel at its437 // The floor wins a window too small to honour both ends: a panel at its
434 // floor is still a panel, and `clamp` panics outright on a ceiling under438 // floor is still a panel, and `clamp` panics outright on a ceiling under
@@ -463,6 +467,14 @@ impl Player {
463 .session467 .session
464 .as_ref()468 .as_ref()
465 .map_or(2, |session| session.lanes().len());469 .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)
467 }479 }
468 }480 }
crates/app/src/main.rsmodified+7 -0
@@ -110,6 +110,12 @@ struct Player {
110 /// A thumb in the hand: how far into the thumb the press landed, in110 /// A thumb in the hand: how far into the thumb the press landed, in
111 /// track pixels. `None` with no drag in flight.111 /// track pixels. `None` with no drag in flight.
112 scroll_drag: Option<f32>,112 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>,
113 /// How wide a second of timeline is drawn, and from which moment. Held here119 /// How wide a second of timeline is drawn, and from which moment. Held here
114 /// and nowhere else: every frame-to-pixel answer in the panel comes out of120 /// and nowhere else: every frame-to-pixel answer in the panel comes out of
115 /// it, so the boxes, the playhead and the pointer cannot disagree.121 /// it, so the boxes, the playhead and the pointer cannot disagree.
@@ -656,6 +662,7 @@ fn main() {
656 ruler: Rc::default(),662 ruler: Rc::default(),
657 scroll_track: Rc::default(),663 scroll_track: Rc::default(),
658 scroll_drag: None,664 scroll_drag: None,
665+ lanes_drag: None,
659 // draws: the title bar and the header name it while its666 // draws: the title bar and the header name it while its
660 // header is still being read.667 // header is still being read.
661 name: name.clone(),668 name: name.clone(),
crates/app/src/player/timeline_edit.rsmodified+15 -0
@@ -1312,6 +1312,17 @@ impl Player {
1312 }1312 }
1313 return;1313 return;
1314 }1314 }
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+ }
1315 // A divider is answered before every gesture below it: it is pressed on1326 // A divider is answered before every gesture below it: it is pressed on
1316 // a strip of its own that nothing else is under, so neither can swallow1327 // a strip of its own that nothing else is under, so neither can swallow
1317 // the other -- a seam over the timeline never scrubs, and a scrub is1328 // the other -- a seam over the timeline never scrubs, and a scrub is
@@ -1417,6 +1428,10 @@ impl Player {
1417 self.scroll_drag_to(event.position.x, cx);1428 self.scroll_drag_to(event.position.x, cx);
1418 return;1429 return;
1419 }1430 }
1431+ if self.lanes_drag.take().is_some() {
1432+ self.lanes_drag_to(event.position.y, cx);
1433+ return;
1434+ }
1420 if let Some(split) = self.split_drag.take() {1435 if let Some(split) = self.split_drag.take() {
1421 self.drag_split(split, event.position, window, cx);1436 self.drag_split(split, event.position, window, cx);
1422 return;1437 return;
crates/app/src/player/view.rsmodified+78 -0
@@ -299,6 +299,84 @@ impl Player {
299 cx.notify();299 cx.notify();
300 }300 }
301 301
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+
302 /// One notch of the wheel anywhere over the timeline -- the ruler or a380 /// One notch of the wheel anywhere over the timeline -- the ruler or a
303 /// lane's bed alike, since a hand aims at the clip it is working on and not381 /// lane's bed alike, since a hand aims at the clip it is working on and not
304 /// at the strip above it. Ctrl zooms about the pointer, bare scrolls the382 /// 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() {
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- // The timeline is a region and not the window: its chrome and one whole66+ use crate::timeline_fixed_h;
67- // lane fit the share it may take at the floor.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.
68 let floor = 360. * TIMELINE_SHARE;72 let floor = 360. * TIMELINE_SHARE;
69 assert!(73 assert!(
70- TIMELINE_FIXED_H + LANE_H <= floor,74+ timeline_fixed_h(true) + LANE_H <= floor,
71- "{TIMELINE_FIXED_H} px of chrome and a lane will not fit {floor} px"75+ "{} px of chrome and a lane will not fit {floor} px",
76+ timeline_fixed_h(true)
72 );77 );
73 // What is left over is measured in whole lanes, at least one.78 // What is left over is measured in whole lanes, at least one.
74 assert_eq!(lanes_shown(LANE_H), 1);79 assert_eq!(lanes_shown(LANE_H), 1);
@@ -289,6 +294,82 @@ fn the_scroll_thumb_is_the_visible_share_at_its_own_place() {
289 assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.);294 assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.);
290 }295 }
291 296
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+
292 /// A caption's box wears the rate its window plays at, derived off the373 /// A caption's box wears the rate its window plays at, derived off the
293 /// placement itself: unity placements -- including odd widths whose frames374 /// placement itself: unity placements -- including odd widths whose frames
294 /// came off `frames_of_us` rounding -- do not badge, and a re-rate does, with375 /// 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() {
1341 fn a_dragged_divider_stops_before_either_panel_disappears() {1422 fn a_dragged_divider_stops_before_either_panel_disappears() {
1342 use crate::ui::theme::INSPECTOR_MIN_W;1423 use crate::ui::theme::INSPECTOR_MIN_W;
1343 use crate::{1424 use crate::{
1344- SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w,1425+ SIDE_MAX_FRAC, SPLIT_W, SCROLL_HIT, SCROLL_THUMB_MIN, Split, TIMELINE_MAX_SHARE,
1345- split_drag_size, split_size, timeline_h,1426+ TOOLBAR_H, inspector_w, lanes_thumb, library_w, split_drag_size, split_size,
1427+ timeline_fixed_h, timeline_h,
1346 };1428 };
1347 use gpui::{point, px, size};1429 use gpui::{point, px, size};
1348 1430
1349 let window = size(px(1280.), px(720.));1431 let window = size(px(1280.), px(720.));
1350- // Untouched, every region is still the share the window gives it.1432+ // Untouched, every region is still the share the window gives it. The
1351- assert_eq!(split_size(Split::Library, None, 2, window), library_w(1280.));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.));
1352 assert_eq!(1437 assert_eq!(
1353- split_size(Split::Inspector, None, 2, window),1438+ split_size(Split::Inspector, None, 2, window, false),
1354 inspector_w(1280.)1439 inspector_w(1280.)
1355 );1440 );
1356 assert_eq!(1441 assert_eq!(
1357- split_size(Split::Timeline, None, 2, window),1442+ split_size(Split::Timeline, None, 2, window, false),
1358- timeline_h(2).min(720. * TIMELINE_SHARE)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)
1359 );1448 );
1360 // Dragged, it is what the hand asked for...1449 // Dragged, it is what the hand asked for...
1361- assert_eq!(split_size(Split::Library, Some(300.), 2, window), 300.);1450+ assert_eq!(split_size(Split::Library, Some(300.), 2, window, false), 300.);
1362- assert_eq!(split_size(Split::Timeline, Some(300.), 2, window), 300.);1451+ assert_eq!(split_size(Split::Timeline, Some(300.), 2, window, false), 300.);
1363 // ...and never past either end of it.1452 // ...and never past either end of it.
1364 assert_eq!(1453 assert_eq!(
1365- split_size(Split::Library, Some(0.), 2, window),1454+ split_size(Split::Library, Some(0.), 2, window, false),
1366 LIBRARY_MIN_W1455 LIBRARY_MIN_W
1367 );1456 );
1368 assert_eq!(1457 assert_eq!(
1369- split_size(Split::Library, Some(9000.), 2, window),1458+ split_size(Split::Library, Some(9000.), 2, window, false),
1370 1280. * SIDE_MAX_FRAC1459 1280. * SIDE_MAX_FRAC
1371 );1460 );
1372 assert_eq!(1461 assert_eq!(
1373- split_size(Split::Inspector, Some(-40.), 2, window),1462+ split_size(Split::Inspector, Some(-40.), 2, window, false),
1374 INSPECTOR_MIN_W1463 INSPECTOR_MIN_W
1375 );1464 );
1376 // The timeline's own floor is a floor with a whole lane *drawn* in it. At1465 // 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() {
1378 // saying the rest are below is drawn too -- out of the region's pixels,1467 // saying the rest are below is drawn too -- out of the region's pixels,
1379 // not out of the lane's. Left unbudgeted the header came out 27 px of its1468 // not out of the lane's. Left unbudgeted the header came out 27 px of its
1380 // 48 and the track's name, its subtitle dot and its × were cut in half.1469 // 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);1470+ // Stated for the strip-bearing face, the taller of the two -- that is the
1382- assert_eq!(floor, TIMELINE_FIXED_H + LANE_H + LABEL_H + 8.);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.);
1383 // The same arithmetic the timeline lays the column out with1474 // The same arithmetic the timeline lays the column out with
1384 // ([`Player::timeline`]): what the affordance costs comes off the box, and1475 // ([`Player::timeline`]): what the affordance costs comes off the box, and
1385 // a whole lane is still standing under it.1476 // 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);
1387 assert!(2 > lanes_shown(lanes_box), "no line to pay for at the floor");1478 assert!(2 > lanes_shown(lanes_box), "no line to pay for at the floor");
1388 assert!(1479 assert!(
1389 lanes_box - LABEL_H - 8. >= LANE_H,1480 lanes_box - LABEL_H - 8. >= LANE_H,
@@ -1393,16 +1484,16 @@ fn a_dragged_divider_stops_before_either_panel_disappears() {
1393 // A lone track has nothing below it and pays nothing for the line -- the1484 // A lone track has nothing below it and pays nothing for the line -- the
1394 // floor is a floor, not a reserved corridor.1485 // floor is a floor, not a reserved corridor.
1395 assert_eq!(1486 assert_eq!(
1396- split_size(Split::Timeline, Some(0.), 1, window),1487+ split_size(Split::Timeline, Some(0.), 1, window, true),
1397- TIMELINE_FIXED_H + LANE_H1488+ timeline_fixed_h(true) + LANE_H
1398 );1489 );
1399 // A size dragged with one track and kept while a second arrives is raised1490 // A size dragged with one track and kept while a second arrives is raised
1400 // to the new floor as it is read, not silently drawn under it.1491 // 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);
1402 // And the floor still fits the share the shortest window gives the region.1493 // And the floor still fits the share the shortest window gives the region.
1403 assert!(floor <= 360. * TIMELINE_SHARE, "{floor} px will not fit");1494 assert!(floor <= 360. * TIMELINE_SHARE, "{floor} px will not fit");
1404 assert_eq!(1495 assert_eq!(
1405- split_size(Split::Timeline, Some(9000.), 2, window),1496+ split_size(Split::Timeline, Some(9000.), 2, window, true),
1406 720. * TIMELINE_MAX_SHARE1497 720. * TIMELINE_MAX_SHARE
1407 );1498 );
1408 // A window too narrow to honour both ends keeps the floor rather than1499 // 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() {
1410 // does.1501 // does.
1411 let narrow = size(px(600.), px(360.));1502 let narrow = size(px(600.), px(360.));
1412 assert_eq!(1503 assert_eq!(
1413- split_size(Split::Inspector, Some(9000.), 2, narrow),1504+ split_size(Split::Inspector, Some(9000.), 2, narrow, false),
1414 INSPECTOR_MIN_W1505 INSPECTOR_MIN_W
1415 );1506 );
1416 1507
crates/app/src/timeline_math.rsmodified+21 -0
@@ -204,6 +204,21 @@ pub(crate) fn scroll_thumb(
204 (x as f32, width as f32)204 (x as f32, width as f32)
205 }205 }
206 206
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+
207 impl Selection {222 impl Selection {
208 pub(crate) fn len(&self) -> usize {223 pub(crate) fn len(&self) -> usize {
209 self.picks.len()224 self.picks.len()
@@ -479,6 +494,12 @@ pub(crate) fn px_along(x: Pixels, bounds: Bounds<Pixels>) -> f32 {
479 f32::from(x - bounds.left()).clamp(0., f32::from(bounds.size.width).max(0.))494 f32::from(x - bounds.left()).clamp(0., f32::from(bounds.size.width).max(0.))
480 }495 }
481 496
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+
482 /// One turn of the wheel as a single number, positive for a turn *up*, in503 /// One turn of the wheel as a single number, positive for a turn *up*, in
483 /// whatever units the device sends (a mouse counts lines, a touchpad pixels).504 /// whatever units the device sends (a mouse counts lines, a touchpad pixels).
484 /// A tilt wheel's own axis counts as the same gesture: it is the sideways505 /// 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 {
82 // What the lane count asks for against its share of the window -- or82 // What the lane count asks for against its share of the window -- or
83 // what a hand dragged the seam above to, which wins both83 // what a hand dragged the seam above to, which wins both
84 // ([`Player::split_px`]).84 // ([`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();
85 let region_h = self.split_px(Split::Timeline, viewport);96 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);
87 let overflows = lanes.len() > lanes_shown(lanes_box);98 let overflows = lanes.len() > lanes_shown(lanes_box);
88 let lanes_box = match overflows {99 let lanes_box = match overflows {
89 true => (lanes_box - LABEL_H - 8.).max(LANE_H),100 true => (lanes_box - LABEL_H - 8.).max(LANE_H),
90 false => lanes_box,101 false => lanes_box,
91 };102 };
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) =103 let (thumb_x, thumb_w) =
98 scroll_thumb(view.bed, view.duration, view.scale.start.max(0.), view.span());104 scroll_thumb(view.bed, view.duration, view.scale.start.max(0.), view.span());
99 // Live, not a count of the lanes: the column reports where it has been105 // Live, not a count of the lanes: the column reports where it has been
100 // taken to, so the line empties itself as the last track comes up106 // 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.
102 let scrolled = -f32::from(self.lanes_scroll.offset().y);110 let scrolled = -f32::from(self.lanes_scroll.offset().y);
103 let below = rows_below(lanes.len(), lanes_box, scrolled);111 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);
104 div()122 div()
105 .flex_none()123 .flex_none()
106 // Never more than its share of a short window: the lane column124 // Never more than its share of a short window: the lane column
@@ -219,93 +237,168 @@ impl Player {
219 // column, so a project with more lanes than the panel is tall237 // column, so a project with more lanes than the panel is tall
220 // scrolls its tracks instead of pushing the picture off the window.238 // scrolls its tracks instead of pushing the picture off the window.
221 // The gap is the panel's own, so two lanes lay out exactly as they239 // 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.
223 .child(245 .child(
224 div()246 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.
230 .flex_1()247 .flex_1()
231 .min_h(px(0.))248 .min_h(px(0.))
232- .flex()
233- .flex_col()
234- .gap(px(8.))
235 .max_h(px(lanes_h(LANES_MAX)))249 .max_h(px(lanes_h(LANES_MAX)))
236- .overflow_y_scroll()250+ .relative()
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 .flex()251 .flex()
251- .gap(px(HEADER_GAP))252+ .flex_col()
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(253 .child(
256 div()254 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.
258 .flex_1()260 .flex_1()
259- .min_w(px(0.))261+ .min_h(px(0.))
260- .h(px(SCROLL_HIT_H))262+ .w_full()
261 .flex()263 .flex()
262 .flex_col()264 .flex_col()
263- .justify_center()265+ .gap(px(8.))
264- .rounded(px(3.))266+ .overflow_y_scroll()
265- .cursor_pointer()267+ .track_scroll(&self.lanes_scroll)
266- .hover(|s| s.bg(rgb(BG_HOVER_DIM())))268+ .children(rows),
267- .tooltip(|_, cx| {269+ )
268- cx.new(|_| {270+ // The lane stack's own scrollbar, drawn only while the
269- Tip("Scroll the timeline — drag the thumb or click to jump; \271+ // stack overflows -- the same state the affordance below
270- wheel scrolls, ctrl+wheel zooms"272+ // announces -- and never while the whole stack is on
271- .into())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()
272 })296 })
273- .into()297+ .on_scroll_wheel(cx.listener(
274- })298+ |this, event: &ScrollWheelEvent, _, cx| {
275- .on_scroll_wheel(cx.listener(299+ this.lanes_wheel(wheel_delta(event), cx);
276- |this, event: &ScrollWheelEvent, _, cx| {300+ },
277- this.timeline_wheel(event, cx);301+ ))
278- },302+ .on_mouse_down(
279- ))303+ MouseButton::Left,
280- .on_mouse_down(304+ cx.listener(|this, event: &MouseDownEvent, _, cx| {
281- MouseButton::Left,305+ this.lanes_press(event.position.y, cx);
282- cx.listener(|this, event: &MouseDownEvent, _, cx| {306+ }),
283- this.scroll_press(event.position.x, cx);307+ )
284- }),308+ .child(
285- )309+ div()
286- .child(310+ .absolute()
287- div()311+ .top_0()
288- .w_full()312+ .bottom_0()
289- .h(px(6.))313+ .left(px((SCROLL_HIT - 6.) / 2.))
290- .rounded(px(3.))314+ .w(px(6.))
291- .bg(rgb(BG_RAISED()))315+ .rounded(px(3.))
292- .child(bounds_probe(self.scroll_track.clone()))316+ .bg(rgb(BG_RAISED()))
293- .child(317+ .child(
294- div()318+ div()
295- .h_full()319+ .absolute()
296- .rounded(px(3.))320+ .top(px(stack_y))
297- .left(px(thumb_x))321+ .h(px(stack_thumb_h))
298- .absolute()322+ .w_full()
299- .top_0()323+ .rounded(px(3.))
300- .w(px(thumb_w))324+ .bg(rgb(ACCENT_PRIMARY())),
301- .bg(rgb(match scrollable {325+ ),
302- true => ACCENT_PRIMARY(),326+ ),
303- false => FG_SECONDARY(),327+ )
304- })),328+ }),
305- ),
306- ),
307- ),
308 )329 )
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+ })
309 // "It scrolls" is not "it can be found": when the region is too402 // "It scrolls" is not "it can be found": when the region is too
310 // short for every track -- which is what the 640x360 floor does to a403 // short for every track -- which is what the 640x360 floor does to a
311 // three-track project -- the lanes below the fold say so, in the one404 // three-track project -- the lanes below the fold say so, in the one