forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

ruler.rs603 lines, 25.9 KiBHistoryRawDownload
1//! The pinned ruler: ticks, timecode plate, the playhead's lamp tab and line (DESIGN §6.5).
2
3use super::*;
4use crate::timeline_math::{ruler_label, ruler_step};
5use crate::ui::widgets::MarkerField;
6
7/// The pixel pitch a tick label needs before the next one may be drawn
8/// (DESIGN §6.5): 80px keeps a `1:00:00` label clear of its neighbour at
9/// the 12px mono floor.
10const TICK_MIN_PX: f64 = 80.;
11/// The least clear gap kept between one label's end and the next label's start.
12const LABEL_GAP_PX: f32 = 8.;
13/// The black halo either side of the playhead line, in px (DESIGN §4.1).
14const PLAYHEAD_HALO: f32 = 1.;
15
16/// The playhead timecode plate's own width: eleven mono characters at the
17/// 14px readout role plus its horizontal padding and a 1px rounding guard,
18/// derived from the shared list-character calibration so the plate grows with
19/// its type scale.
20const PLATE_W: f32 = 11. * crate::layout::LIST_CHAR_W / type_scale::CHORD_METADATA_MIN_PX
21 * type_scale::CHORD_METADATA_MAX_PX
22 + 9.;
23
24/// The ruler's ticks as `(x, label)` in the bed's own pixels. The step and
25/// its labels live in `timeline_math` ([`ruler_step`], [`ruler_label`]):
26/// human stops (frames, then 1 s, 2 s, 5 s, 10 s, 30 s, a minute...) read as
27/// `2s`, `1:30` and `+10f`, never a colon form a reader could take for the
28/// transport's `HH:MM:SS:FF`. Walked from the first tick at or after the
29/// bed's left edge to its right edge; a label that would start within
30/// [`LABEL_GAP_PX`] of the previous one's end, or inside the first `plate_w`
31/// pixels, is skipped, so no two labels ever touch. Pure, so the test pins the
32/// sequence without a window.
33pub(super) fn ticks(scale: Scale, fps: f64, bed_w: f32, plate_w: f32) -> Vec<(f32, String)> {
34 let mut ticks = Vec::new();
35 // Guarded on `pps > 0` -- a zero scale (no session yet) has no step that
36 // ever advances past the bed's own width, which would loop forever.
37 if scale.pps <= 0. {
38 return ticks;
39 }
40 let step = ruler_step(scale.pps, fps, TICK_MIN_PX);
41 let secs = step.secs(fps);
42 // Walked by index, not by summing `secs`, so a frame step's position
43 // does not drift off its frame over a long bed.
44 let mut i = (scale.start / secs).ceil().max(0.);
45 let mut label_end = f32::NEG_INFINITY;
46 while scale.px_at(i * secs) <= bed_w {
47 let x = scale.px_at(i * secs).max(0.);
48 let label = ruler_label(step, i as u64, fps);
49 let label_w = label.chars().count() as f32 * char_w(type_scale::FLOOR_PX);
50 if x >= plate_w && x + label_w <= bed_w && x >= label_end + LABEL_GAP_PX {
51 label_end = x + label_w;
52 ticks.push((x, label));
53 }
54 i += 1.;
55 }
56 ticks
57}
58
59/// The shade of the In-Out range on the ruler and the overview strip.
60pub(crate) const RANGE_SHADE: u32 = 0x5aa0ff40;
61
62/// The In-Out range as `(x, width)` in the ruler's pixels, clipped to the
63/// bed; `None` when no range is set or it is wholly off the bed.
64pub(super) fn range_band(
65 range: Option<(u32, u32)>,
66 fps: f64,
67 scale: crate::viewport::Scale,
68 bed_w: f32,
69) -> Option<(f32, f32)> {
70 let (a, b) = range?;
71 let x0 = scale.px_at(f64::from(a) / fps).max(0.);
72 let x1 = scale.px_at(f64::from(b) / fps).min(bed_w);
73 (x1 > x0).then_some((x0, x1 - x0))
74}
75
76/// The pinned ruler: click or drag to seek, tick marks with mono `ink3`
77/// timecodes, and the playhead's own lamp-white line with its grab tab
78/// (DESIGN §6.5). `render` places it; the tick and timecode-plate maths live
79/// here with it.
80pub(super) fn ruler(
81 player: &Player,
82 position: f64,
83 cx: &mut Context<Player>,
84) -> impl IntoElement + use<> {
85 let scale = player.scale;
86 let bed_w = f32::from(player.ruler.get().size.width).max(1.);
87 let filled = scale.px_at(position).clamp(0., bed_w);
88 // Ruler ticks (DESIGN §6.5): see [`ticks`].
89 // The ruler's one reserved band, which no tick label may enter: the
90 // playhead timecode plate, which now shows only while a scrub
91 // drag is live (the hero timecode leads the time band at rest, DESIGN
92 // §4, and the ledger keeps position, §6.6 -- a third resting copy is the
93 // crowding) -- at rest the band is zero and the ticks have the width
94 // back.
95 let plate_w = if player.scrubbing { PLATE_W } else { 0. };
96 let fps = player.fps;
97 let ticks = ticks(scale, fps, bed_w, plate_w);
98 let flags: Vec<(f32, f32)> = player
99 .session
100 .as_ref()
101 .map(|s| marker_flags(s.markers(), fps, scale, bed_w).into_iter().map(|f| (f.x, f.reach())).collect())
102 .unwrap_or_default();
103 // The playhead line is 3px while the transport runs and 2px at rest
104 // (DESIGN §4.1), each with a 1px black halo either side, so the line is
105 // the same white on every clip colour and the moving one reads as live
106 // without a colour change.
107 let playing = player.transport().is_playing();
108 let playhead_w = if playing { 3. } else { 2. };
109 let playhead_tc = crate::viewport::timecode(position, fps);
110 div()
111 .id("bench-ruler")
112 .flex_none()
113 .h(px(RULER_H))
114 .ml(px(HEAD_W))
115 .relative()
116 .bg(rgb(crate::ui::theme::tokens().e1))
117 .border_b_1()
118 .border_color(rgba(crate::ui::theme::tokens().line))
119 .cursor_pointer()
120 .child(bounds_probe(player.ruler.clone()))
121 // The In-Out range, shaded behind the ticks as an NLE does.
122 .children(range_band(player.range, fps, scale, bed_w).map(|(x, w)| {
123 div()
124 .id("bench-ruler-range")
125 .absolute()
126 .bottom_0()
127 .h(px(4.))
128 .left(px(x))
129 .w(px(w))
130 .bg(rgba(crate::ui::theme::with_alpha(crate::ui::theme::tokens().accent, 0x66)))
131 }))
132 // The render bar (DESIGN.md §6.5): green where a render matches the timeline, amber
133 // where a clip with effects still has none. A 3px strip laid over the ruler's top
134 // edge, so no height changes when it appears.
135 .children(player.render_bands.iter().filter_map(|band| {
136 let (x, w) = range_band(Some((band.from, band.to)), fps, scale, bed_w)?;
137 let tokens = crate::ui::theme::tokens();
138 let colour = if band.cached { tokens.ok } else { tokens.warn };
139 Some(
140 div()
141 .id("bench-ruler-render")
142 .absolute()
143 .top_0()
144 .h(px(3.))
145 .left(px(x))
146 .w(px(w))
147 .bg(rgb(colour)),
148 )
149 }))
150 // The render being made fills green from its start as it goes.
151 .children(player.render_progress.and_then(|((from, to), done)| {
152 let to_done = from + ((to - from) as f32 * done) as u32;
153 let (x, w) = range_band(Some((from, to_done)), fps, scale, bed_w)?;
154 Some(
155 div()
156 .id("bench-ruler-render-progress")
157 .absolute()
158 .top_0()
159 .h(px(3.))
160 .left(px(x))
161 .w(px(w))
162 .bg(rgb(crate::ui::theme::tokens().ok)),
163 )
164 }))
165 .on_mouse_down(
166 MouseButton::Left,
167 cx.listener(|this, event: &MouseDownEvent, _, cx| {
168 this.scrubbing = true;
169 this.clear_picks(cx);
170 this.scrub_to(event.position.x, true, cx);
171 }),
172 )
173 // The bench's own menu, on the strip that *is* the timeline:
174 // walking the cuts, the zoom, the snap and the undo pair, none
175 // of which is about a clip (DESIGN §9).
176 .on_mouse_down(
177 MouseButton::Right,
178 cx.listener(|this, event: &MouseDownEvent, _, cx| {
179 this.open_bench_menu(event.position, cx);
180 }),
181 )
182 // Major ticks 8px with the label 4px to their right, minor ticks 4px halfway
183 // between; a label that would sit under the playhead's head is left out.
184 .children(ticks.iter().enumerate().flat_map(|(i, (x, label))| {
185 let x = *x;
186 let w = label.chars().count() as f32 * 7.2 + 6.;
187 let under_head = x + 4. + w >= filled - 8. && x + 4. <= filled + 8.;
188 // A flag stands at each marker: a label that would run under one yields to it.
189 let under_flag = flags.iter().any(|(from, to)| x + 4. + w >= *from - 4. && x + 2. <= *to);
190 let minor = ticks.get(i + 1).map(|(n, _)| x + (n - x) / 2.);
191 let tick = div()
192 .absolute()
193 .bottom_0()
194 .left(px(x))
195 .w(px(1.))
196 .h(px(8.))
197 .bg(rgb(INK3()));
198 let text = (!under_head && !under_flag).then(|| {
199 div()
200 .absolute()
201 .top(px(3.))
202 .left(px(x + 3.))
203 .px(px(2.))
204 .rounded(px(2.))
205 // A plate in the ruler's own ground, so nothing drawn under the text
206 // (a range band, a neighbouring flag) cuts through it.
207 .bg(rgb(crate::ui::theme::tokens().e1))
208 .whitespace_nowrap()
209 .type_style(type_scale::caption())
210 .text_color(rgb(INK3()))
211 .child(label.clone())
212 });
213 let half = minor.map(|m| {
214 div()
215 .absolute()
216 .bottom_0()
217 .left(px(m))
218 .w(px(1.))
219 .h(px(4.))
220 .bg(rgb(INK3()))
221 });
222 [Some(tick.into_any_element()), text.map(IntoElement::into_any_element), half.map(IntoElement::into_any_element)]
223 .into_iter()
224 .flatten()
225 .collect::<Vec<_>>()
226 }))
227 .child(
228 div()
229 .absolute()
230 .top_0()
231 .h_full()
232 .left(px(filled - PLAYHEAD_HALO))
233 .w(px(playhead_w + 2. * PLAYHEAD_HALO))
234 .bg(rgba(DARK_SEAM())),
235 )
236 .child(
237 div()
238 .absolute()
239 .top_0()
240 .h_full()
241 .left(px(filled))
242 .w(px(playhead_w))
243 .bg(rgb(LAMP_WHITE())),
244 )
245 // The lamp tab: the one part of the playhead a press can grab. Its
246 // 24px box is centred on the playhead and sits inside the ruler, so a
247 // press there bubbles up to the ruler's own left handler and scrubs
248 // through that same path -- no second one to keep in step.
249 .child(
250 div()
251 .absolute()
252 .top(px(1.))
253 .left(px(filled - crate::layout::HIT_MIN / 2.))
254 .w(px(crate::layout::HIT_MIN))
255 .h(px(crate::layout::HIT_MIN))
256 .flex()
257 .justify_center()
258 .child(playhead_head()),
259 )
260 // The In and Out marks as brackets, facing in over the range they bound.
261 .children(range_brackets(player.range, fps, scale, bed_w))
262 // The comment markers: a flag in each one's colour on a strip along the ruler's foot,
263 // its name beside it where there is room -- a point is a 3px post, a range runs from
264 // its start to its end. Over the playhead's line, so a marker under it stays seen.
265 .children(marker_marks(player, bed_w, cx))
266 .when(player.scrubbing, |ruler| {
267 // The playhead timecode plate, and ONLY while a scrub drag
268 // is live: a drag is a state change, which is what a plate
269 // is for. At rest the hero timecode leads the time band
270 // (DESIGN §4) and the ledger carries position (§6.6); this
271 // was the third resting copy of the same reading. Always
272 // at `left_0`, never following the scrubbed x, so it never
273 // overlaps the picture region above it.
274 ruler.child(
275 div()
276 .absolute()
277 .top_0()
278 .left_0()
279 .h_full()
280 .w(px(PLATE_W))
281 .flex()
282 .items_center()
283 .px(px(4.))
284 .bg(rgb(DARK_CANVAS()))
285 .type_style(type_scale::mono(
286 type_scale::CHORD_METADATA_MAX_PX,
287 gpui::FontWeight::MEDIUM,
288 ))
289 .text_color(rgb(INK1()))
290 .child(playhead_tc),
291 )
292 })
293}
294
295/// The playhead's head: a 12x14 pentagon in the lamp colour, point down.
296fn playhead_head() -> impl IntoElement {
297 canvas(
298 |_, _, _| (),
299 move |bounds, _, window, _| {
300 let o = bounds.origin;
301 let pts = [(0., 0.), (12., 0.), (12., 8.), (6., 14.), (0., 8.)]
302 .map(|(x, y)| point(o.x + px(x), o.y + px(y)));
303 let mut path = gpui::PathBuilder::fill();
304 path.add_polygon(&pts, true);
305 if let Ok(path) = path.build() {
306 window.paint_path(path, rgb(LAMP_WHITE()));
307 }
308 },
309 )
310 .w(px(12.))
311 .h(px(14.))
312}
313
314/// The marker strip's marks as `(x, width, colour)` in the ruler's own pixels: a point is
315/// [`MARK_POINT_W`] wide, a range as wide as it runs (never narrower than a point), and a
316/// mark wholly off the bed is left out. Pure, so the test pins it without a window.
317#[cfg_attr(not(test), allow(dead_code))]
318pub(super) fn marker_spans(
319 markers: &[engine::project::Marker],
320 fps: f64,
321 scale: Scale,
322 bed_w: f32,
323) -> Vec<(f32, f32, engine::project::MarkerColor)> {
324 if fps <= 0. || scale.pps <= 0. {
325 return Vec::new();
326 }
327 markers
328 .iter()
329 .filter_map(|m| {
330 let x = scale.px_at(f64::from(m.frame) / fps);
331 let end = scale.px_at(f64::from(m.end()) / fps);
332 let w = (end - x).max(MARK_POINT_W);
333 (x <= bed_w && x + w >= 0.).then_some((x, w, m.color))
334 })
335 .collect()
336}
337
338/// A point marker's width on the ruler, in px.
339pub(super) const MARK_POINT_W: f32 = 3.;
340
341/// The marker strip's height at the ruler's foot, in px.
342const MARK_H: f32 = 6.;
343
344/// A marker's flag on the ruler: where it stands, the strip it covers, its colour and the name
345/// that fits beside it (empty when there is no room).
346pub(super) struct Flag {
347 /// The marker's place in the session's list, the one a click on the flag names.
348 pub(super) idx: usize,
349 pub(super) x: f32,
350 pub(super) w: f32,
351 pub(super) color: engine::project::MarkerColor,
352 pub(super) name: String,
353}
354
355impl Flag {
356 /// Where the flag, and its name, end.
357 fn reach(&self) -> f32 {
358 let name = match self.name.is_empty() {
359 true => 0.,
360 false => self.name.chars().count() as f32 * char_w(type_scale::FLOOR_PX) + 8.,
361 };
362 self.x + (self.w).max(14.) + name
363 }
364}
365
366/// The least room beside a flag worth a name, in px.
367const FLAG_NAME_MIN_PX: f32 = 36.;
368
369/// The flags in order along the ruler, each named as far as the room up to the next flag (or
370/// the bed's end) allows: a name that does not fit whole is cut with an ellipsis, and one with
371/// less than [`FLAG_NAME_MIN_PX`] left is left off. Pure, so a test pins it.
372pub(super) fn marker_flags(markers: &[engine::project::Marker], fps: f64, scale: Scale, bed_w: f32) -> Vec<Flag> {
373 if fps <= 0. || scale.pps <= 0. {
374 return Vec::new();
375 }
376 let mut spans: Vec<_> = markers
377 .iter()
378 .enumerate()
379 .filter_map(|(idx, m)| {
380 let x = scale.px_at(f64::from(m.frame) / fps);
381 let w = (scale.px_at(f64::from(m.end()) / fps) - x).max(MARK_POINT_W);
382 (x <= bed_w && x + w >= 0.).then(|| (x, w, m.color, m.name.clone(), idx))
383 })
384 .collect();
385 spans.sort_by(|a, b| a.0.total_cmp(&b.0));
386 let ahead: Vec<f32> = spans.iter().skip(1).map(|s| s.0).chain([bed_w]).collect();
387 spans
388 .into_iter()
389 .zip(ahead)
390 .map(|((x, w, color, name, idx), next)| {
391 let room = next - x.max(0.) - w.max(14.) - 8.;
392 let per = char_w(type_scale::FLOOR_PX).max(1.);
393 let name = match (name.is_empty(), room >= FLAG_NAME_MIN_PX) {
394 (true, _) | (_, false) => String::new(),
395 _ => {
396 let fit = (room / per).floor() as usize;
397 match name.chars().count() > fit {
398 true => name.chars().take(fit.saturating_sub(1)).collect::<String>().trim_end().to_string() + "\u{2026}",
399 false => name,
400 }
401 }
402 };
403 Flag { idx, x, w, color, name }
404 })
405 .collect()
406}
407
408/// The width of a marker's hit area on the ruler, in px: wide enough to double-click, centred on
409/// the flag.
410const MARK_HIT_W: f32 = 14.;
411
412fn marker_marks(player: &Player, bed_w: f32, cx: &mut Context<Player>) -> Vec<gpui::AnyElement> {
413 let Some(session) = player.session.as_ref() else {
414 return Vec::new();
415 };
416 // The name being retyped, if it is a marker's name: that marker's flag shows the field
417 // in its name's place, so the rename happens on the ruler and nowhere else.
418 let editing = player
419 .marker_edit
420 .as_ref()
421 .filter(|e| e.field == MarkerField::Name)
422 .cloned();
423 marker_flags(session.markers(), player.fps, player.scale, bed_w)
424 .into_iter()
425 .map(|Flag { idx, x, w, color, name }| {
426 // A flag in the marker's colour standing on the strip, so a marker reads at a
427 // glance; the strip under it is the range it covers.
428 // The hit area is centred on the flag; the flag sits inside it at its own offset.
429 let hit_w = w.max(MARK_HIT_W);
430 let hit_x = x + w / 2. - hit_w / 2.;
431 let retyped = editing.as_ref().filter(|e| e.idx == idx);
432 let flag = div()
433 .absolute()
434 .bottom_0()
435 .left(px(x - hit_x))
436 .w(px(w))
437 .h(px(MARK_H))
438 .bg(rgb(marker_rgb(color)))
439 .child(
440 div()
441 .absolute()
442 .bottom(px(MARK_H - 1.))
443 .left(px(-3.))
444 .child(crate::ui::icons::Icon::FlagTriangleRight.el(crate::ui::icons::IconSize::Inline, marker_rgb(color))),
445 )
446 .when(!name.is_empty() && retyped.is_none(), |d| {
447 d.child(
448 div()
449 .absolute()
450 .bottom(px(MARK_H))
451 .left(px(w.max(14.) - 2.))
452 .px(px(3.))
453 .rounded(px(2.))
454 .bg(rgb(crate::ui::theme::tokens().e1))
455 .whitespace_nowrap()
456 .type_style(type_scale::caption())
457 .text_color(rgb(crate::ui::theme::tokens().ink1))
458 .child(name),
459 )
460 });
461 // The flag's own hit area, a little wider than the flag and the ruler's full height:
462 // a right-click names the marker (its menu), a double-click renames it. Its
463 // right-click stops here, so the bench's menu does not open under it.
464 div()
465 .id(("ruler-marker", idx))
466 .absolute()
467 .top_0()
468 .bottom_0()
469 .left(px(hit_x))
470 .w(px(hit_w))
471 .cursor_pointer()
472 .on_mouse_down(
473 MouseButton::Right,
474 cx.listener(move |this, event: &MouseDownEvent, _, cx| {
475 this.open_marker_menu(idx, event.position, cx);
476 cx.stop_propagation();
477 }),
478 )
479 .on_click(cx.listener(move |this, event: &ClickEvent, _, cx| {
480 // A double-click inside the open field is the caret's, not a new rename.
481 let typing = this.marker_edit.as_ref().is_some_and(|e| e.idx == idx && e.field == MarkerField::Name);
482 if event.click_count() >= 2 && !typing {
483 this.rename_marker_at(idx, cx);
484 }
485 }))
486 .child(flag)
487 // The name's field, where the name was: the same field the Markers card's
488 // rename was, its words all selected. A press in it stays in it -- it does not
489 // move the playhead or start a new rename.
490 .when_some(retyped, |d, e| {
491 d.child(
492 div()
493 .absolute()
494 .top_0()
495 .left(px(x - hit_x + w.max(14.) - 2.))
496 .on_mouse_down(MouseButton::Left, crate::interact::swallow)
497 .child(crate::ui::toolbar::seq_name_field(&crate::player::text_field::TextField {
498 text: e.text.clone(),
499 all: e.all,
500 })),
501 )
502 })
503 .into_any_element()
504 })
505 .collect()
506}
507
508/// The In and Out marks as brackets on the ruler: a 2px bar with two short arms, the In
509/// opening to the right and the Out to the left, in the accent.
510fn range_brackets(range: Option<(u32, u32)>, fps: f64, scale: Scale, bed_w: f32) -> Vec<gpui::AnyElement> {
511 let Some((a, b)) = range else {
512 return Vec::new();
513 };
514 let ink = rgb(crate::ui::theme::tokens().accent);
515 let at = |frame: u32| scale.px_at(f64::from(frame) / fps);
516 [(at(a), true), (at(b), false)]
517 .into_iter()
518 .filter(|(x, _)| *x >= 0. && *x <= bed_w)
519 .map(|(x, opens_right)| {
520 let arm = |top: bool| {
521 let d = div().absolute().h(px(2.)).w(px(5.)).bg(ink);
522 let d = if top { d.top_0() } else { d.bottom_0() };
523 if opens_right { d.left_0() } else { d.right_0() }
524 };
525 div()
526 .absolute()
527 .top(px(1.))
528 .bottom(px(1.))
529 .left(px(if opens_right { x - 1. } else { x - 4. }))
530 .w(px(5.))
531 .child(div().absolute().top_0().bottom_0().w(px(2.)).bg(ink).when(opens_right, |d| d.left_0()).when(!opens_right, |d| d.right_0()))
532 .child(arm(true))
533 .child(arm(false))
534 .into_any_element()
535 })
536 .collect()
537}
538
539#[cfg(test)]
540mod tests {
541 use super::*;
542
543 #[test]
544 fn a_marker_is_a_post_and_a_range_runs_its_length() {
545 use engine::project::{Marker, MarkerColor};
546 let m = |frame, length| Marker { frame, length, name: "m".into(), note: String::new(), color: MarkerColor::Red };
547 let scale = Scale { pps: 10., start: 0. };
548 let spans = marker_spans(&[m(25, 0), m(50, 50), m(25 * 100, 0)], 25., scale, 200.);
549 assert_eq!(spans.len(), 2, "a marker past the bed is left out");
550 assert_eq!((spans[0].0, spans[0].1), (10., MARK_POINT_W));
551 assert_eq!((spans[1].0, spans[1].1), (20., 20.));
552 assert!(marker_spans(&[m(25, 0)], 25., Scale { pps: 0., start: 0. }, 200.).is_empty());
553 }
554
555 #[test]
556 fn a_flag_carries_its_name_where_there_is_room_and_cuts_it_otherwise() {
557 use engine::project::{Marker, MarkerColor};
558 let m = |frame, name: &str| Marker { frame, length: 0, name: name.into(), note: String::new(), color: MarkerColor::Red };
559 let scale = Scale { pps: 100., start: 0. };
560 let flags = marker_flags(&[m(25, "Intro"), m(75, "A very long marker name"), m(78, "x")], 25., scale, 400.);
561 assert_eq!(flags[0].name, "Intro");
562 assert!(flags[1].name.is_empty(), "no room before the next flag");
563 assert_eq!(flags.len(), 3);
564 let cut = marker_flags(&[m(25, "A very long marker name here")], 25., Scale { pps: 40., start: 0. }, 100.);
565 assert!(cut[0].name.ends_with('\u{2026}'), "{:?}", cut[0].name);
566 }
567
568 #[test]
569 fn a_short_clip_at_25fps_reads_in_seconds_and_frames_not_timecodes() {
570 // The audit's 2s clip: fitted to a 1200px bed it sits at ~600px/s,
571 // where the finest step is five frames (120px). The `2s` tick at the
572 // bed's very edge has no room for its label and is left out.
573 let scale = Scale { pps: 600., start: 0. };
574 let labels: Vec<_> = ticks(scale, 25., 1200., 0.).into_iter().map(|(_, l)| l).collect();
575 assert_eq!(labels, ["0s", "+5f", "+10f", "+15f", "+20f", "1s", "+5f", "+10f", "+15f", "+20f"]);
576 // At the default 60px/s the same bed reads in whole seconds.
577 let scale = Scale { pps: 60., start: 0. };
578 let labels: Vec<_> = ticks(scale, 25., 1200., 0.).into_iter().map(|(_, l)| l).collect();
579 assert_eq!(labels[..4], ["0s", "2s", "4s", "6s"]);
580 assert!(labels.iter().all(|l| !l.contains(':')), "{labels:?}");
581 // Scrolled past a minute at 4px/s, the labels turn to M:SS.
582 let scale = Scale { pps: 4., start: 50. };
583 let labels: Vec<_> = ticks(scale, 25., 1200., 0.).into_iter().map(|(_, l)| l).collect();
584 assert_eq!(labels[..3], ["1:00", "1:30", "2:00"]);
585 // The scrub plate's band and a zero scale give no ticks there.
586 assert!(ticks(scale, 25., 1200., 2000.).is_empty());
587 assert!(ticks(Scale { pps: 0., start: 0. }, 25., 1200., 0.).is_empty());
588 }
589}
590
591#[cfg(test)]
592mod range_band_tests {
593 use super::*;
594
595 #[test]
596 fn the_in_out_range_is_shaded_between_its_marks_and_clipped_to_the_bed() {
597 let scale = crate::viewport::Scale { pps: 100., start: 0. };
598 assert_eq!(range_band(None, 25., scale, 500.), None);
599 assert_eq!(range_band(Some((25, 75)), 25., scale, 500.), Some((100., 200.)));
600 assert_eq!(range_band(Some((25, 1000)), 25., scale, 500.), Some((100., 400.)));
601 assert_eq!(range_band(Some((2500, 3000)), 25., scale, 500.), None);
602 }
603}