forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

mod.rs735 lines, 30.9 KiBHistoryRawDownload
1//! The bench's own content: lanes, ruler and clips (DESIGN.md §5's clip
2//! anatomy, §7's degradation ladder). `stance.rs::bench()` owns the frame
3//! (height, surfaces, section head); this module owns what fills it, the way
4//! `dock_stance.rs` owns the dock's content next to `stance.rs::dock()`'s
5//! frame.
6//!
7//! Reused rather than reimplemented (`ui/timeline.rs` already shipped this
8//! plumbing on the legacy timeline): `Player::insert_source` and the
9//! `AssetDrag` payload for add-at-playhead and drag-drop from the Sources
10//! tab, `Player::pick`/`Player::marks`/`marked` for selection, and
11//! `Player::nudge_cut`/`walk_cut`/`cut`/`toggle_loop_trim` (DESIGN §6, wired
12//! in `player/actions.rs` already, and answered to by every keystroke the
13//! stance's own key handler forwards) for the whole cut grammar -- none of
14//! that is touched here, because a clip's `start`/`frames()` already reflect
15//! a commit the moment the keymap makes one (`nudge_cut` writes straight to
16//! the session), so this module reads the session straight, needing no live
17//! drag-preview state to mirror it. New here: the clip anatomy (ink spine,
18//! trace, name plate, splice gaps) and the width ladder that degrades it
19//! (DESIGN §7) -- neither existed on the legacy timeline in this shape.
20//!
21//! Now also reused: `ClipDrag` (moving a placed clip along its lane and onto
22//! another, `Player::dragged`/`Player::move_clip`), the mouse edge-trim
23//! strips (`Player::start_trim`/`trims(span)`, the same minimum-width rule
24//! the legacy strips use), `Player::timeline_wheel` (ctrl+wheel zooms about
25//! the pointer, a bare wheel scrolls the bed -- the same mapping on the
26//! ruler and on every bed) and `LaneDrag`/`Player::reorder_lane` (drag a
27//! track head onto another to swap their order). `Player::drag_move`/
28//! `Player::drag_release`, wired once on the window's own root
29//! (`render.rs`), already carry a trim or a scroll off the 6px strip that
30//! started it, for the darkroom tree exactly as for the legacy one -- no
31//! root wiring lives here.
32//!
33//! Fade wedges, dissolve joins, and the lane header's drop-line cue reuse the
34//! legacy interaction state: `FadeDrag` previews the ramp until release,
35//! `dissolve_selected` still owns the toggle, and `LaneDrop` answers the same
36//! slot that `reorder_lane` commits.
37//!
38//! `nudge_cut` and friends still act on `Player::selected` directly, with no
39//! element under the pointer required, and stay untouched by any of this.
40
41pub(crate) mod clip;
42pub(crate) mod clip_envelope;
43pub(crate) mod lane;
44mod ruler;
45mod sub;
46mod titles_row;
47pub(crate) mod overview;
48
49use crate::ui::hitmap;
50use crate::ui::type_scale::{self, Typeset};
51use crate::ui::widgets::*;
52use crate::*;
53
54use lane::lane_row;
55use ruler::ruler;
56
57/// The pinned ruler's own height, above the lane stack -- tall enough for a
58/// tick line plus a mono label under it, and the playhead's lamp tab along
59/// its top edge (DESIGN §6.5).
60pub(crate) const RULER_H: f32 = crate::layout::redesign::RULER_H;
61/// A mono character's width at `size_px`, from the shared
62/// [`crate::layout::LIST_CHAR_W`] calibration (taken at
63/// [`type_scale::CHORD_METADATA_MIN_PX`]).
64pub(crate) fn char_w(size_px: f32) -> f32 {
65 crate::layout::LIST_CHAR_W / type_scale::CHORD_METADATA_MIN_PX * size_px
66}
67
68/// The pinned track-head column: the source dot and the lane's name, and
69/// nothing else since the head's verbs moved into its own menu (cleanse
70/// round 2) -- the pixels it gave up are the bed's now.
71pub(crate) const HEAD_W: f32 = 156.;
72pub(crate) const ROW_GAP: f32 = 2.;
73/// The height a lane is drawn at when nobody has dragged it (DESIGN §5 "Lane
74/// heights", REDESIGN §3.6): by kind. An empty lane keeps its kind's height, so
75/// dropping the first clip on it moves nothing.
76const LANE_VIDEO_H: f32 = crate::layout::redesign::LANE_H_V;
77const LANE_AUDIO_H: f32 = crate::layout::redesign::LANE_H_A;
78const LANE_SUB_H: f32 = 28.;
79/// The range a dragged lane may be held to. Past the top the lane stops
80/// growing and the column scrolls instead.
81pub(crate) const LANE_MAX_H: f32 = 120.;
82/// The gap `lane_row`'s pinned head column puts between the lane label and
83/// its status dot (its own `.gap(px(...))`), named so [`LANE_MIN_H`]'s
84/// derivation below doesn't repeat the literal blind.
85pub(crate) const LANE_HEAD_GAP: f32 = 2.;
86/// The status dot's own diameter (`lane_row`'s "Pinned track head" child,
87/// its own `.w(px(...)).h(px(...))`).
88pub(crate) const LANE_DOT_D: f32 = 4.;
89/// The source patch box's side (its slot at the head's left edge is always this wide, shown or not).
90pub(crate) const PATCH_W: f32 = 16.;
91/// The widest a lane's label may be inside the head (a long track name is ellipsised to it;
92/// the head itself stays [`HEAD_W`]): the head less the patch slot, the dot, the two switches and
93/// their gaps.
94pub(crate) const LANE_NAME_MAX_W: f32 = 68.;
95/// The least a lane row may be (DESIGN §5). The head is one row -- dot, name,
96/// switches -- so its tallest piece is the 24px switch hit area ([`HIT_MIN`]),
97/// not a stack of label, gap and dot; `a_lane_row_fits_what_its_own_head_draws`
98/// checks that this still holds. 28 leaves the switches a little air.
99pub(crate) const LANE_MIN_H: f32 = 28.;
100
101/// Holds a lane's height to what the bench may draw: [`LANE_MIN_H`] to
102/// [`LANE_MAX_H`].
103pub(crate) fn clamp_lane_h(h: f32) -> f32 {
104 h.clamp(LANE_MIN_H, LANE_MAX_H)
105}
106
107/// A lane's key in the view file (`view_state`): its kind's letter and its
108/// ord plus one, the same number its head names it by -- "v1", "a2", "s1".
109pub(crate) fn lane_key(lane: Lane) -> String {
110 let kind = match lane.kind {
111 LaneKind::Video => 'v',
112 LaneKind::Audio => 'a',
113 LaneKind::Subtitle => 's',
114 };
115 format!("{kind}{}", lane.ord + 1)
116}
117
118/// The height a lane has when nobody has dragged it: its kind's own, whether
119/// or not it holds anything (no auto-collapse; the layout is stable); on a window
120/// shorter than 800 px the short pair (REDESIGN §2.2).
121pub(crate) fn default_lane_h(kind: LaneKind) -> f32 {
122 let short = SHORT_WINDOW.with(Cell::get);
123 match (kind, short) {
124 (LaneKind::Video, false) => LANE_VIDEO_H,
125 (LaneKind::Video, true) => crate::layout::redesign::LANE_H_V_SHORT,
126 (LaneKind::Audio, false) => LANE_AUDIO_H,
127 (LaneKind::Audio, true) => crate::layout::redesign::LANE_H_A_SHORT,
128 (LaneKind::Subtitle, _) => LANE_SUB_H,
129 }
130}
131
132thread_local! {
133 /// Whether the window is shorter than 800 px (REDESIGN §2.2): lanes are drawn
134 /// V 44 / A 32 so four of them still fit. Set by `stance::bench` each frame.
135 static SHORT_WINDOW: Cell<bool> = const { Cell::new(false) };
136}
137
138/// Tells the bench the window height, so the default lane heights can follow it.
139pub(crate) fn set_window_h(height: f32) {
140 SHORT_WINDOW.with(|c| c.set(height < 800.));
141}
142
143/// The height `lane` is drawn at: the one a hand dragged it to and saved for
144/// this project, else [`default_lane_h`]. A saved value that is not a number
145/// is ignored, and the result is always held to the lane range.
146pub(crate) fn lane_height(player: &Player, lane: Lane) -> f32 {
147 let key = lane_key(lane);
148 let saved = player
149 .lane_h
150 .iter()
151 .find(|(k, h)| *k == key && h.is_finite())
152 .map(|(_, h)| *h);
153 let h = saved.unwrap_or_else(|| default_lane_h(lane.kind));
154 clamp_lane_h(h)
155}
156
157/// Saves the height a lane was dragged to, replacing its earlier one.
158pub(crate) fn save_lane_h(saved: &mut Vec<(String, f32)>, lane: Lane, h: f32) {
159 let key = lane_key(lane);
160 match saved.iter_mut().find(|(k, _)| *k == key) {
161 Some(entry) => entry.1 = h,
162 None => saved.push((key, h)),
163 }
164}
165
166/// Forgets a lane's saved height, so it draws at its kind's default again.
167pub(crate) fn forget_lane_h(saved: &mut Vec<(String, f32)>, lane: Lane) {
168 let key = lane_key(lane);
169 saved.retain(|(k, _)| *k != key);
170}
171
172/// The three track heights a lane can be set to, from its header's menu, the
173/// Timeline menu or the keyboard (Premiere's and Resolution's "track height").
174/// Small is the floor a lane may be held to, Medium is the kind's own default
175/// and Large is the taller one that shows its thumbnails and waveform in full.
176#[derive(Clone, Copy, PartialEq, Eq, Debug)]
177pub(crate) enum TrackSize {
178 Small,
179 Medium,
180 Large,
181}
182
183impl TrackSize {
184 pub(crate) const ALL: [TrackSize; 3] = [TrackSize::Small, TrackSize::Medium, TrackSize::Large];
185
186 /// One size taller (`up`) or shorter, held at the ends.
187 pub(crate) fn step(self, up: bool) -> Self {
188 match (self, up) {
189 (TrackSize::Small, true) | (TrackSize::Large, false) => TrackSize::Medium,
190 (TrackSize::Medium, true) | (TrackSize::Large, true) => TrackSize::Large,
191 (TrackSize::Medium, false) | (TrackSize::Small, false) => TrackSize::Small,
192 }
193 }
194
195 pub(crate) fn word(self) -> &'static str {
196 match self {
197 TrackSize::Small => "Small",
198 TrackSize::Medium => "Medium",
199 TrackSize::Large => "Large",
200 }
201 }
202
203 /// The size a track-height row sets, if `action` is one of those rows.
204 pub(crate) fn of_action(action: crate::keymap::ActionId) -> Option<Self> {
205 use crate::keymap::ActionId;
206 match action {
207 ActionId::TrackSmall => Some(TrackSize::Small),
208 ActionId::TrackMedium => Some(TrackSize::Medium),
209 ActionId::TrackLarge => Some(TrackSize::Large),
210 _ => None,
211 }
212 }
213}
214
215/// Large lanes: a video lane's thumbnails and an audio lane's waveform get
216/// the room they need; the subtitle lane's text simply gets more air.
217const LANE_LARGE_VIDEO_H: f32 = 96.;
218const LANE_LARGE_AUDIO_H: f32 = 72.;
219const LANE_LARGE_SUB_H: f32 = 40.;
220
221/// The height a lane of `kind` has at `size`. Medium follows the window
222/// (`default_lane_h`), so it stays the height the lane is drawn at unless
223/// somebody has set it.
224pub(crate) fn size_h(kind: LaneKind, size: TrackSize) -> f32 {
225 match (size, kind) {
226 (TrackSize::Small, _) => LANE_MIN_H,
227 (TrackSize::Medium, _) => default_lane_h(kind),
228 (TrackSize::Large, LaneKind::Video) => LANE_LARGE_VIDEO_H,
229 (TrackSize::Large, LaneKind::Audio) => LANE_LARGE_AUDIO_H,
230 (TrackSize::Large, LaneKind::Subtitle) => LANE_LARGE_SUB_H,
231 }
232}
233
234/// The size a lane is drawn at: the preset nearest its height. A tie (a
235/// subtitle lane's Small and Medium are one height) is Medium, the default.
236pub(crate) fn track_size(player: &Player, lane: Lane) -> TrackSize {
237 let h = lane_height(player, lane);
238 [TrackSize::Medium, TrackSize::Small, TrackSize::Large]
239 .into_iter()
240 .min_by(|a, b| (size_h(lane.kind, *a) - h).abs().total_cmp(&(size_h(lane.kind, *b) - h).abs()))
241 .unwrap_or(TrackSize::Medium)
242}
243
244/// Sets a lane to a size. Medium forgets the saved height, so the lane keeps
245/// following the window the way it does before anyone touches it.
246pub(crate) fn set_track_size(saved: &mut Vec<(String, f32)>, lane: Lane, size: TrackSize) {
247 match size {
248 TrackSize::Medium => forget_lane_h(saved, lane),
249 _ => save_lane_h(saved, lane, size_h(lane.kind, size)),
250 }
251}
252
253/// How close a dragged lane has to come to a size's height to land on it.
254pub(crate) const LANE_SNAP_PX: f32 = 4.;
255
256/// A dragged height, held to the size it sits next to when it is within
257/// [`LANE_SNAP_PX`] of one; otherwise the height as dragged.
258pub(crate) fn snap_lane_h(kind: LaneKind, h: f32) -> f32 {
259 TrackSize::ALL
260 .into_iter()
261 .map(|size| size_h(kind, size))
262 .find(|p| (p - h).abs() <= LANE_SNAP_PX)
263 .unwrap_or(h)
264}
265
266/// The order the bench draws its lanes top to bottom, the way every NLE stacks them: video
267/// lanes climb upward, the highest (`V3`) on top and `V1` just above the audio, and audio
268/// lanes descend below. Only the drawing changes; the engine's own lane order and every
269/// lane's address stay as they are. Anything else (captions) keeps its engine place,
270/// after the audio it sat with.
271pub(crate) fn display_order(lanes: &[Lane]) -> Vec<Lane> {
272 let mut video: Vec<Lane> = lanes.iter().copied().filter(|l| l.kind == LaneKind::Video).collect();
273 video.sort_by_key(|l| std::cmp::Reverse(l.ord));
274 let rest = lanes.iter().copied().filter(|l| l.kind != LaneKind::Video);
275 video.into_iter().chain(rest).collect()
276}
277
278/// Where each lane's band lies in a column of lanes drawn one under another
279/// with [`ROW_GAP`] between them, top first: `(lane, top, bottom)`. Each
280/// lane takes its own height, so the bands of a mixed stack are not evenly
281/// spaced.
282#[cfg(test)]
283pub(crate) fn lane_bands(stack: &[(Lane, f32)]) -> Vec<(Lane, f32, f32)> {
284 let mut top = 0.;
285 stack
286 .iter()
287 .map(|&(lane, h)| {
288 let band = (lane, top, top + h);
289 top += h + ROW_GAP;
290 band
291 })
292 .collect()
293}
294
295/// The lane whose band holds `y`, if any; a y in the gap between two lanes
296/// holds neither.
297#[cfg(test)]
298pub(crate) fn lane_at_y(bands: &[(Lane, f32, f32)], y: f32) -> Option<Lane> {
299 bands
300 .iter()
301 .find(|(_, top, bottom)| y >= *top && y < *bottom)
302 .map(|(lane, _, _)| *lane)
303}
304
305/// One clip's degradation tier (DESIGN §7), picked off the clip's own worth
306/// in pixels (`span`, unclamped) rather than its drawn floor
307/// ([`clip_width`]'s `HIT_MIN`) -- a clip zoomed far out is worth a fraction
308/// of a pixel long before its box stops shrinking, and the ladder has to see
309/// that or "sliver" would never fire under the floor that keeps it clickable.
310#[derive(Clone, Copy, PartialEq)]
311enum Tier {
312 /// Trace + name plate + speed chip.
313 Full,
314 /// Trace + name plate.
315 NoChip,
316 /// Trace only -- REDESIGN §3.6's "<40px" boundary for the name.
317 NoLabel,
318 /// Solid ink fill + splice gaps: film scale, below the trace's floor.
319 Sliver,
320}
321
322/// The narrowest a clip's spine is drawn at all (DESIGN §7): under this the
323/// spine would be wider than the box it sits in.
324const SPINE_MIN_W: f32 = 3.;
325
326/// `MM:SS` for a clip's own readout -- the bench talks in the film's units,
327/// not in seconds with a decimal point.
328pub(crate) fn mmss(secs: f64) -> String {
329 let s = secs.max(0.).round() as u64;
330 match s >= 3600 {
331 true => format!("{}:{:02}:{:02}", s / 3600, s / 60 % 60, s % 60),
332 false => format!("{}:{:02}", s / 60, s % 60),
333 }
334}
335
336/// A clip's thumbnail, filling its box. `Cover` rather than `Contain`: a clip
337/// is a strip of film, so it crops rather than letterboxing inside a lane.
338pub(crate) fn cover_image(image: std::sync::Arc<gpui::RenderImage>) -> impl IntoElement {
339 canvas(
340 |_, _, _| (),
341 move |bounds, _, window, _| {
342 let fitted = gpui::ObjectFit::Cover.get_bounds(bounds, image.size(0));
343 let _ = window.paint_image(fitted, Corners::default(), image, 0, false);
344 },
345 )
346 .size_full()
347}
348
349/// A clip's thumbnail as a film strip: the picture at the strip's height, whole and uncropped,
350/// repeated along the clip from its left edge -- one frame stretched over a long clip was cut
351/// through its middle (and its text) as the clip grew. Only the tiles in view are painted.
352pub(crate) fn film_image(image: std::sync::Arc<gpui::RenderImage>) -> impl IntoElement {
353 canvas(
354 |_, _, _| (),
355 move |bounds, _, window, _| {
356 let size = image.size(0);
357 let (iw, ih) = (size.width.0 as f32, size.height.0 as f32);
358 let h = f32::from(bounds.size.height);
359 if iw <= 0. || ih <= 0. || h <= 0. {
360 return;
361 }
362 let tile_w = (h * iw / ih).max(1.);
363 let view = window.content_mask().bounds;
364 let (left, right) = (f32::from(bounds.origin.x), f32::from(bounds.size.width));
365 let first = ((f32::from(view.left()) - left) / tile_w).floor().max(0.);
366 let mut x = first * tile_w;
367 while x < right && left + x < f32::from(view.right()) {
368 let tile = Bounds { origin: point(bounds.origin.x + px(x), bounds.origin.y), size: gpui::size(px(tile_w), px(h)) };
369 let _ = window.paint_image(tile, Corners::default(), image.clone(), 0, false);
370 x += tile_w;
371 }
372 },
373 )
374 .size_full()
375}
376
377/// The width ladder (REDESIGN §3.6): the name strip from 40 px, the trace from 24
378/// px, and the solid fill below that.
379fn tier(span: f32) -> Tier {
380 match span {
381 s if s >= 120. => Tier::Full,
382 s if s >= 40. => Tier::NoChip,
383 s if s >= 24. => Tier::NoLabel,
384 _ => Tier::Sliver,
385 }
386}
387
388/// The bench's side gutter, spent inside [`render`]'s own content box.
389const BENCH_GUTTER: f32 = 12.;
390
391/// The bench's content: pinned ruler, pinned heads, lane stack. Each lane is
392/// drawn at its own height ([`lane_height`]); the lane column takes what the
393/// box leaves and scrolls behind the pinned ruler and heads when the lanes
394/// add up to more (DESIGN §7). The box no longer sizes the rows, so it is not
395/// read here.
396pub(crate) fn render(player: &mut Player, cx: &mut Context<Player>) -> impl IntoElement {
397 let lanes = display_order(
398 &player
399 .session
400 .as_ref()
401 .map_or_else(|| vec![Lane::V1, Lane::A1], PlaybackSession::lanes),
402 );
403 let position = player.session.as_ref().map_or(0., PlaybackSession::now);
404 let scale = player.scale;
405 let (picks, pick_links) = player.marks();
406 // The scrollbar row is spent only while the film is longer than the
407 // window (DESIGN §7), the same test `scrollbar` is mounted on below.
408 let scroll = {
409 let view = player.view();
410 view.duration > view.span()
411 };
412 let empty = player.session.as_ref().is_some_and(PlaybackSession::is_empty) && player.drag_lane.is_none();
413 let rows_h: f32 = lanes.first().map_or(0., |&l| lane_height(player, l));
414 let mut rows = Vec::new();
415 rows.extend(titles_row::titles_row(player, scale, cx).map(IntoElement::into_any_element));
416 for &lane in &lanes {
417 let h = lane_height(player, lane);
418 rows.push(lane_row(player, lane, h, scale, &picks, &pick_links, cx).into_any_element());
419 }
420 div()
421 .id("bench-content")
422 .relative()
423 .flex_1()
424 .min_w(px(0.))
425 .h_full()
426 .flex()
427 .flex_col()
428 .gap(px(ROW_GAP))
429 // The wheel over the WHOLE bench region, not just a bed: the ruler,
430 // the strip left of it, the gaps between rows and the space below the
431 // last track all answer a notch here with the same mapping every row
432 // gives (`Player::timeline_wheel`; the ruler's own former listener
433 // folded into this one, so no strip answers a notch twice). A row
434 // stops propagation, so a notch over a track never reaches this.
435 .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| {
436 this.timeline_wheel(event, cx);
437 }))
438 // The bench's side gutter, spent here rather than by the `bench` div
439 // above, so this element's bounds -- and the catch-all release below
440 // with them -- reach the window edge (note at `ui::stance::bench`).
441 .px(px(BENCH_GUTTER))
442 // The catch-all release: a clip let go of anywhere on the bench that is
443 // not a lane row -- left of the tracks, in the gap between two rows, on
444 // the empty bench below the last one -- lands on the lane and the x the
445 // last live sample of that same drag was over (`Player::drag_lane`,
446 // `Player::drag_x`), which is exactly what the shadow was drawn at. A
447 // release that reaches no drop target at all is the one thing a drag
448 // may never do: a hand that has aimed a clip and let go has made an
449 // edit, and "nothing happened" is not one of the answers an editor
450 // accepts. A row's own listener stops propagation when it answers, so
451 // this only ever runs when none did -- and it would answer with the
452 // same frame if it did run, since both read the one sample.
453 .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| {
454 if this.pro_drag.is_some() {
455 this.commit_pro(cx);
456 return;
457 }
458 let (Some(lane), Some(idx)) = (this.drag_lane, this.dragged(drag)) else {
459 return;
460 };
461 let x = this
462 .drag_x
463 .take()
464 .unwrap_or_else(|| window.mouse_position().x);
465 this.drag_alt = window.modifiers().alt;
466 this.move_clip(drag.lane, idx, lane, x, cx);
467 }))
468 // The same catch-all for the other three things a hand can be holding
469 // over the bench -- a library row, a caption already down, a palette
470 // row. Each lands on the lane its last live sample was over, through
471 // the very door that row's own release uses, so the engine words the
472 // refusal when that lane cannot hold it. Without these, letting one go
473 // off the rows reached nothing at all.
474 // The library drag's own move sample over the bench: below the last lane's bed is the
475 // empty stack, where a drop makes a track. Rows answer the same move for their own
476 // room, and the two never both claim a pointer, since they split it by y.
477 .on_drag_move(cx.listener(move |this, event: &DragMoveEvent<AssetDrag>, _, cx| {
478 if !event.bounds.contains(&event.event.position) {
479 return;
480 }
481 let y = f32::from(event.event.position.y);
482 let bottom = this
483 .lane_beds
484 .borrow()
485 .iter()
486 .map(|(_, bed)| f32::from(bed.bottom()))
487 .fold(f32::NEG_INFINITY, f32::max);
488 let below = y > bottom;
489 let ctrl = event.event.modifiers.control;
490 if below != this.drag_below || ctrl != this.drag_ctrl {
491 this.drag_below = below;
492 this.drag_ctrl = ctrl;
493 cx.notify();
494 }
495 }))
496 .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| {
497 this.end_drag_preview(cx);
498 let x = this
499 .drag_x
500 .take()
501 .unwrap_or_else(|| window.mouse_position().x);
502 this.drag_alt = window.modifiers().alt;
503 let at = this.place_frame(x).0;
504 let insert = window.modifiers().control;
505 // Let go below the last lane there is no row to aim at: the drop makes the tracks
506 // the file needs at the foot of the stack, in the same step as the placement.
507 match this.drag_lane {
508 Some(lane) => this.drop_source(&drag.0.clone(), drag.1, Some(lane), Some(at), insert, cx),
509 None => this.drop_source_below_lanes(&drag.0.clone(), drag.1, Some(at), insert, cx),
510 }
511 }))
512 .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| {
513 let Some(lane) = this.drag_lane else {
514 return;
515 };
516 let x = this
517 .drag_x
518 .take()
519 .unwrap_or_else(|| window.mouse_position().x);
520 this.drag_alt = window.modifiers().alt;
521 this.move_sub(drag, lane, x, cx);
522 }))
523 .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| {
524 let Some(lane) = this.drag_lane else {
525 return;
526 };
527 let x = this
528 .drag_x
529 .take()
530 .unwrap_or_else(|| window.mouse_position().x);
531 this.drag_alt = window.modifiers().alt;
532 this.place_sub(drag.0, lane, x, cx);
533 }))
534 .child(overview::overview(player, cx))
535 .child(ruler(player, position, cx))
536 .child(
537 // The lanes and, over their foot while more lies below, the shared fade -- a lane
538 // cut mid-row reads as the end of the list otherwise.
539 div()
540 .relative()
541 .flex_1()
542 .min_h(px(0.))
543 .flex()
544 .flex_col()
545 .child(
546 div()
547 .id("bench-lanes")
548 // Empty room below the last lane is still the bench: the same
549 // menu the ruler opens, and the same guard the bed carries --
550 // a menu standing here belongs to the press that opened it.
551 .on_mouse_down(
552 MouseButton::Right,
553 cx.listener(|this, event: &MouseDownEvent, _, cx| {
554 if this.context_menu.is_some() {
555 return;
556 }
557 this.open_bench_menu(event.position, cx);
558 }),
559 )
560 .flex_1()
561 .min_h(px(0.))
562 .overflow_y_scroll()
563 .track_scroll(&player.lanes_scroll)
564 .flex()
565 .flex_col()
566 .gap(px(ROW_GAP))
567 .children(rows),
568 )
569 .child(lanes_fade(player.lanes_scroll.clone())),
570 )
571 .children(scroll.then(|| overview::scrollbar(player, cx)))
572 // The empty timeline says what to do, over the bed of its lanes (no hitbox: a drop
573 // still lands on the lane under it).
574 .when(empty, |d| {
575 d.child(
576 div()
577 .absolute()
578 .top(px(overview::OVERVIEW_H + ROW_GAP + RULER_H + ROW_GAP))
579 .left(px(BENCH_GUTTER + HEAD_W))
580 .right(px(BENCH_GUTTER))
581 .h(px(rows_h))
582 .flex()
583 .items_center()
584 .justify_center()
585 .type_style(type_scale::body())
586 .text_color(rgb(INK3()))
587 .child("Drag media here to start"),
588 )
589 })
590 .child(playhead_line(player, position, scale))
591}
592
593/// A short, gentle fade over the foot of the lane stack while lanes are hidden below it. Only
594/// 18px and never past 60% of the bed's own ground, so the last partly visible lane stays
595/// readable. Painted, so it reads the scroll extent of the frame it is drawn in.
596fn lanes_fade(scroll: ScrollHandle) -> impl IntoElement {
597 canvas(
598 |_, _, _| (),
599 move |bounds, _, window, _| {
600 let hidden = f32::from(scroll.max_offset().height) + f32::from(scroll.offset().y);
601 if hidden < 2. {
602 return;
603 }
604 let ground = rgb(crate::ui::theme::tokens().well);
605 let clear = gpui::Rgba { a: 0., ..ground };
606 let soft = gpui::Rgba { a: 0.6, ..ground };
607 window.paint_quad(gpui::fill(
608 bounds,
609 gpui::linear_gradient(180., gpui::linear_color_stop(clear, 0.), gpui::linear_color_stop(soft, 1.)),
610 ));
611 },
612 )
613 .absolute()
614 .left_0()
615 .right_0()
616 .bottom_0()
617 .h(px(18.))
618}
619
620/// The playhead's line carried down through the lanes, over the clips: 2px
621/// (3 while playing), lamp colour, a 1px black halo each side. The ruler draws
622/// its own part and the pentagon head.
623fn playhead_line(player: &Player, position: f64, scale: Scale) -> impl IntoElement + use<> {
624 let bed_w = f32::from(player.ruler.get().size.width).max(1.);
625 let x = scale.px_at(position).clamp(0., bed_w);
626 let w = if player.transport().is_playing() { 3. } else { 2. };
627 div()
628 .absolute()
629 .top(px(overview::OVERVIEW_H + ROW_GAP + RULER_H + ROW_GAP))
630 .bottom_0()
631 .left(px(BENCH_GUTTER + HEAD_W + x - 1.))
632 .w(px(w + 2.))
633 .bg(rgba(crate::ui::theme::with_alpha(0x000000, 0xb3)))
634 .child(
635 div()
636 .absolute()
637 .top_0()
638 .bottom_0()
639 .left(px(1.))
640 .w(px(w))
641 .bg(rgb(LAMP_WHITE())),
642 )
643}
644
645#[cfg(test)]
646mod tests {
647 use super::{
648 LANE_AUDIO_H, LANE_MAX_H, LANE_MIN_H, LANE_SUB_H, LANE_VIDEO_H, Tier,
649 clamp_lane_h, default_lane_h, forget_lane_h, lane_key, save_lane_h, tier,
650 };
651 use crate::*;
652
653 #[test]
654 fn a_clips_duration_reads_m_ss_and_h_mm_ss_over_an_hour() {
655 assert_eq!(super::mmss(14.), "0:14");
656 assert_eq!(super::mmss(60.), "1:00");
657 assert_eq!(super::mmss(3725.), "1:02:05");
658 }
659
660 #[test]
661 fn a_label_is_whole_cut_with_an_ellipsis_or_left_to_nothing() {
662 let at = |ch: char| if ch.is_whitespace() { 3. } else { 6.8 };
663 assert_eq!(super::clip::fit_with("grad", 200., at).as_deref(), Some("grad"));
664 assert_eq!(super::clip::fit_with("summer_reel_final", 68., at).as_deref(), Some("summer_re…"));
665 // One letter and the ellipsis still fit; not even that does, nothing shows.
666 assert_eq!(super::clip::fit_with("summer", 20., at).as_deref(), Some("s…"));
667 assert_eq!(super::clip::fit_with("summer", 13., at), None);
668 }
669
670 #[test]
671 fn the_width_ladder_steps_at_its_thresholds() {
672 assert!(tier(120.) == Tier::Full && tier(119.9) == Tier::NoChip);
673 assert!(tier(40.) == Tier::NoChip && tier(39.9) == Tier::NoLabel);
674 assert!(tier(24.) == Tier::NoLabel && tier(23.9) == Tier::Sliver);
675 assert!(tier(0.) == Tier::Sliver);
676 }
677
678 #[test]
679 fn a_lane_without_a_drag_is_drawn_at_its_kinds_height() {
680 assert_eq!(default_lane_h(LaneKind::Video), LANE_VIDEO_H);
681 assert_eq!(default_lane_h(LaneKind::Audio), LANE_AUDIO_H);
682 assert_eq!(default_lane_h(LaneKind::Subtitle), LANE_SUB_H);
683 assert_eq!((LANE_VIDEO_H, LANE_AUDIO_H, LANE_SUB_H), (52., 40., 28.));
684 }
685
686 #[test]
687 fn a_dragged_lane_is_held_between_the_floor_and_the_ceiling() {
688 assert_eq!(clamp_lane_h(5.), LANE_MIN_H);
689 assert_eq!(clamp_lane_h(500.), LANE_MAX_H);
690 assert_eq!(clamp_lane_h(70.), 70.);
691 assert_eq!((LANE_MIN_H, LANE_MAX_H), (28., 120.));
692 }
693
694 #[test]
695 fn a_reset_forgets_the_saved_height_and_a_drag_replaces_it() {
696 let mut saved = Vec::new();
697 save_lane_h(&mut saved, Lane::A1, 90.);
698 save_lane_h(&mut saved, Lane::A1, 70.);
699 assert_eq!(
700 saved,
701 vec![("a1".to_string(), 70.)],
702 "a key is replaced, not repeated"
703 );
704 save_lane_h(&mut saved, Lane::V1, 100.);
705 forget_lane_h(&mut saved, Lane::A1);
706 assert_eq!(saved, vec![("v1".to_string(), 100.)]);
707 forget_lane_h(&mut saved, Lane::S1);
708 assert_eq!(saved.len(), 1, "a lane never saved forgets nothing");
709 }
710
711 #[test]
712 fn a_lane_is_keyed_by_its_kind_letter_and_its_ord_plus_one() {
713 assert_eq!(lane_key(Lane::V1), "v1");
714 assert_eq!(lane_key(Lane::A1), "a1");
715 assert_eq!(lane_key(Lane::S1), "s1");
716 assert_eq!(lane_key(Lane::new(LaneKind::Audio, 1)), "a2");
717 }
718}
719
720#[cfg(test)]
721mod display_order_tests {
722 use super::*;
723
724 #[test]
725 fn video_lanes_climb_above_v1_and_audio_descends_below() {
726 let v = |ord| Lane::new(LaneKind::Video, ord);
727 let a = |ord| Lane::new(LaneKind::Audio, ord);
728 let engine = [v(0), v(1), v(2), a(0), a(1)];
729 assert_eq!(
730 display_order(&engine),
731 vec![v(2), v(1), v(0), a(0), a(1)],
732 "V3 on top, then V2, V1, then the audio stack"
733 );
734 }
735}