forge
Explore
Log in

Don't you dare go Hollow

🔀 merge(B1): the timeline measures seconds in pixels — absolute scale, honest zoom stops

Browse files at this commit

0c3c47668ad321209495f31386a4f3deef49ba51Ahmet Kaan GümüşParent: d9fd7cf8baa710
Scale{pps,start}: a second of timeline is a fixed number of pixels wherever it
is, so a clip's width says how long the clip is and adding a second one does not
redraw the first one narrower. width_frac/frac_at are gone; every box, the
playhead, a seek and a trim go through the one mapping.

Composed with main: the transport state machine reads Transport, the panel and
the render loop take their state from it and their geometry from Scale. The
zoom-out tooltip stops lying about where it stops -- four hours on the bed, which
is what ZOOM_MAX_SECONDS actually is.
crates/app/src/main.rsmodified+470 -265
@@ -681,10 +681,10 @@ struct Player {
681681 /// The ruler's own box, recorded at prepaint: a mouse listener is handed
682682 /// the window position and nothing else.
683683 ruler: Rc<Cell<Bounds<Pixels>>>,
684- /// How much of the timeline the ruler and the lanes are showing. Held here
684+ /// How wide a second of timeline is drawn, and from which moment. Held here
685685 /// and nowhere else: every frame-to-pixel answer in the panel comes out of
686686 /// it, so the boxes, the playhead and the pointer cannot disagree.
687- view: View,
687+ scale: Scale,
688688 /// Which clip the edit keys act on: the lane it is in and its index there.
689689 /// The *clicked* half, not the group -- a group is what gets marked on
690690 /// screen, but Lift has to know which half it was aimed at. Indices move
@@ -1201,23 +1201,37 @@ impl Player {
12011201 cx.notify();
12021202 }
12031203
1204- /// Magnifies the timeline about a point that stays put: `anchor` is where
1205- /// along the bed to hold still (a ctrl+wheel holds the pointer), and with
1206- /// none it is the playhead -- so the frame being worked on is still the
1204+ /// The scale against the bed it is drawn on and the timeline it is drawn
1205+ /// from: every clamp, zoom and scroll is worked out through this, and the
1206+ /// bed is measured off the ruler's probe rather than remembered, so a
1207+ /// resized window is a resized view on the very next answer.
1208+ fn view(&self) -> View {
1209+ View {
1210+ scale: self.scale,
1211+ bed: f32::from(self.ruler.get().size.width),
1212+ duration: self.drawn_duration(),
1213+ fps: self.fps,
1214+ }
1215+ }
1216+
1217+ /// Magnifies the timeline about a point that stays put: `anchor` is how many
1218+ /// pixels along the bed to hold still (a ctrl+wheel holds the pointer), and
1219+ /// with none it is the playhead -- so the frame being worked on is still the
12071220 /// frame on screen after the zoom. Clamped at both ends by [`View`]: out
1208- /// stops at the whole timeline, in at a handful of frames.
1221+ /// stops at [`ZOOM_MAX_SECONDS`] on the bed, in at a handful of frames.
12091222 fn zoom(&mut self, factor: f32, anchor: Option<f32>, cx: &mut Context<Self>) {
1210- let duration = self.drawn_duration();
1211- let at = self.playhead(duration);
1212- let anchor = anchor.unwrap_or_else(|| self.view.frac_at(at, duration).clamp(0., 1.));
1213- self.view = self.view.zoomed(factor, anchor, duration, self.fps);
1223+ let view = self.view();
1224+ let at = self.playhead(view.duration);
1225+ let anchor = anchor.unwrap_or_else(|| self.scale.px_at(at).clamp(0., view.bed));
1226+ self.scale = view.zoomed(factor, anchor);
12141227 cx.notify();
12151228 }
12161229
1217- /// All the way back out: the whole timeline across the bed, which is what
1218- /// the panel shows before anyone has zoomed at all.
1230+ /// All the way back out: the whole timeline across the bed, and the one
1231+ /// thing that reads the timeline's own length to decide how wide a second
1232+ /// is drawn.
12191233 fn zoom_fit(&mut self, cx: &mut Context<Self>) {
1220- self.view = View::default();
1234+ self.scale = self.view().fit();
12211235 cx.notify();
12221236 }
12231237
@@ -2421,14 +2435,12 @@ impl Player {
24212435 /// there is no such clip to move. The engine has the last word on where it
24222436 /// may actually go -- this is the ask, not the answer.
24232437 ///
2424- /// ponytail: the bed ends where the timeline does, so a clip cannot be
2425- /// dragged *past* the last frame -- the pointer has no pixel out there to
2426- /// name and [`View::time_at`] clamps to the duration. Room to the right is
2427- /// made by pulling a tail out first ([`Player::drawn_duration`] already
2428- /// lengthens the bed for exactly that gesture). The upgrade is to draw the
2429- /// bed past the end while a clip drag is in flight, the way a trim already
2430- /// does: `drawn_duration` would take the dragged clip's length the same way
2431- /// it takes a trim's reach.
2438+ /// ponytail: the bed now runs past the last frame whenever the timeline is
2439+ /// shorter than the view ([`Scale::time_at`] clamps at the head only), so a
2440+ /// clip *can* be dragged out there. Zoomed in against the far end it cannot:
2441+ /// the scroll clamp pins the bed's right edge to the duration, and the
2442+ /// pointer has no pixel past it. The upgrade is to let the scroll clamp
2443+ /// leave a screen of empty bed after the end, the way every NLE does.
24322444 fn drop_frame(&self, from: Lane, idx: usize, to: Lane, x: Pixels) -> Option<u32> {
24332445 let session = self.session.as_ref()?;
24342446 let clip = session.lane_clips(from).get(idx).copied()?;
@@ -2451,16 +2463,11 @@ impl Player {
24512463 Some(snapped(raw, clip.frames(), self.snap_frames(), &marks))
24522464 }
24532465
2454- /// [`SNAP_PX`] in timeline frames at the zoom the bed is drawn at: a snap is
2455- /// a distance on screen, so zoomed right in it is worth less than a frame
2456- /// (no snap at all, which is what a hand placing single frames wants) and
2457- /// zoomed out to the whole timeline it is worth many.
2466+ /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the bed's
2467+ /// own width drops out of it, since a pixel is now worth the same stretch of
2468+ /// timeline wherever the view sits.
24582469 fn snap_frames(&self) -> u32 {
2459- let bed = f64::from(f32::from(self.ruler.get().size.width));
2460- if bed <= 0. {
2461- return 0;
2462- }
2463- (SNAP_PX / bed * self.view.span(self.drawn_duration()) * self.fps) as u32
2470+ self.scale.snap_frames(self.fps)
24642471 }
24652472
24662473 /// Opens the clip menu on the box under the pointer, from the right button
@@ -2529,14 +2536,13 @@ impl Player {
25292536 }
25302537
25312538 /// The timeline frame a pointer at window x is on: along the same bed the
2532- /// ruler is measured on, through the same [`View`] every box is drawn
2539+ /// ruler is measured on, through the same [`Scale`] every box is drawn
25332540 /// through, so a zoomed-in panel answers with the frame under the pointer
25342541 /// and not with the one that would have been there unzoomed. The one
25352542 /// question a trim, a grab and a drop all ask.
25362543 fn frame_under(&self, x: Pixels) -> u32 {
2537- let duration = self.drawn_duration();
25382544 frame_at(
2539- self.view.time_at(frac_along(x, self.ruler.get()), duration),
2545+ self.scale.time_at(px_along(x, self.ruler.get())),
25402546 self.fps,
25412547 )
25422548 }
@@ -3195,9 +3201,12 @@ impl Player {
31953201 let Some(session) = &self.session else {
31963202 return;
31973203 };
3204+ // Clamped to the timeline here rather than in the mapping: there is bed
3205+ // past the last frame now, and a seek out there is a seek to the end.
31983206 let t = self
3199- .view
3200- .time_at(frac_along(x, self.ruler.get()), session.timeline_duration());
3207+ .scale
3208+ .time_at(px_along(x, self.ruler.get()))
3209+ .clamp(0., session.timeline_duration());
32013210 let target = (t * self.fps) as u32;
32023211 if commit || scrub_due(target, self.last_target, self.last_scrub.elapsed()) {
32033212 self.last_target = target;
@@ -3513,7 +3522,7 @@ impl Render for Player {
35133522 // edit that shortens the timeline moves the far end of the view, and a
35143523 // playhead that has run off the bed pulls the view after it -- which is
35153524 // what makes a zoomed-in timeline scroll while it plays.
3516- self.view = self.view.following(position, duration, self.fps);
3525+ self.scale = self.view().following(position);
35173526
35183527 div()
35193528 .track_focus(&self.focus)
@@ -4289,11 +4298,12 @@ impl Player {
42894298 state: Transport,
42904299 cx: &mut Context<Self>,
42914300 ) -> impl IntoElement {
4292- // Where the playhead is *on the bed*, which at the fit is where along
4293- // the timeline it is and zoomed in is where along the visible slice.
4294- // Clamped because it is drawn as a width as well as an offset, and the
4295- // view follows the playhead anyway, so it is never off the bed.
4296- let filled = self.view.frac_at(position, duration).clamp(0., 1.);
4301+ // Where the playhead is *on the bed*, in pixels from its left edge.
4302+ // Clamped to the bed because it is drawn as a width as well as an
4303+ // offset, and the view follows the playhead anyway, so it is never off
4304+ // the bed for long.
4305+ let bed_w = f32::from(self.ruler.get().size.width);
4306+ let filled = self.scale.px_at(position).clamp(0., bed_w);
42974307 // An export owns the hint slot and the ruler while it runs: the
42984308 // percentage and the accent bar are the same number, so the playhead
42994309 // fill doubles as the progress bar for free.
@@ -4316,7 +4326,7 @@ impl Player {
43164326 // closure would hold it for as long as the iterator lives.
43174327 let mut rows = Vec::new();
43184328 for &lane in &lanes {
4319- rows.push(self.lane_row(lane, duration, filled, cx));
4329+ rows.push(self.lane_row(lane, filled, cx));
43204330 }
43214331 let (hint, filled) = if let Some(export) = self.exporting() {
43224332 let progress = export.progress();
@@ -4515,14 +4525,14 @@ impl Player {
45154525 // How much of the timeline the panel below is showing --
45164526 // beside the resolution, since neither of them edits
45174527 // anything: they are both what is being looked at. The
4518- // middle one reads as the state (1.0x is the whole
4519- // timeline) and is the way back to it.
4528+ // middle one says how much of it is on the bed, and is the
4529+ // way back to the whole of it.
45204530 .child(control(
45214531 "zoom-out",
45224532 None,
45234533 "−",
45244534 format!(
4525- "{} — show more of the timeline; stops at the whole of it",
4535+ "{} — show more of the timeline; stops at four hours on the bed",
45264536 key(ActionId::ZoomOut)
45274537 ),
45284538 live,
@@ -4533,13 +4543,17 @@ impl Player {
45334543 .child(control(
45344544 "zoom-fit",
45354545 None,
4536- format!("{:.1}x", self.view.zoom),
4546+ // How much timeline is on the bed, not a multiple of
4547+ // "the whole of it": the scale no longer knows what the
4548+ // whole of it is, and a number that changed on every
4549+ // import was a number that lied.
4550+ span_label(self.view().span()),
45374551 format!(
45384552 "{} — fit the whole timeline; showing {} to {}",
45394553 key(ActionId::ZoomFit),
4540- timecode(self.view.start, self.fps),
4554+ timecode(self.scale.start, self.fps),
45414555 timecode(
4542- (self.view.start + self.view.span(duration)).min(duration),
4556+ (self.scale.start + self.view().span()).min(duration),
45434557 self.fps
45444558 )
45454559 ),
@@ -4690,7 +4704,7 @@ impl Player {
46904704 if dy == 0. {
46914705 return;
46924706 }
4693- let anchor = frac_along(event.position.x, this.ruler.get());
4707+ let anchor = px_along(event.position.x, this.ruler.get());
46944708 let factor = if dy > 0. { ZOOM_STEP } else { 1. / ZOOM_STEP };
46954709 this.zoom(factor, Some(anchor), cx);
46964710 },
@@ -4712,7 +4726,7 @@ impl Player {
47124726 .child(
47134727 div()
47144728 .h_full()
4715- .w(relative(filled))
4729+ .w(px(filled))
47164730 .rounded(px(3.))
47174731 .bg(rgb(ACCENT)),
47184732 ),
@@ -6667,21 +6681,18 @@ impl Player {
66676681 fn lane_row(
66686682 &self,
66696683 lane: Lane,
6670- duration: f64,
6684+ // Where the playhead is on the bed, in pixels: worked out once by the
6685+ // panel so the ruler's line and every lane's draw the same one.
66716686 filled: f32,
66726687 cx: &mut Context<Self>,
66736688 // Borrows nothing it was given (`use<>`): the rows are built one after
66746689 // another into a list, and a row still holding `cx` would be the only
66756690 // one that could be built.
66766691 ) -> impl IntoElement + use<> {
6677- // The bed's own width, measured last repaint off the ruler's bar: the
6678- // two are laid out identically (same header offset, same `flex_1`), so
6679- // one probe answers for both. Zero before the first paint, which only
6680- // costs the labels one frame.
6681- let bed_w = f32::from(self.ruler.get().size.width);
6682- // The slice being shown, copied out once: every box in the row is
6683- // placed through it, so all of them move together when it does.
6684- let view = self.view;
6692+ // The mapping, copied out once: every box in the row is placed through
6693+ // it, so all of them move together when it does. No bed width is needed
6694+ // to place them any more -- a second is so many pixels wherever it is.
6695+ let scale = self.scale;
66856696 let clips = self
66866697 .session
66876698 .as_ref()
@@ -6865,7 +6876,7 @@ impl Player {
68656876 .and_then(|s| sources.iter().position(|o| o.path == s.path))
68666877 .unwrap_or(clip.source),
68676878 );
6868- let width = view.width_frac(len, duration);
6879+ let width = scale.width_px(len);
68696880 let label = sources.get(clip.source).map(|s| file_name(&s.path));
68706881 let wave = sources
68716882 .get(clip.source)
@@ -6897,8 +6908,8 @@ impl Player {
68976908 // off the left edge: the bed clips what hangs out
68986909 // of it, so a half-visible clip is drawn as the
68996910 // half of itself that is on screen.
6900- .left(relative(view.frac_at(start, duration)))
6901- .w(relative(width))
6911+ .left(px(scale.px_at(start)))
6912+ .w(px(width))
69026913 .overflow_hidden()
69036914 .rounded(px(3.))
69046915 .border_1()
@@ -7041,7 +7052,7 @@ impl Player {
70417052 .child(format!("{}", clip.speed)),
70427053 )
70437054 })
7044- .when_some(label.filter(|_| show_label(bed_w * width)), |d, label| {
7055+ .when_some(label.filter(|_| show_label(width)), |d, label| {
70457056 d.child(
70467057 div()
70477058 .relative()
@@ -7067,12 +7078,8 @@ impl Player {
70677078 .absolute()
70687079 .top_0()
70697080 .h_full()
7070- .left(relative(
7071- view.frac_at(f64::from(at) / self.fps, duration),
7072- ))
7073- .w(relative(
7074- view.width_frac(f64::from(len) / self.fps, duration),
7075- ))
7081+ .left(px(scale.px_at(f64::from(at) / self.fps)))
7082+ .w(px(scale.width_px(f64::from(len) / self.fps)))
70767083 .bg(rgba(0x4a9effaa))
70777084 }),
70787085 )
@@ -7083,7 +7090,7 @@ impl Player {
70837090 .absolute()
70847091 .top_0()
70857092 .h_full()
7086- .left(relative(filled))
7093+ .left(px(filled))
70877094 .w(px(1.))
70887095 .bg(rgb(ACCENT)),
70897096 ),
@@ -8138,10 +8145,6 @@ fn panel_h(lanes: usize) -> f32 {
81388145 PANEL_H + lanes_h(lanes.clamp(2, LANES_MAX)) - lanes_h(2)
81398146 }
81408147
8141-fn width_frac(len: f64, total: f64) -> f32 {
8142- if total > 0. { (len / total) as f32 } else { 1. }
8143-}
8144-
81458148 /// One press of a zoom key, or one notch of ctrl+wheel.
81468149 const ZOOM_STEP: f32 = 1.25;
81478150
@@ -8150,118 +8153,222 @@ const ZOOM_STEP: f32 = 1.25;
81508153 /// not an edit surface.
81518154 const ZOOM_MIN_FRAMES: f64 = 8.;
81528155
8153-/// Which slice of the timeline the ruler and the lanes are showing: `zoom` is
8154-/// how many times the whole of it the bed is now worth, and `start` the moment
8155-/// at the bed's left edge. The one place frames become pixels -- every box, the
8156-/// playhead, a seek and a trim all go through it, so none of them can drift
8157-/// away from the others when the view moves.
8156+/// How much timeline the bed may be widened out to hold. The far stop, and the
8157+/// counterpart of [`ZOOM_MIN_FRAMES`]: both are measured against the bed, never
8158+/// against what is on the timeline, so neither moves when a clip is added.
8159+const ZOOM_MAX_SECONDS: f64 = 4. * 3600.;
8160+
8161+/// How wide a second of timeline is drawn before anyone zooms: a five second
8162+/// import is 200 px of a bed several times that, so a short clip reads as
8163+/// short -- the thing a bed scaled to the content's own length cannot say.
8164+/// [`View::fit`] is the one way back to "the whole timeline across the bed".
8165+const PPS_DEFAULT: f64 = 40.;
8166+
8167+/// What the zoom button says it is showing: how much timeline fits on the bed,
8168+/// in the coarsest unit that still tells two zooms apart.
8169+fn span_label(span: f64) -> String {
8170+ match span {
8171+ s if !s.is_finite() || s <= 0. => "—".to_string(),
8172+ s if s >= 600. => format!("{:.0}m", s / 60.),
8173+ s if s >= 60. => format!("{:.1}m", s / 60.),
8174+ s if s >= 10. => format!("{s:.0}s"),
8175+ s => format!("{s:.1}s"),
8176+ }
8177+}
8178+
8179+/// The mapping the whole panel is drawn and clicked through: `pps` pixels to a
8180+/// second of timeline, `start` the moment at the bed's left edge. Absolute --
8181+/// how wide a clip is drawn depends on how long the clip is and on nothing
8182+/// else, so adding a second clip does not redraw the first one narrower and
8183+/// zooming out always makes every box smaller.
81588184 ///
8159-/// [`View::default`] is the whole timeline across the bed, which is what the
8160-/// panel drew before there was a zoom at all: at zoom 1 `start` is pinned to 0
8161-/// and every fraction here is the one [`width_frac`] and `start_frac` gave.
8185+/// The one place seconds become pixels: every box, the playhead, a seek and a
8186+/// trim all go through it, so none of them can drift away from the others when
8187+/// the view moves. What clamps it -- the stops, the scroll, the fit -- needs the
8188+/// bed it is drawn on and lives on [`View`].
81628189 #[derive(Clone, Copy, Debug, PartialEq)]
8163-struct View {
8164- zoom: f32,
8190+struct Scale {
8191+ pps: f64,
81658192 start: f64,
81668193 }
81678194
8168-impl Default for View {
8195+impl Default for Scale {
81698196 fn default() -> Self {
8170- View {
8171- zoom: 1.,
8197+ Scale {
8198+ pps: PPS_DEFAULT,
81728199 start: 0.,
81738200 }
81748201 }
81758202 }
81768203
8177-impl View {
8178- /// How much of the timeline is on the bed, in seconds.
8179- fn span(self, duration: f64) -> f64 {
8180- duration / f64::from(self.zoom)
8204+impl Scale {
8205+ /// Where a moment sits on the bed, in pixels from its left edge. Negative
8206+ /// for a moment scrolled off to the left, which is exactly the offset a
8207+ /// half-visible clip is drawn at.
8208+ fn px_at(self, at: f64) -> f32 {
8209+ ((at - self.start) * self.pps) as f32
8210+ }
8211+
8212+ /// How wide a stretch of `len` seconds is drawn. Wider than the bed once
8213+ /// zoomed in, which is the point of zooming in; never negative, which gpui
8214+ /// has no meaning for.
8215+ fn width_px(self, len: f64) -> f32 {
8216+ (len * self.pps).max(0.) as f32
8217+ }
8218+
8219+ /// The moment `x` pixels along the bed is pointing at: the inverse of
8220+ /// [`Scale::px_at`], and what every seek and every trim reads. Clamped at
8221+ /// the head of the timeline only -- there is bed past the last frame now,
8222+ /// and a tail dragged into it is a longer clip, not an error.
8223+ fn time_at(self, x: f32) -> f64 {
8224+ if self.pps > 0. {
8225+ (self.start + f64::from(x) / self.pps).max(0.)
8226+ } else {
8227+ self.start
8228+ }
81818229 }
81828230
8183- /// The tightest this timeline may be zoomed: [`ZOOM_MIN_FRAMES`] across the
8184- /// bed. Never under 1 -- a timeline shorter than that is already at its
8185- /// floor, and a zoom that cannot fit the whole of it is not a zoom.
8186- fn max_zoom(duration: f64, fps: f64) -> f32 {
8187- let frames = duration * fps;
8188- if frames > ZOOM_MIN_FRAMES {
8189- (frames / ZOOM_MIN_FRAMES) as f32
8231+ /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: a snap
8232+ /// is a distance on screen, so zoomed right in it is worth less than a frame
8233+ /// (no snap at all, which is what a hand placing single frames wants) and
8234+ /// zoomed out it is worth many.
8235+ fn snap_frames(self, fps: f64) -> u32 {
8236+ if self.pps > 0. {
8237+ (SNAP_PX / self.pps * fps) as u32
81908238 } else {
8191- 1.
8239+ 0
81928240 }
81938241 }
8242+}
81948243
8195- /// Where a moment sits along the bed, 0 at its left edge and 1 at its
8196- /// right. Outside that range for a moment scrolled off the view, which is
8197- /// exactly the negative offset a half-visible clip is drawn at.
8198- fn frac_at(self, at: f64, duration: f64) -> f32 {
8199- let span = self.span(duration);
8200- if span > 0. {
8201- ((at - self.start) / span) as f32
8244+/// A [`Scale`] against the bed it is drawn on and the timeline it is drawn
8245+/// from. The bed's width is what turns a scale into "how much is on screen",
8246+/// and that is all the stops, the scroll clamp and the fit are made of.
8247+///
8248+/// Built per use out of [`Player::view`] and thrown away again -- the state is
8249+/// the `Scale`, and this is what a bed of `bed` px showing `duration` seconds
8250+/// at `fps` may do to it. So no call site can measure a moment against a bed or
8251+/// a duration that another one did not.
8252+#[derive(Clone, Copy, Debug, PartialEq)]
8253+struct View {
8254+ scale: Scale,
8255+ bed: f32,
8256+ duration: f64,
8257+ fps: f64,
8258+}
8259+
8260+impl View {
8261+ /// How much of the timeline is on the bed, in seconds.
8262+ fn span(self) -> f64 {
8263+ if self.scale.pps > 0. {
8264+ f64::from(self.bed) / self.scale.pps
82028265 } else {
82038266 0.
82048267 }
82058268 }
82068269
8207- /// How wide a stretch of `len` seconds is on the bed. More than the whole
8208- /// bed once zoomed in, which is the point of zooming in.
8209- fn width_frac(self, len: f64, duration: f64) -> f32 {
8210- width_frac(len, self.span(duration))
8270+ /// The two stops, in pixels per second: [`ZOOM_MIN_FRAMES`] across the bed
8271+ /// is as tight as it goes, [`ZOOM_MAX_SECONDS`] across it as wide. `None`
8272+ /// on a bed that was never painted -- there is nothing to measure them
8273+ /// against yet, and a stop guessed off a zero width would throw away a zoom
8274+ /// the user asked for.
8275+ fn stops(self) -> Option<(f64, f64)> {
8276+ (self.bed > 0.).then(|| {
8277+ let bed = f64::from(self.bed);
8278+ let min = bed / ZOOM_MAX_SECONDS;
8279+ (min, (bed * self.fps / ZOOM_MIN_FRAMES).max(min))
8280+ })
82118281 }
82128282
8213- /// The moment a pointer at `frac` along the bed is pointing at: the inverse
8214- /// of [`View::frac_at`], and what every seek and every trim reads.
8215- fn time_at(self, frac: f32, duration: f64) -> f64 {
8216- (self.start + f64::from(frac) * self.span(duration)).clamp(0., duration)
8283+ /// Clamped to the bed it draws on: between the two stops, and never
8284+ /// scrolled past either end of the timeline. Unlike the fractional view
8285+ /// this replaced, the *floor* is not the content -- a five second timeline
8286+ /// zooms out as far as an hour long one does.
8287+ fn settled(self) -> Scale {
8288+ let pps = match self.scale.pps.is_finite() && self.scale.pps > 0. {
8289+ true => self.scale.pps,
8290+ false => PPS_DEFAULT,
8291+ };
8292+ let start = match self.scale.start.is_finite() {
8293+ true => self.scale.start,
8294+ false => 0.,
8295+ };
8296+ let Some((min, max)) = self.stops() else {
8297+ return Scale {
8298+ pps,
8299+ start: start.max(0.),
8300+ };
8301+ };
8302+ let pps = pps.clamp(min, max);
8303+ let span = f64::from(self.bed) / pps;
8304+ Scale {
8305+ pps,
8306+ start: start.clamp(0., (self.duration - span).max(0.)),
8307+ }
82178308 }
82188309
8219- /// Zoomed by `factor` about `anchor` (0..1 along the bed): whatever moment
8310+ /// Zoomed by `factor` about `anchor` (pixels along the bed): whatever moment
82208311 /// was under that point stays under it, so a zoom magnifies what was being
82218312 /// looked at rather than throwing it off the edge.
8222- fn zoomed(self, factor: f32, anchor: f32, duration: f64, fps: f64) -> Self {
8223- let at = self.start + f64::from(anchor) * self.span(duration);
8313+ fn zoomed(self, factor: f32, anchor: f32) -> Scale {
8314+ let at = self.scale.time_at(anchor);
82248315 // Clamped *before* the offset is worked out, not after: a press that
82258316 // runs into either stop must still leave the anchor where it is, and a
8226- // start measured against a zoom the stop then took away would slide it.
8227- let zoom = (self.zoom * factor).clamp(1., Self::max_zoom(duration, fps));
8228- let start = at - f64::from(anchor) * View { zoom, start: 0. }.span(duration);
8229- View { zoom, start }.settled(duration, fps)
8230- }
8231-
8232- /// Clamped to the timeline it draws: never wider than the whole of it (the
8233- /// zoom-out floor is the fit), never tighter than [`View::max_zoom`], and
8234- /// never scrolled past either end.
8235- fn settled(self, duration: f64, fps: f64) -> Self {
8236- let zoom = if self.zoom.is_finite() {
8237- self.zoom.clamp(1., Self::max_zoom(duration, fps))
8238- } else {
8239- 1.
8317+ // start measured against a scale the stop then took away would slide it.
8318+ let raw = self.scale.pps * f64::from(factor);
8319+ let pps = match self.stops() {
8320+ Some((min, max)) => raw.clamp(min, max),
8321+ None => raw,
82408322 };
8241- let span = View { zoom, start: 0. }.span(duration);
8242- let start = if self.start.is_finite() {
8243- self.start.clamp(0., (duration - span).max(0.))
8244- } else {
8245- 0.
8323+ View {
8324+ scale: Scale {
8325+ pps,
8326+ start: at - f64::from(anchor) / pps,
8327+ },
8328+ ..self
8329+ }
8330+ .settled()
8331+ }
8332+
8333+ /// The whole timeline across the bed. The one place the content's own
8334+ /// length sets the scale, and the only one -- everywhere else a second is a
8335+ /// second -- because this is a user pressing a key that asks for exactly
8336+ /// that.
8337+ fn fit(self) -> Scale {
8338+ let pps = match self.duration > 0. && self.bed > 0. {
8339+ true => f64::from(self.bed) / self.duration,
8340+ false => PPS_DEFAULT,
82468341 };
8247- View { zoom, start }
8342+ View {
8343+ scale: Scale { pps, start: 0. },
8344+ ..self
8345+ }
8346+ .settled()
82488347 }
82498348
8250- /// The view a playhead at `at` needs: the same one while it is on the bed,
8349+ /// The scale a playhead at `at` needs: the same one while it is on the bed,
82518350 /// and one centred on it once it has run off -- which is how a zoomed-in
8252- /// timeline scrolls, during playback and after a seek alike. At the fit
8253- /// this can never fire, so an unzoomed panel is untouched by it.
8254- fn following(self, at: f64, duration: f64, fps: f64) -> Self {
8255- let view = self.settled(duration, fps);
8256- let span = view.span(duration);
8257- if at < view.start || at > view.start + span {
8351+ /// timeline scrolls, during playback and after a seek alike. With the whole
8352+ /// timeline on the bed this can never fire, so a panel showing all of it is
8353+ /// untouched by it.
8354+ fn following(self, at: f64) -> Scale {
8355+ // Nothing is drawn yet, so nothing has run off anything.
8356+ if self.bed <= 0. {
8357+ return self.scale;
8358+ }
8359+ let scale = self.settled();
8360+ let span = f64::from(self.bed) / scale.pps;
8361+ if at < scale.start || at > scale.start + span {
82588362 View {
8259- start: at - span / 2.,
8260- ..view
8363+ scale: Scale {
8364+ start: at - span / 2.,
8365+ ..scale
8366+ },
8367+ ..self
82618368 }
8262- .settled(duration, fps)
8369+ .settled()
82638370 } else {
8264- view
8371+ scale
82658372 }
82668373 }
82678374 }
@@ -8594,6 +8701,15 @@ fn frac_along(x: Pixels, bounds: Bounds<Pixels>) -> f32 {
85948701 ((x - bounds.left()) / bounds.size.width).clamp(0., 1.)
85958702 }
85968703
8704+/// Where along an element a click landed, in pixels from its own left edge:
8705+/// [`frac_along`] in the units the timeline is drawn in, since a [`Scale`]
8706+/// measures in pixels and not in shares of a bed. Clamped to the element -- a
8707+/// drag that slid off the end names its end -- and an element that was never
8708+/// painted reads as its start.
8709+fn px_along(x: Pixels, bounds: Bounds<Pixels>) -> f32 {
8710+ f32::from(x - bounds.left()).clamp(0., f32::from(bounds.size.width).max(0.))
8711+}
8712+
85978713 /// The frame a dropped clip's head lands on: `raw`, unless one of `marks` is
85988714 /// within `tol` frames of where its head -- or its tail, `len` frames along --
85998715 /// would come to rest, in which case that edge wins. The snap every timeline
@@ -8959,11 +9075,11 @@ mod tests {
89599075 keymap, lanes_h, marked, menu_at, next_container, normalise, nothing_to_play, panel_h,
89609076 project_path, push_digit, retarget, scrub_due, show_label, silence_rate, snapped,
89619077 source_tint, span_partner, speed_at, summary_head, summary_tail, timecode, transport,
8962- unseen_paths, unseen_sources, whole_take, width_frac, window_title,
9078+ unseen_paths, unseen_sources, whole_take, window_title,
89639079 };
89649080 use super::{
8965- LaneKind, Repeat, View, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, library_rows,
8966- repeats, unscannable,
9081+ LaneKind, PPS_DEFAULT, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP,
9082+ file_name, file_uri, library_rows, px_along, repeats, span_label, unscannable,
89679083 };
89689084
89699085 /// What the file manager is handed: the parts a path keeps as they are, and
@@ -10020,10 +10136,10 @@ mod tests {
1002010136 assert_eq!(frac_down(px(50.), Bounds::default()), 0.5);
1002110137 }
1002210138
10023- /// What a drop reads: the frame under the pointer, through the same view
10139+ /// What a drop reads: the frame under the pointer, through the same scale
1002410140 /// the boxes are drawn through. Zoomed in, the same pixel is a different
1002510141 /// frame -- which is the whole reason `Player::frame_under` goes through
10026- /// [`View`] rather than through the duration alone.
10142+ /// [`Scale`] rather than through the duration alone.
1002710143 #[test]
1002810144 fn a_drop_reads_the_frame_under_the_pointer_at_every_zoom() {
1002910145 // A 200 px bed inset by the panel's padding, 10 seconds at 30 fps.
@@ -10031,29 +10147,32 @@ mod tests {
1003110147 origin: point(px(12.), px(400.)),
1003210148 size: size(px(200.), px(6.)),
1003310149 };
10034- let (duration, fps) = (10., 30.);
10150+ let fps = 30.;
1003510151 // The frame a pointer at window `x` names, exactly as `frame_under`
1003610152 // composes it.
10037- let under =
10038- |view: View, x: f32| frame_at(view.time_at(frac_along(px(x), bed), duration), fps);
10153+ let under = |scale: Scale, x: f32| frame_at(scale.time_at(px_along(px(x), bed)), fps);
1003910154
10040- // The whole timeline across the bed: halfway along is frame 150.
10041- let fit = View::default();
10155+ // The whole 10 s timeline across the 200 px bed: 20 px to the second,
10156+ // so halfway along is frame 150.
10157+ let fit = Scale {
10158+ pps: 20.,
10159+ start: 0.,
10160+ };
1004210161 assert_eq!(under(fit, 12.), 0);
1004310162 assert_eq!(under(fit, 112.), 150);
1004410163 assert_eq!(under(fit, 212.), 300);
1004510164
1004610165 // Four times in, starting at second 5: the same middle pixel is now the
1004710166 // frame in the middle of seconds 5..7.5, and the left edge is not 0.
10048- let zoomed = View {
10049- zoom: 4.,
10167+ let zoomed = Scale {
10168+ pps: 80.,
1005010169 start: 5.,
1005110170 };
1005210171 assert_eq!(under(zoomed, 12.), 150);
1005310172 assert_eq!(under(zoomed, 112.), 187);
1005410173 assert_eq!(under(zoomed, 212.), 225);
10055- // ...and a drop past either end of the bed lands on the timeline, never
10056- // outside it: `time_at` clamps.
10174+ // ...and a pointer that slid off either end of the bed names an end of
10175+ // the bed, never a pixel outside it.
1005710176 assert_eq!(under(zoomed, 0.), 150);
1005810177 assert_eq!(under(fit, 9999.), 300);
1005910178 }
@@ -10218,50 +10337,63 @@ mod tests {
1021810337 }
1021910338 }
1022010339
10340+ /// The bed the view tests are drawn on: 200 px at 30 fps, as the drop test
10341+ /// above uses.
10342+ const TEST_BED: f32 = 200.;
10343+
10344+ /// A scale against that bed and a timeline `duration` seconds long.
10345+ fn test_view(scale: Scale, duration: f64) -> View {
10346+ View {
10347+ scale,
10348+ bed: TEST_BED,
10349+ duration,
10350+ fps: 30.,
10351+ }
10352+ }
10353+
1022110354 /// The mapping the whole panel is drawn and clicked through: a moment goes
10222- /// to a fraction of the bed and comes back the same moment, at every zoom.
10223- /// The fit is the invariant that matters most -- it must be the arithmetic
10224- /// the panel did before there was a zoom at all.
10355+ /// to a pixel on the bed and comes back the same moment, at every zoom.
1022510356 #[test]
1022610357 fn a_moment_and_the_place_it_is_drawn_are_the_same_at_every_zoom() {
1022710358 let duration = 20.;
10228- // The fit: what `start_frac`/`width_frac` used to answer, exactly.
10229- let fit = View::default();
10359+ // The fit, which is the only scale the content's own length picks: 20 s
10360+ // across a 200 px bed is 10 px to the second, and a 5 s clip is a
10361+ // quarter of the bed -- the answer the fractional view gave for it.
10362+ let fit = test_view(Scale::default(), duration).fit();
10363+ assert_eq!(fit.pps, 10.);
10364+ assert_eq!(fit.width_px(5.), TEST_BED * 0.25);
1023010365 for t in [0., 5., 12.5, 20.] {
10231- assert_eq!(
10232- fit.frac_at(t, duration),
10233- (t / duration) as f32,
10234- "fit at {t}"
10235- );
10366+ assert_eq!(fit.px_at(t), (t / duration) as f32 * TEST_BED, "fit at {t}");
1023610367 }
10237- assert_eq!(fit.width_frac(5., duration), width_frac(5., duration));
10238- for view in [
10368+ for scale in [
1023910369 fit,
10240- View {
10241- zoom: 2.,
10370+ Scale {
10371+ pps: 20.,
1024210372 start: 4.,
1024310373 },
10244- View {
10245- zoom: 8.,
10374+ Scale {
10375+ pps: 80.,
1024610376 start: 12.5,
1024710377 },
10248- View {
10249- zoom: 37.5,
10378+ Scale {
10379+ pps: 375.,
1025010380 start: 19.,
1025110381 },
1025210382 ] {
10253- let view = view.settled(duration, 30.);
10254- for frac in [0., 0.25, 0.5, 1.] {
10255- let at = view.time_at(frac, duration);
10383+ let scale = test_view(scale, duration).settled();
10384+ for x in [0., 50., 100., TEST_BED] {
10385+ let at = scale.time_at(x);
1025610386 assert!(
10257- (f64::from(view.frac_at(at, duration)) - f64::from(frac)).abs() < 1e-6,
10258- "{view:?} round trip at {frac}"
10387+ (f64::from(scale.px_at(at)) - f64::from(x)).abs() < 1e-3,
10388+ "{scale:?} round trip at {x}"
1025910389 );
1026010390 }
10261- // A stretch is as wide as the share of the visible slice it takes.
10391+ // A stretch as long as what is on the bed is as wide as the bed.
1026210392 assert!(
10263- (f64::from(view.width_frac(view.span(duration), duration)) - 1.).abs() < 1e-6,
10264- "{view:?} spans the bed"
10393+ (f64::from(scale.width_px(test_view(scale, duration).span())) - f64::from(TEST_BED))
10394+ .abs()
10395+ < 1e-3,
10396+ "{scale:?} spans the bed"
1026510397 );
1026610398 }
1026710399 }
@@ -10271,70 +10403,98 @@ mod tests {
1027110403 /// ctrl+wheel.
1027210404 #[test]
1027310405 fn a_zoom_leaves_the_anchor_where_it_was_on_screen() {
10274- let (duration, fps) = (20., 30.);
10275- let mut view = View::default();
10276- for anchor in [0.5f32, 0.25, 0.9] {
10406+ let duration = 20.;
10407+ let mut scale = test_view(Scale::default(), duration).settled();
10408+ // The same three points along the bed the fractional view held: a half,
10409+ // a quarter and nine tenths of 200 px.
10410+ for anchor in [100f32, 50., 180.] {
1027710411 // Well past the zoom-in stop: the anchor holds at the clamp too,
1027810412 // which is where it used to slide (the clamp came after the offset).
1027910413 for _ in 0..30 {
10280- let at = view.time_at(anchor, duration);
10281- let zoomed = view.zoomed(ZOOM_STEP, anchor, duration, fps);
10414+ let at = scale.time_at(anchor);
10415+ let view = test_view(scale, duration);
10416+ let zoomed = view.zoomed(ZOOM_STEP, anchor);
1028210417 // Only where the anchor is not pinned by an edge of the
1028310418 // timeline: a view already against an end cannot slide further.
10284- let pinned = zoomed.start <= 0. || zoomed.start + zoomed.span(duration) >= duration;
10419+ let span = test_view(zoomed, duration).span();
10420+ let pinned = zoomed.start <= 0. || zoomed.start + span >= duration;
1028510421 if !pinned {
1028610422 assert!(
10287- (f64::from(zoomed.frac_at(at, duration)) - f64::from(anchor)).abs() < 1e-6,
10288- "{at} moved: {view:?} -> {zoomed:?}"
10423+ (f64::from(zoomed.px_at(at)) - f64::from(anchor)).abs() < 1e-3,
10424+ "{at} moved: {scale:?} -> {zoomed:?}"
1028910425 );
1029010426 }
10291- assert!(zoomed.zoom >= view.zoom, "and it did zoom in");
10292- view = zoomed;
10427+ assert!(zoomed.pps >= scale.pps, "and it did zoom in");
10428+ scale = zoomed;
1029310429 }
1029410430 }
1029510431 }
1029610432
10297- /// Both stops: out is the whole timeline (which is where the panel starts,
10298- /// so nothing regressed for anyone who never zooms), in is a handful of
10299- /// frames -- and neither can scroll off an end.
10433+ /// Both stops, and the point of the whole mapping: neither is the content's
10434+ /// own length any more. Out is [`ZOOM_MAX_SECONDS`] across the bed, in is
10435+ /// [`ZOOM_MIN_FRAMES`] across it -- so a short import can be zoomed out of
10436+ /// and a long one zoomed into, and neither can scroll off an end.
1030010437 #[test]
10301- fn zoom_stops_at_the_whole_timeline_and_at_a_handful_of_frames() {
10438+ fn zoom_stops_at_a_bedful_of_time_and_at_a_handful_of_frames() {
1030210439 let (duration, fps) = (20., 30.);
10303- let mut view = View::default();
10440+ let mut scale = Scale::default();
1030410441 for _ in 0..200 {
10305- view = view.zoomed(1. / ZOOM_STEP, 0.5, duration, fps);
10442+ scale = test_view(scale, duration).zoomed(1. / ZOOM_STEP, 100.);
1030610443 }
10307- assert_eq!(view, View::default(), "zoomed out is the fit");
10444+ assert!(
10445+ (test_view(scale, duration).span() - ZOOM_MAX_SECONDS).abs() < 1e-6,
10446+ "widest is a bedful of hours, not the 20 s that happen to be on it"
10447+ );
1030810448 for _ in 0..200 {
10309- view = view.zoomed(ZOOM_STEP, 0.5, duration, fps);
10449+ scale = test_view(scale, duration).zoomed(ZOOM_STEP, 100.);
1031010450 }
1031110451 assert_eq!(
10312- (view.span(duration) * fps).round(),
10452+ (test_view(scale, duration).span() * fps).round(),
1031310453 ZOOM_MIN_FRAMES,
1031410454 "tightest is a handful of frames"
1031510455 );
1031610456 // Against the far end, the slice still ends at the last frame.
10317- let end = View {
10318- zoom: view.zoom,
10319- start: 1e6,
10320- }
10321- .settled(duration, fps);
10322- assert!((end.start + end.span(duration) - duration).abs() < 1e-9);
10323- assert!(
10324- View {
10325- zoom: view.zoom,
10326- start: -5.
10327- }
10328- .settled(duration, fps)
10329- .start
10330- == 0.
10457+ let end = test_view(
10458+ Scale {
10459+ start: 1e6,
10460+ ..scale
10461+ },
10462+ duration,
10463+ );
10464+ let end = (end.settled(), end.span());
10465+ assert!((end.0.start + end.1 - duration).abs() < 1e-9);
10466+ assert_eq!(
10467+ test_view(
10468+ Scale {
10469+ start: -5.,
10470+ ..scale
10471+ },
10472+ duration
10473+ )
10474+ .settled()
10475+ .start,
10476+ 0.
1033110477 );
10332- // A timeline too short to zoom into, and one with no length at all,
10333- // both stay at the fit rather than dividing by nothing.
10334- assert_eq!(View::max_zoom(0.1, fps), 1.);
10335- assert_eq!(View::default().settled(0., fps), View::default());
10336- assert_eq!(View::default().frac_at(3., 0.), 0.);
10337- assert_eq!(View::default().time_at(0.5, 0.), 0.);
10478+ // The dead zone the fractional view had: a timeline of a handful of
10479+ // frames could not be zoomed at all, because its own length was the
10480+ // floor *and* the ceiling. Both keys work on it now.
10481+ let tiny = test_view(Scale::default(), 0.1);
10482+ assert!(tiny.zoomed(ZOOM_STEP, 100.).pps > PPS_DEFAULT);
10483+ assert!(tiny.zoomed(1. / ZOOM_STEP, 100.).pps < PPS_DEFAULT);
10484+ // A timeline with no length at all divides by nothing and scrolls
10485+ // nowhere; the fit of one keeps the scale it had.
10486+ let empty = test_view(Scale::default(), 0.);
10487+ assert_eq!(empty.settled(), Scale::default());
10488+ assert_eq!(empty.fit(), Scale::default());
10489+ assert_eq!(Scale::default().px_at(0.), 0.);
10490+ // A bed that was never painted clamps nothing -- there is nothing to
10491+ // clamp against, and a zoom must survive the frame before the probe.
10492+ let unpainted = View {
10493+ bed: 0.,
10494+ ..test_view(Scale { pps: 4e6, start: 3. }, duration)
10495+ };
10496+ assert_eq!(unpainted.settled().pps, 4e6);
10497+ assert_eq!(unpainted.following(19.), unpainted.scale);
1033810498 }
1033910499
1034010500 /// What makes a zoomed timeline follow the playing head: off the bed at
@@ -10342,53 +10502,96 @@ mod tests {
1034210502 /// view that jumped every frame would be unreadable.
1034310503 #[test]
1034410504 fn the_view_follows_a_playhead_that_runs_off_the_bed() {
10345- let (duration, fps) = (20., 30.);
10346- let view = View {
10347- zoom: 4.,
10348- start: 5.,
10349- }
10350- .settled(duration, fps);
10351- assert_eq!(view.span(duration), 5.);
10505+ let duration = 20.;
10506+ // 5 s on a 200 px bed: 40 px to the second, starting at second 5.
10507+ let view = test_view(
10508+ Scale {
10509+ pps: 40.,
10510+ start: 5.,
10511+ },
10512+ duration,
10513+ );
10514+ let scale = view.settled();
10515+ assert_eq!(view.span(), 5.);
1035210516 // Inside: untouched, whichever part of the slice it is in.
1035310517 for at in [5., 7.5, 10.] {
10354- assert_eq!(
10355- view.following(at, duration, fps),
10356- view,
10357- "{at} is on the bed"
10358- );
10518+ assert_eq!(view.following(at), scale, "{at} is on the bed");
1035910519 }
1036010520 // Past the right edge, as playback does it: the head comes back on the
10361- // bed, and the zoom is not changed by the scroll.
10362- let moved = view.following(12., duration, fps);
10363- assert_eq!(moved.zoom, view.zoom);
10364- assert!(moved.start > view.start, "scrolled forward");
10521+ // bed, and the scale is not changed by the scroll.
10522+ let moved = view.following(12.);
10523+ assert_eq!(moved.pps, scale.pps);
10524+ assert!(moved.start > scale.start, "scrolled forward");
1036510525 assert!(
10366- moved.frac_at(12., duration) > 0. && moved.frac_at(12., duration) < 1.,
10526+ moved.px_at(12.) > 0. && moved.px_at(12.) < TEST_BED,
1036710527 "and the playhead is on screen"
1036810528 );
1036910529 // A seek back behind the slice does the same the other way.
10370- let back = view.following(1., duration, fps);
10371- assert!(back.start < view.start);
10372- assert!(back.frac_at(1., duration) >= 0.);
10373- // At the fit there is nothing to follow: the whole timeline is on the
10374- // bed already, so no playhead can move it.
10530+ let back = view.following(1.);
10531+ assert!(back.start < scale.start);
10532+ assert!(back.px_at(1.) >= 0.);
10533+ // With the whole timeline on the bed there is nothing to follow.
10534+ let whole = test_view(Scale::default(), duration);
10535+ let fit = whole.fit();
1037510536 for at in [0., 10., 20.] {
1037610537 assert_eq!(
10377- View::default().following(at, duration, fps),
10378- View::default(),
10538+ test_view(fit, duration).following(at),
10539+ fit,
1037910540 "the fit never scrolls"
1038010541 );
1038110542 }
1038210543 }
1038310544
10545+ /// The bug this mapping exists for: the first import used to fill the whole
10546+ /// track whatever it was, because the bed *was* the timeline -- so a 5 s
10547+ /// clip was 100% of the lane, zooming out did nothing, and adding a second
10548+ /// clip silently halved the first one's box.
10549+ #[test]
10550+ fn a_clip_is_drawn_the_same_width_whatever_else_is_on_the_timeline() {
10551+ let bed = 900.;
10552+ let of = |duration: f64| View {
10553+ scale: Scale::default(),
10554+ bed,
10555+ duration,
10556+ fps: 30.,
10557+ };
10558+ // One 5 s import, then a second clip after it: 20 s of timeline where
10559+ // there were 5, and the first box has not moved or narrowed.
10560+ let (alone, joined) = (of(5.).settled(), of(20.).settled());
10561+ assert_eq!(alone, joined);
10562+ assert_eq!(alone.width_px(5.), joined.width_px(5.));
10563+ assert_eq!(joined.px_at(5.), alone.width_px(5.));
10564+ // And it does not fill the track: a short clip reads as short.
10565+ assert!(
10566+ alone.width_px(5.) < bed / 2.,
10567+ "5 s at {} px/s is {} px of a {bed} px bed",
10568+ alone.pps,
10569+ alone.width_px(5.)
10570+ );
10571+ // Zooming out visibly shrinks it, however short the timeline is -- the
10572+ // press that used to be a no-op.
10573+ let out = of(5.).zoomed(1. / ZOOM_STEP, 0.);
10574+ assert!(
10575+ out.width_px(5.) < alone.width_px(5.),
10576+ "{} px is not smaller than {} px",
10577+ out.width_px(5.),
10578+ alone.width_px(5.)
10579+ );
10580+ // The way back to "the whole timeline across the bed" is still one key.
10581+ assert_eq!(of(5.).fit().width_px(5.), bed);
10582+ }
10583+
10584+ /// What the zoom button says: how much timeline is on the bed, in a unit
10585+ /// that tells two zooms apart.
1038410586 #[test]
10385- fn clip_boxes_split_the_lane_by_duration() {
10386- // 1 s + 3 s of a 4 s timeline: a quarter and three quarters.
10387- assert_eq!(width_frac(1., 4.), 0.25);
10388- assert_eq!(width_frac(3., 4.), 0.75);
10389- assert_eq!(width_frac(4., 4.), 1.);
10390- // A timeline with no length must not hand gpui a NaN width.
10391- assert_eq!(width_frac(0., 0.), 1.);
10587+ fn the_zoom_button_says_how_much_is_on_the_bed() {
10588+ assert_eq!(span_label(4.5), "4.5s");
10589+ assert_eq!(span_label(22.5), "22s");
10590+ assert_eq!(span_label(90.), "1.5m");
10591+ assert_eq!(span_label(3600.), "60m");
10592+ // Before the first paint there is no bed and so no answer to give.
10593+ assert_eq!(span_label(0.), "—");
10594+ assert_eq!(span_label(f64::NAN), "—");
1039210595 }
1039310596
1039410597 #[test]
@@ -11525,10 +11728,11 @@ mod tests {
1152511728 assert!(show_label(LABEL_MIN_W));
1152611729 assert!(show_label(400.));
1152711730 assert!(!show_label(LABEL_MIN_W - 0.1));
11528- // A timeline with no length must not put a box outside its lane.
11529- let fit = View::default();
11530- assert_eq!(fit.frac_at(3., 0.), 0.);
11531- assert_eq!(fit.frac_at(1., 4.), 0.25);
11731+ // The label test is the box's own width in pixels now, which is what
11732+ // the scale hands it -- no bed width, and so nothing to be zero.
11733+ let scale = Scale::default();
11734+ assert!(show_label(scale.width_px(LABEL_MIN_W as f64 / PPS_DEFAULT)));
11735+ assert!(!show_label(scale.width_px(0.)));
1153211736 }
1153311737
1153411738 #[test]
@@ -11894,9 +12098,10 @@ fn main() {
1189412098 image: None,
1189512099 held: None,
1189612100 ruler: Rc::default(),
11897- // The whole timeline across the bed, which is where a
11898- // project opens: zooming is something the user asks for.
11899- view: View::default(),
12101+ // A second is [`PPS_DEFAULT`] pixels wide until someone
12102+ // zooms or asks for the fit: a project opens at a scale, not
12103+ // at whatever its first import happens to be long.
12104+ scale: Scale::default(),
1190012105 selected: None,
1190112106 context_menu: None,
1190212107 library_menu: None,