From dd77ab098a61bce21a33947f37ee101d7d60cb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 16 Aug 2026 00:30:35 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(timeline):=20the=20scrollbar?= =?UTF-8?q?=20is=20only=20there=20while=20there=20is=20somewhere=20to=20go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.rs | 10 +- crates/app/src/layout.rs | 44 +++-- crates/app/src/main.rs | 7 + crates/app/src/player/timeline_edit.rs | 15 ++ crates/app/src/player/view.rs | 78 ++++++++ crates/app/src/tests/layout.rs | 139 +++++++++++--- crates/app/src/timeline_math.rs | 21 ++ crates/app/src/ui/timeline.rs | 255 +++++++++++++++++-------- 8 files changed, 444 insertions(+), 125 deletions(-) diff --git a/crates/app/src/interact.rs b/crates/app/src/interact.rs index 443720f..17c9830 100644 --- a/crates/app/src/interact.rs +++ b/crates/app/src/interact.rs @@ -221,10 +221,12 @@ pub(crate) const SNAP_PX: f64 = 5.; /// own seek strip, which is the idiom it sits under. pub(crate) const SCROLL_THUMB_MIN: f32 = 24.; -/// The scrollbar track's own hit height: the bar looks 6 px tall, and the -/// strip that takes the press is taller for the ruler strip's reason -- a -/// hand must be able to find it without aiming (WCAG 2.5.8). -pub(crate) const SCROLL_HIT_H: f32 = 14.; +/// The thickness of a scrollbar strip's hit area, in the one dimension the +/// strip spans: the height of the horizontal one under the lanes, the width +/// of the vertical one on the beds' right edge. The bar inside it looks 6 px, +/// and the strip that takes the press is thicker for the ruler strip's +/// reason -- a hand must be able to find it without aiming (WCAG 2.5.8). +pub(crate) const SCROLL_HIT: f32 = 14.; /// Where a held key would land, which is the whole of what auto-repeat has to /// know. [`Player::repeat_scope`] answers it from the same state the handler diff --git a/crates/app/src/layout.rs b/crates/app/src/layout.rs index 82aba04..508f571 100644 --- a/crates/app/src/layout.rs +++ b/crates/app/src/layout.rs @@ -389,20 +389,27 @@ impl Splits { /// region rather than a sliver. Neither end is passable -- a panel dragged to /// nothing is a panel nobody can get back, and a picture squeezed out by two /// side columns is the same loss on the other side of the window. -pub(crate) fn split_bounds(split: Split, lanes: usize, window: Size) -> (f32, f32) { +pub(crate) fn split_bounds( + split: Split, + lanes: usize, + window: Size, + scroll: bool, +) -> (f32, f32) { let (w, h) = (f32::from(window.width), f32::from(window.height)); match split { Split::Library => (LIBRARY_MIN_W, w * SIDE_MAX_FRAC), Split::Inspector => (INSPECTOR_MIN_W, w * SIDE_MAX_FRAC), - // One whole lane under the chrome: a timeline shorter than that is a - // ruler with nothing beneath it. A second track pays for the line that - // says the rest are below the fold as well -- at this height only one - // row fits, so that line is *always* drawn there, and it is drawn - // inside the region ([`Player::timeline`]). Left out of the floor it - // comes off the lane's own pixels, and the one lane the floor promises - // is a header cut in half. + // One whole lane under the chrome, the scrollbar strip's row included + // while there is one to draw ([`timeline_fixed_h`]): a timeline + // shorter than that is a ruler with nothing beneath it. A second + // track pays for the line that says the rest are below the fold as + // well -- at this height only one row fits, so that line is *always* + // drawn there, and it is drawn inside the region + // ([`Player::timeline`]). Left out of the floor it comes off the + // lane's own pixels, and the one lane the floor promises is a header + // cut in half. Split::Timeline => ( - TIMELINE_FIXED_H + timeline_fixed_h(scroll) + LANE_H + match lanes > 1 { true => LABEL_H + 8., @@ -413,22 +420,19 @@ pub(crate) fn split_bounds(split: Split, lanes: usize, window: Size) -> } } -/// How big the panel at this seam is drawn: what the hand dragged it to, held -/// inside the window *being drawn now* -- the window is resizable, and a width -/// set at 1920 px is not a width at 640 -- or the share the untouched layout -/// gives it. pub(crate) fn split_size( split: Split, set: Option, lanes: usize, window: Size, + scroll: bool, ) -> f32 { let (w, h) = (f32::from(window.width), f32::from(window.height)); - let (min, max) = split_bounds(split, lanes, window); + let (min, max) = split_bounds(split, lanes, window, scroll); let default = match split { Split::Library => library_w(w), Split::Inspector => inspector_w(w), - Split::Timeline => timeline_h(lanes).min(h * TIMELINE_SHARE), + Split::Timeline => timeline_h(lanes, scroll).min(h * TIMELINE_SHARE), }; // The floor wins a window too small to honour both ends: a panel at its // floor is still a panel, and `clamp` panics outright on a ceiling under @@ -463,6 +467,14 @@ impl Player { .session .as_ref() .map_or(2, |session| session.lanes().len()); - split_size(split, self.splits.get(split), lanes, window) + // Whether the time axis has anywhere to go: the scrollbar strip is + // drawn only while it does, and the region's furniture -- and its + // floor -- carry the strip's row only while it is. One door + // ([`timeline_fixed_h`]) answers the region, the fold and the floor + // together, so the three cannot disagree about whether the strip is + // there. + let view = self.view(); + let scroll = view.duration > view.span(); + split_size(split, self.splits.get(split), lanes, window, scroll) } } diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 2c0530e..111eeb6 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -110,6 +110,12 @@ struct Player { /// A thumb in the hand: how far into the thumb the press landed, in /// track pixels. `None` with no drag in flight. scroll_drag: Option, + /// A thumb of the lane stack's own scrollbar in the hand: how far into + /// the thumb the press landed, in track pixels. `None` with no drag in + /// flight. The stack's box itself is read straight off the scroll handle + /// each frame, so unlike the time axis's strip it needs no probe of its + /// own. + lanes_drag: Option, /// How wide a second of timeline is drawn, and from which moment. Held here /// and nowhere else: every frame-to-pixel answer in the panel comes out of /// it, so the boxes, the playhead and the pointer cannot disagree. @@ -656,6 +662,7 @@ fn main() { ruler: Rc::default(), scroll_track: Rc::default(), scroll_drag: None, + lanes_drag: None, // draws: the title bar and the header name it while its // header is still being read. name: name.clone(), diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 2d4d101..f8aec6c 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1312,6 +1312,17 @@ impl Player { } return; } + // The lane stack's own thumb, on exactly the same terms: the pointer + // leaves the strip on the first move, so the root carries the gesture + // -- and a hand holding the stack is not holding anything on it + // either. + if self.lanes_drag.is_some() { + match event.pressed_button { + Some(MouseButton::Left) => self.lanes_drag_to(event.position.y, cx), + _ => self.lanes_drag = None, + } + return; + } // A divider is answered before every gesture below it: it is pressed on // a strip of its own that nothing else is under, so neither can swallow // the other -- a seam over the timeline never scrubs, and a scrub is @@ -1417,6 +1428,10 @@ impl Player { self.scroll_drag_to(event.position.x, cx); return; } + if self.lanes_drag.take().is_some() { + self.lanes_drag_to(event.position.y, cx); + return; + } if let Some(split) = self.split_drag.take() { self.drag_split(split, event.position, window, cx); return; diff --git a/crates/app/src/player/view.rs b/crates/app/src/player/view.rs index 5f9d86b..c05c3dc 100644 --- a/crates/app/src/player/view.rs +++ b/crates/app/src/player/view.rs @@ -299,6 +299,84 @@ impl Player { cx.notify(); } + /// The lane stack's own scroll, as one number: how far down the column + /// has been taken, clamped to what it can show. The names and the beds + /// are one column (`id("lanes")`), so one offset moves them together and + /// this is the whole of the stack's scrolling -- the wheel over the names + /// and the thumb on the strip both land here. + fn lanes_taken(&self, to: f32) -> f32 { + let max = f32::from(self.lanes_scroll.max_offset().height); + to.clamp(0., max) + } + + /// A press on the lane stack's scrollbar: on the thumb, the drag begins + /// from wherever in it the hand landed; beside it, the stack jumps so the + /// thumb's middle is at the press and the drag carries on from there -- + /// the time axis's own terms ([`Self::scroll_press`]), turned through a + /// right angle. + pub(crate) fn lanes_press(&mut self, y: Pixels, cx: &mut Context) { + let track = f32::from(self.lanes_scroll.bounds().size.height); + let max = f32::from(self.lanes_scroll.max_offset().height); + if track <= 0. || max <= 0. { + return; + } + let scrolled = -f32::from(self.lanes_scroll.offset().y); + let (thumb_y, thumb_h) = lanes_thumb(track, track + max, track, scrolled); + let at = px_down(y, self.lanes_scroll.bounds()); + let grab = match (thumb_y..thumb_y + thumb_h).contains(&at) { + true => at - thumb_y, + // Beside the thumb: jump so its middle is under the pointer, at + // the press's own share of the stack. The thumb is clamped inside + // the track by [`lanes_thumb`], so the grab this leaves is always + // a real place inside it. + false => { + let to = self.lanes_taken( + (at - thumb_h / 2.).max(0.) / (track - thumb_h).max(1.) * max, + ); + self.lanes_scroll + .set_offset(point(self.lanes_scroll.offset().x, px(-to))); + thumb_h / 2. + } + }; + self.lanes_drag = Some(grab); + cx.notify(); + } + + /// A sample of the lane thumb's drag: the stack is taken to where the + /// thumb's grabbed point sits under the pointer, clamped by the same + /// `max_offset` the column's own wheel answers to. No reseek, no repaint + /// of anything outside the column -- the view is not moving. + pub(crate) fn lanes_drag_to(&mut self, y: Pixels, cx: &mut Context) { + let Some(grab) = self.lanes_drag else { + return; + }; + let track = f32::from(self.lanes_scroll.bounds().size.height); + let max = f32::from(self.lanes_scroll.max_offset().height); + let (_, thumb_h) = lanes_thumb(track, track + max, track, 0.); + let at = px_down(y, self.lanes_scroll.bounds()); + let to = self.lanes_taken((at - grab).max(0.) / (track - thumb_h).max(1.) * max); + self.lanes_scroll + .set_offset(point(self.lanes_scroll.offset().x, px(-to))); + cx.notify(); + } + + /// One notch of the wheel over the lane stack's strip: the stack moves a + /// share of what it is showing, the same share the time axis gives a + /// notch of its own -- the strip is the names' scroll surface, and this + /// is what a wheel there did already. + pub(crate) fn lanes_wheel(&mut self, notches: f32, cx: &mut Context) { + let track = f32::from(self.lanes_scroll.bounds().size.height); + let max = f32::from(self.lanes_scroll.max_offset().height); + if track <= 0. || max <= 0. { + return; + } + let scrolled = -f32::from(self.lanes_scroll.offset().y); + let to = self.lanes_taken(scrolled - notches * track * SCROLL_NOTCH_SHARE); + self.lanes_scroll + .set_offset(point(self.lanes_scroll.offset().x, px(-to))); + cx.notify(); + } + /// One notch of the wheel anywhere over the timeline -- the ruler or a /// lane's bed alike, since a hand aims at the clip it is working on and not /// at the strip above it. Ctrl zooms about the pointer, bare scrolls the diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index b5b0444..0c93335 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -63,12 +63,17 @@ fn no_colour_is_written_outside_the_theme() { /// being scrolled, or it is an instruction nobody can carry out. #[test] fn the_line_about_what_is_below_the_fold_counts_what_is_still_below_it() { - // The timeline is a region and not the window: its chrome and one whole - // lane fit the share it may take at the floor. + use crate::timeline_fixed_h; + + // The timeline is a region and not the window: its chrome -- the + // scrollbar strip's row included, which is the larger of the two the + // zoom can leave in it -- and one whole lane fit the share it may take + // at the floor. let floor = 360. * TIMELINE_SHARE; assert!( - TIMELINE_FIXED_H + LANE_H <= floor, - "{TIMELINE_FIXED_H} px of chrome and a lane will not fit {floor} px" + timeline_fixed_h(true) + LANE_H <= floor, + "{} px of chrome and a lane will not fit {floor} px", + timeline_fixed_h(true) ); // What is left over is measured in whole lanes, at least one. assert_eq!(lanes_shown(LANE_H), 1); @@ -289,6 +294,82 @@ fn the_scroll_thumb_is_the_visible_share_at_its_own_place() { assert_eq!(scroll_thumb(400., 1_000_000., 0., 100.).0, 0.); } +/// The strip's row is furniture only while there is somewhere to scroll to: +/// zoomed out to the whole timeline the strip is not drawn and neither is its +/// height -- out of every budget at once (the region, the box the lanes are +/// laid out against, and the seam's floor), or the lanes would gain or lose a +/// strip's row at the zoom boundary without the strip to show for it. +#[test] +fn the_scroll_strip_row_comes_and_goes_with_the_zoom() { + use crate::{SCROLL_HIT, Split, lanes_h, split_size, timeline_fixed_h, timeline_h}; + use gpui::{px, size}; + + // The strip's row, and only the strip's row, is what the two faces differ + // by -- the gap above it and its own hit height. + assert_eq!( + timeline_fixed_h(true) - timeline_fixed_h(false), + 8. + SCROLL_HIT + ); + let window = size(px(1280.), px(720.)); + for scroll in [false, true] { + // Whatever the strip is doing, the lanes keep exactly the room they + // had: the region grows by the strip's row when it appears, by + // exactly the row the lanes would otherwise lose to it. + assert_eq!(timeline_h(2, scroll) - timeline_fixed_h(scroll), lanes_h(2)); + assert_eq!( + timeline_h(6, scroll) - timeline_fixed_h(scroll), + lanes_h(6) + ); + // ...and the floor keeps a whole lane standing under the line, on + // either face of the zoom boundary. + let floor = split_size(Split::Timeline, Some(0.), 2, window, scroll); + let box_h = floor - timeline_fixed_h(scroll); + assert!(2 > lanes_shown(box_h), "no line to pay for at the floor"); + assert!( + box_h - LABEL_H - 8. >= LANE_H, + "the floor leaves {} px for a {LANE_H} px lane", + box_h - LABEL_H - 8. + ); + // The two floors land the lanes in the same place: whichever face + // the zoom is on, a timeline held at its floor shows the same whole + // lane under the same line -- the strip's row comes and goes with + // the floor, not out of the lane. (A size dragged into the interior + // stays the hand's across the boundary, and the lanes are simply + // given the row back.) + assert_eq!(box_h, LANE_H + LABEL_H + 8.); + } + // The share covers the taller floor, strip in -- the one the clamp would + // otherwise overrule at the 640x360 floor, saying the panel takes less of + // a short window than it does. + assert!( + timeline_fixed_h(true) + LANE_H + LABEL_H + 8. <= 360. * TIMELINE_SHARE, + "the strip-bearing floor will not fit the share" + ); +} + +/// The lane stack's thumb: the visible share of the rows at their own place +/// on the track, the time axis's own thumb turned through a right angle. +#[test] +fn the_lane_thumb_is_the_visible_share_of_the_stack() { + use crate::lanes_thumb; + use crate::SCROLL_THUMB_MIN; + + // Whole stack on screen: the track fills and there is nothing to scroll. + assert_eq!(lanes_thumb(200., 104., 200., 0.), (0., 200.)); + assert_eq!(lanes_thumb(200., 0., 0., 0.), (0., 200.)); + // Half the stack visible, taken halfway down: a half-height thumb at the + // halfway mark. + assert_eq!(lanes_thumb(200., 400., 200., 100.), (50., 100.)); + assert_eq!(lanes_thumb(200., 400., 200., 0.), (0., 100.)); + // The floor height: however tall the stack, the thumb stays holdable -- + // and the clamp keeps it on the track, not the caller. + let (y, h) = lanes_thumb(200., 2000., 200., 1800.); + assert_eq!(h, SCROLL_THUMB_MIN); + assert_eq!(y, 200. - SCROLL_THUMB_MIN); + assert_eq!(lanes_thumb(200., 2000., 200., 0.).0, 0.); + assert_eq!(lanes_thumb(200., 1_000_000., 200., 0.).0, 0.); +} + /// A caption's box wears the rate its window plays at, derived off the /// placement itself: unity placements -- including odd widths whose frames /// 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() { fn a_dragged_divider_stops_before_either_panel_disappears() { use crate::ui::theme::INSPECTOR_MIN_W; use crate::{ - SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w, - split_drag_size, split_size, timeline_h, + SIDE_MAX_FRAC, SPLIT_W, SCROLL_HIT, SCROLL_THUMB_MIN, Split, TIMELINE_MAX_SHARE, + TOOLBAR_H, inspector_w, lanes_thumb, library_w, split_drag_size, split_size, + timeline_fixed_h, timeline_h, }; use gpui::{point, px, size}; let window = size(px(1280.), px(720.)); - // Untouched, every region is still the share the window gives it. - assert_eq!(split_size(Split::Library, None, 2, window), library_w(1280.)); + // Untouched, every region is still the share the window gives it. The + // timeline's answer is stated for both of its faces: the timeline fits + // the bed with nothing to scroll to, and zoomed in past that line the + // strip's row joins the furniture. + assert_eq!(split_size(Split::Library, None, 2, window, false), library_w(1280.)); assert_eq!( - split_size(Split::Inspector, None, 2, window), + split_size(Split::Inspector, None, 2, window, false), inspector_w(1280.) ); assert_eq!( - split_size(Split::Timeline, None, 2, window), - timeline_h(2).min(720. * TIMELINE_SHARE) + split_size(Split::Timeline, None, 2, window, false), + timeline_h(2, false).min(720. * TIMELINE_SHARE) + ); + assert_eq!( + split_size(Split::Timeline, None, 2, window, true), + timeline_h(2, true).min(720. * TIMELINE_SHARE) ); // Dragged, it is what the hand asked for... - assert_eq!(split_size(Split::Library, Some(300.), 2, window), 300.); - assert_eq!(split_size(Split::Timeline, Some(300.), 2, window), 300.); + assert_eq!(split_size(Split::Library, Some(300.), 2, window, false), 300.); + assert_eq!(split_size(Split::Timeline, Some(300.), 2, window, false), 300.); // ...and never past either end of it. assert_eq!( - split_size(Split::Library, Some(0.), 2, window), + split_size(Split::Library, Some(0.), 2, window, false), LIBRARY_MIN_W ); assert_eq!( - split_size(Split::Library, Some(9000.), 2, window), + split_size(Split::Library, Some(9000.), 2, window, false), 1280. * SIDE_MAX_FRAC ); assert_eq!( - split_size(Split::Inspector, Some(-40.), 2, window), + split_size(Split::Inspector, Some(-40.), 2, window, false), INSPECTOR_MIN_W ); // 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() { // saying the rest are below is drawn too -- out of the region's pixels, // not out of the lane's. Left unbudgeted the header came out 27 px of its // 48 and the track's name, its subtitle dot and its × were cut in half. - let floor = split_size(Split::Timeline, Some(0.), 2, window); - assert_eq!(floor, TIMELINE_FIXED_H + LANE_H + LABEL_H + 8.); + // Stated for the strip-bearing face, the taller of the two -- that is the + // one the clamp has to hold at the 640x360 floor. + let floor = split_size(Split::Timeline, Some(0.), 2, window, true); + assert_eq!(floor, timeline_fixed_h(true) + LANE_H + LABEL_H + 8.); // The same arithmetic the timeline lays the column out with // ([`Player::timeline`]): what the affordance costs comes off the box, and // a whole lane is still standing under it. - let lanes_box = floor - TIMELINE_FIXED_H; + let lanes_box = floor - timeline_fixed_h(true); assert!(2 > lanes_shown(lanes_box), "no line to pay for at the floor"); assert!( lanes_box - LABEL_H - 8. >= LANE_H, @@ -1393,16 +1484,16 @@ fn a_dragged_divider_stops_before_either_panel_disappears() { // A lone track has nothing below it and pays nothing for the line -- the // floor is a floor, not a reserved corridor. assert_eq!( - split_size(Split::Timeline, Some(0.), 1, window), - TIMELINE_FIXED_H + LANE_H + split_size(Split::Timeline, Some(0.), 1, window, true), + timeline_fixed_h(true) + LANE_H ); // A size dragged with one track and kept while a second arrives is raised // to the new floor as it is read, not silently drawn under it. - assert_eq!(split_size(Split::Timeline, Some(126.), 2, window), floor); + assert_eq!(split_size(Split::Timeline, Some(126.), 2, window, true), floor); // And the floor still fits the share the shortest window gives the region. assert!(floor <= 360. * TIMELINE_SHARE, "{floor} px will not fit"); assert_eq!( - split_size(Split::Timeline, Some(9000.), 2, window), + split_size(Split::Timeline, Some(9000.), 2, window, true), 720. * TIMELINE_MAX_SHARE ); // 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() { // does. let narrow = size(px(600.), px(360.)); assert_eq!( - split_size(Split::Inspector, Some(9000.), 2, narrow), + split_size(Split::Inspector, Some(9000.), 2, narrow, false), INSPECTOR_MIN_W ); diff --git a/crates/app/src/timeline_math.rs b/crates/app/src/timeline_math.rs index 9cad527..45b7f45 100644 --- a/crates/app/src/timeline_math.rs +++ b/crates/app/src/timeline_math.rs @@ -204,6 +204,21 @@ pub(crate) fn scroll_thumb( (x as f32, width as f32) } +/// The lane stack's thumb over a track `h` px tall: `(y, height)` of the box +/// standing for the visible share of a stack `content` px tall in a box +/// `box_h` px tall, taken down by `scrolled` px -- the time axis's +/// [`scroll_thumb`] turned through a right angle, and on the same terms: +/// full track when the whole stack is on screen, never shorter than +/// [`SCROLL_THUMB_MIN`] when it is not, and never off the track either way. +pub(crate) fn lanes_thumb(track: f32, content: f32, box_h: f32, scrolled: f32) -> (f32, f32) { + if track <= 0. || content <= 0. || box_h >= content { + return (0., track.max(0.)); + } + let height = (track * box_h / content).clamp(SCROLL_THUMB_MIN, track); + let y = (scrolled / (content - box_h) * (track - height)).clamp(0., track - height); + (y, height) +} + impl Selection { pub(crate) fn len(&self) -> usize { self.picks.len() @@ -479,6 +494,12 @@ pub(crate) fn px_along(x: Pixels, bounds: Bounds) -> f32 { f32::from(x - bounds.left()).clamp(0., f32::from(bounds.size.width).max(0.)) } +/// [`px_along`] turned through a right angle, for the lane stack's scrollbar: +/// how far down its track a press landed. +pub(crate) fn px_down(y: Pixels, bounds: Bounds) -> f32 { + f32::from(y - bounds.top()).clamp(0., f32::from(bounds.size.height).max(0.)) +} + /// One turn of the wheel as a single number, positive for a turn *up*, in /// whatever units the device sends (a mouse counts lines, a touchpad pixels). /// A tilt wheel's own axis counts as the same gesture: it is the sideways diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 0c443a7..10d824a 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -82,25 +82,43 @@ impl Player { // What the lane count asks for against its share of the window -- or // what a hand dragged the seam above to, which wins both // ([`Player::split_px`]). + // + // The scrollbar's geometry comes off the very view the wheel and the + // zoom write: `settled` is what those paths clamp to, so the thumb + // never disagrees with where the panel actually is. And with the whole + // timeline on the bed there is no strip at all -- nor a row reserved + // for one: the region, this box and the seam's floor all carry the + // strip's pixels or none of them do ([`timeline_fixed_h`]), so the + // lanes keep exactly the room they had at either side of the zoom + // that crosses the line. + let view = self.view(); + let scrollable = view.duration > view.span(); let region_h = self.split_px(Split::Timeline, viewport); - let lanes_box = (region_h - TIMELINE_FIXED_H).max(LANE_H); + let lanes_box = (region_h - timeline_fixed_h(scrollable)).max(LANE_H); let overflows = lanes.len() > lanes_shown(lanes_box); let lanes_box = match overflows { true => (lanes_box - LABEL_H - 8.).max(LANE_H), false => lanes_box, }; - // The scrollbar's geometry, off the very view the wheel and the zoom - // write: `settled` is what those paths clamp to, so the thumb never - // disagrees with where the panel actually is. - let view = self.view(); - let scrollable = view.duration > view.span(); let (thumb_x, thumb_w) = scroll_thumb(view.bed, view.duration, view.scale.start.max(0.), view.span()); // Live, not a count of the lanes: the column reports where it has been // taken to, so the line empties itself as the last track comes up - // instead of insisting there is still something below. + // instead of insisting there is still something below. The stack's own + // strip below reads the same number, so a thumb dragged there and a + // count the affordance lets go of cannot disagree. let scrolled = -f32::from(self.lanes_scroll.offset().y); let below = rows_below(lanes.len(), lanes_box, scrolled); + // The stack's own scrollbar: the thumb is the visible share of the + // lane rows, read straight off the column's own scroll state -- the + // box, the fold and how far down it has been taken are all the + // handle's to know, so nothing here is a second truth about any of + // them. + let stack = self.lanes_scroll.bounds(); + let track_h = f32::from(stack.size.height); + let stack_max = f32::from(self.lanes_scroll.max_offset().height); + let (stack_y, stack_thumb_h) = + lanes_thumb(track_h, track_h + stack_max, track_h, scrolled); div() .flex_none() // Never more than its share of a short window: the lane column @@ -219,93 +237,168 @@ impl Player { // column, so a project with more lanes than the panel is tall // scrolls its tracks instead of pushing the picture off the window. // The gap is the panel's own, so two lanes lay out exactly as they - // did when they were two children of it. + // did when they were two children of it. The column sits in a + // relative box so the stack's own scrollbar can lie *over* the + // beds' right edge: a gutter beside them would take its width off + // the bed, and the ruler above would stop pointing at the moment + // the lanes are drawn at. .child( div() - .id("lanes") - // Takes whatever the region has left and scrolls inside it: - // at the 640x360 floor the region is capped - // ([`TIMELINE_SHARE`]) and a fixed column would be clipped - // by it rather than scrolled. .flex_1() .min_h(px(0.)) - .flex() - .flex_col() - .gap(px(8.)) .max_h(px(lanes_h(LANES_MAX))) - .overflow_y_scroll() - .track_scroll(&self.lanes_scroll) - .children(rows), - ) - // The timeline's own scrollbar: the time axis is the one dimension - // the panel scrolls, and until now only the wheel and the keys - // reached it. The thumb is the visible share of the drawn duration - // and sits where that share is -- 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. - .child( - div() - .flex_none() + .relative() .flex() - .gap(px(HEADER_GAP)) - // Under the lane headers like the ruler is above them, so - // the thumb and the bed it stands for line up. - .child(div().flex_none().w(px(HEADER_W))) + .flex_col() .child( div() - .id("timeline-scroll") + .id("lanes") + // Takes whatever the region has left and scrolls + // inside it: at the 640x360 floor the region is + // capped ([`TIMELINE_SHARE`]) and a fixed column + // would be clipped by it rather than scrolled. .flex_1() - .min_w(px(0.)) - .h(px(SCROLL_HIT_H)) + .min_h(px(0.)) + .w_full() .flex() .flex_col() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER_DIM()))) - .tooltip(|_, cx| { - cx.new(|_| { - Tip("Scroll the timeline — drag the thumb or click to jump; \ - wheel scrolls, ctrl+wheel zooms" - .into()) + .gap(px(8.)) + .overflow_y_scroll() + .track_scroll(&self.lanes_scroll) + .children(rows), + ) + // The lane stack's own scrollbar, drawn only while the + // stack overflows -- the same state the affordance below + // announces -- and never while the whole stack is on + // screen, where a full-height thumb would say nothing the + // lanes themselves do not. It costs the lanes nothing, + // being over the bed rather than out of it, and it is its + // own mouse region: a press there never reaches a clip. + .when(overflows, |d| { + d.child( + div() + .id("lanes-scroll") + .absolute() + .top_0() + .right_0() + .bottom_0() + .w(px(SCROLL_HIT)) + .rounded(px(3.)) + .cursor_pointer() + .hover(|s| s.bg(rgb(BG_HOVER_DIM()))) + .tooltip(|_, cx| { + cx.new(|_| { + Tip("Scroll the tracks — drag the thumb or click to \ + jump; the wheel scrolls them" + .into()) + }) + .into() }) - .into() - }) - .on_scroll_wheel(cx.listener( - |this, event: &ScrollWheelEvent, _, cx| { - this.timeline_wheel(event, cx); - }, - )) - .on_mouse_down( - MouseButton::Left, - cx.listener(|this, event: &MouseDownEvent, _, cx| { - this.scroll_press(event.position.x, cx); - }), - ) - .child( - div() - .w_full() - .h(px(6.)) - .rounded(px(3.)) - .bg(rgb(BG_RAISED())) - .child(bounds_probe(self.scroll_track.clone())) - .child( - div() - .h_full() - .rounded(px(3.)) - .left(px(thumb_x)) - .absolute() - .top_0() - .w(px(thumb_w)) - .bg(rgb(match scrollable { - true => ACCENT_PRIMARY(), - false => FG_SECONDARY(), - })), - ), - ), - ), + .on_scroll_wheel(cx.listener( + |this, event: &ScrollWheelEvent, _, cx| { + this.lanes_wheel(wheel_delta(event), cx); + }, + )) + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, event: &MouseDownEvent, _, cx| { + this.lanes_press(event.position.y, cx); + }), + ) + .child( + div() + .absolute() + .top_0() + .bottom_0() + .left(px((SCROLL_HIT - 6.) / 2.)) + .w(px(6.)) + .rounded(px(3.)) + .bg(rgb(BG_RAISED())) + .child( + div() + .absolute() + .top(px(stack_y)) + .h(px(stack_thumb_h)) + .w_full() + .rounded(px(3.)) + .bg(rgb(ACCENT_PRIMARY())), + ), + ), + ) + }), ) + // The timeline's own scrollbar: the time axis is the one dimension + // the panel scrolls with no bar of its own, and until f69ba33 only + // the wheel and the keys reached it. The thumb is the visible share + // of the drawn duration and sits where that share is -- 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. The row exists only + // while there is somewhere to scroll to: zoomed out to the whole + // timeline the strip is not drawn and no pixels are held for it + // ([`timeline_fixed_h`]) -- a bar for a view that cannot move is a + // bar teaching nothing. + .when(scrollable, |d| { + d.child( + div() + .flex_none() + .flex() + .gap(px(HEADER_GAP)) + // Under the lane headers like the ruler is above them, so + // the thumb and the bed it stands for line up. + .child(div().flex_none().w(px(HEADER_W))) + .child( + div() + .id("timeline-scroll") + .flex_1() + .min_w(px(0.)) + .h(px(SCROLL_HIT)) + .flex() + .flex_col() + .justify_center() + .rounded(px(3.)) + .cursor_pointer() + .hover(|s| s.bg(rgb(BG_HOVER_DIM()))) + .tooltip(|_, cx| { + cx.new(|_| { + Tip("Scroll the timeline — drag the thumb or click to \ + jump; wheel scrolls, ctrl+wheel zooms" + .into()) + }) + .into() + }) + .on_scroll_wheel(cx.listener( + |this, event: &ScrollWheelEvent, _, cx| { + this.timeline_wheel(event, cx); + }, + )) + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, event: &MouseDownEvent, _, cx| { + this.scroll_press(event.position.x, cx); + }), + ) + .child( + div() + .w_full() + .h(px(6.)) + .rounded(px(3.)) + .bg(rgb(BG_RAISED())) + .child(bounds_probe(self.scroll_track.clone())) + .child( + div() + .h_full() + .rounded(px(3.)) + .left(px(thumb_x)) + .absolute() + .top_0() + .w(px(thumb_w)) + .bg(rgb(ACCENT_PRIMARY())), + ), + ), + ), + ) + }) // "It scrolls" is not "it can be found": when the region is too // short for every track -- which is what the 640x360 floor does to a // three-track project -- the lanes below the fold say so, in the one