forge
Explore
Log in

Don't you dare go Hollow

A drag shows where it lands, as a shadow

Browse files at this commit

f75307daf61eb97653857c5202f5d30bfc47dcc6Ahmet Kaan GümüşParent: 1c58757
  • feat
    • a drag shows where it lands, as a shadow
Show full message
✨ feat(timeline): a drag shows where it lands, as a shadow

Every drag over the bed now draws a translucent box at the frame it will
commit to, on the lane the pointer is over: the clip's own width at this
zoom for a take being moved, the file's own length for a library row, and
the refusal red where the lane cannot take the drop at all. The snap line
still marks the frame; the shadow shows the body that will fill it.

One answer behind both halves of the gesture: `landing` takes the grab
offset off the frame under the pointer and snaps it, and the ghost, the
line and the drop all ask it -- so what the eye is promised is where the
release puts it. `lane_refuses` is the same rule for a library row's two
impossible lanes, asked by the tint in flight and by the insert that
commits.

Which lane the pointer is over is read off each lane's own drag-move box
(gpui hands every painted element its own bounds): the root clears the
shadow, the lane the pointer is inside draws it, in that order.
crates/app/src/main.rsmodified+328 -40
@@ -40,6 +40,18 @@ const SELECTED: u32 = 0x2a4a6b;
40 /// the lane stays in the dark family the rest of the chrome lives in40 /// the lane stays in the dark family the rest of the chrome lives in
41 /// (ledger:187), and the first source keeps `SURFACE` exactly.41 /// (ledger:187), and the first source keeps `SURFACE` exactly.
42 const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b];42 const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b];
43+/// The mirror of `SELECTED`: a drop the lane will not take, tinting the shadow
44+/// a drag draws ([`Ghost`]) so a refusal is seen before the release rather than
45+/// read afterwards. Same brightness as the rest of the chrome -- a warning, not
46+/// an alarm.
47+const REFUSE: u32 = 0x6b2a2a;
48+/// How solid that shadow is (`0xRRGGBBAA`): enough to read as a box, little
49+/// enough that the clip it is drawn over is still legible through it.
50+const GHOST_ALPHA: u32 = 0x66;
51+/// ...and the narrowest it is drawn: a library row whose length the engine has
52+/// not measured yet has a landing place but no width, and a head marker says
53+/// where it goes where a zero-width box would say nothing.
54+const GHOST_MIN: f32 = 2.;
43 /// One step lighter than whatever it sits on: the pointer's answer that this is55 /// One step lighter than whatever it sits on: the pointer's answer that this is
44 /// clickable. Two of them, because buttons stand on `SURFACE` and the scrub56 /// clickable. Two of them, because buttons stand on `SURFACE` and the scrub
45 /// strip stands on `CHROME`.57 /// strip stands on `CHROME`.
@@ -297,6 +309,29 @@ struct ClipDrag {
297 clip: Clip,309 clip: Clip,
298 }310 }
299 311
312+/// Where the drag in flight would leave what it is carrying: the lane the
313+/// pointer is over, the snapped head the release will commit ([`landing`]), and
314+/// how long the thing is. Drawn on that lane as a translucent box the size of
315+/// the take, so a landing is *seen* before the release rather than discovered
316+/// after it -- the line ([`Player::snap_cue`]) marks the frame, this shows the
317+/// body. `refused` is a drop the lane cannot take -- a picture over an audio
318+/// track, a sound over a video one -- tinted rather than silent, because the
319+/// refusal is coming at the release either way ([`lane_refuses`],
320+/// [`Project::move_clip`]).
321+#[derive(Clone, Copy, PartialEq)]
322+struct Ghost {
323+ lane: Lane,
324+ start: u32,
325+ /// Timeline frames, which a speed has already been counted into: the box is
326+ /// as wide as the clip is *long where it lands*. Zero for a library row of
327+ /// unknown length, drawn as a head marker.
328+ frames: u32,
329+ /// The swatch of the file being carried ([`Player::file_tint`]), so the
330+ /// ghost reads as the thing in the hand.
331+ tint: u32,
332+ refused: bool,
333+}
334+
300 /// A clip edge being dragged: which end of which clip, and the timeline frame335 /// A clip edge being dragged: which end of which clip, and the timeline frame
301 /// the pointer has pulled it to. The box on screen is drawn from `to` while this336 /// the pointer has pulled it to. The box on screen is drawn from `to` while this
302 /// is set and the engine hears about it once, at the release337 /// is set and the engine hears about it once, at the release
@@ -849,6 +884,12 @@ struct Player {
849 /// happens rather than discovered after the release. Stale between gestures,884 /// happens rather than discovered after the release. Stale between gestures,
850 /// which costs nothing -- it is drawn only while one is live.885 /// which costs nothing -- it is drawn only while one is live.
851 snap_cue: Option<u32>,886 snap_cue: Option<u32>,
887+ /// The box the same gesture is about to fill, or `None` while the pointer is
888+ /// over no lane: the shadow every proper editor draws under a drag. Set by
889+ /// the lane the pointer is actually over -- that is the one question the
890+ /// line above does not answer -- and drawn only while a drag is live, for
891+ /// [`Player::snap_cue`]'s reason.
892+ ghost: Option<Ghost>,
852 last_scrub: Instant,893 last_scrub: Instant,
853 last_target: u32,894 last_target: u32,
854 /// The running export. While it owns the UI the editor is read-only.895 /// The running export. While it owns the UI the editor is read-only.
@@ -1139,6 +1180,10 @@ impl Player {
1139 // index would trim a clip nobody grabbed. Dropping it is the whole fix:1180 // index would trim a clip nobody grabbed. Dropping it is the whole fix:
1140 // nothing has been written yet.1181 // nothing has been written yet.
1141 self.trim = None;1182 self.trim = None;
1183+ // ...and the shadow a drag is drawn under promises a landing on a lane
1184+ // this edit has just reshaped. The next move of the drag draws it
1185+ // again; until then it says nothing.
1186+ self.ghost = None;
1142 }1187 }
1143 1188
1144 /// What an action does, wherever it was asked for -- a stroke, or the clip1189 /// What an action does, wherever it was asked for -- a stroke, or the clip
@@ -1205,6 +1250,7 @@ impl Player {
1205 fn toggle_snap(&mut self, cx: &mut Context<Self>) {1250 fn toggle_snap(&mut self, cx: &mut Context<Self>) {
1206 self.snap = !self.snap;1251 self.snap = !self.snap;
1207 self.snap_cue = None;1252 self.snap_cue = None;
1253+ self.ghost = None;
1208 self.notice = Some(match self.snap {1254 self.notice = Some(match self.snap {
1209 true => "SNAP ON — drags land on clip edges, the playhead and the start".into(),1255 true => "SNAP ON — drags land on clip edges, the playhead and the start".into(),
1210 false => "SNAP OFF — drags land exactly where the hand leaves them".into(),1256 false => "SNAP OFF — drags land exactly where the hand leaves them".into(),
@@ -2619,9 +2665,32 @@ impl Player {
2619 /// leave a screen of empty bed after the end, the way every NLE does.2665 /// leave a screen of empty bed after the end, the way every NLE does.
2620 fn drop_frame(&self, from: Lane, idx: usize, x: Pixels) -> Option<(u32, Option<u32>)> {2666 fn drop_frame(&self, from: Lane, idx: usize, x: Pixels) -> Option<(u32, Option<u32>)> {
2621 let clip = self.session.as_ref()?.lane_clips(from).get(idx).copied()?;2667 let clip = self.session.as_ref()?.lane_clips(from).get(idx).copied()?;
2622- let raw = self.frame_under(x).saturating_sub(self.grab);
2623 let marks = self.snap_targets(Some((from, idx)));2668 let marks = self.snap_targets(Some((from, idx)));
2624- Some(self.snap_to(raw, clip.frames(), &marks))2669+ Some(landing(
2670+ self.frame_under(x),
2671+ self.grab,
2672+ clip.frames(),
2673+ self.snap,
2674+ self.snap_frames(),
2675+ &marks,
2676+ ))
2677+ }
2678+
2679+ /// The same answer for a library row on its way down: nothing is in the hand
2680+ /// yet, so there is no grab offset to take off and no length to snap by --
2681+ /// the file's own is not known until the engine has placed it -- and only
2682+ /// its head lands. Asked by the line, by the ghost and by the drop itself
2683+ /// ([`Player::insert_source`]), so all three name one frame.
2684+ fn place_frame(&self, x: Pixels) -> (u32, Option<u32>) {
2685+ let marks = self.snap_targets(None);
2686+ landing(
2687+ self.frame_under(x),
2688+ 0,
2689+ 0,
2690+ self.snap,
2691+ self.snap_frames(),
2692+ &marks,
2693+ )
2625 }2694 }
2626 2695
2627 /// Which index the clip in the hand is at *now*: [`live_idx`] against the2696 /// Which index the clip in the hand is at *now*: [`live_idx`] against the
@@ -2644,15 +2713,91 @@ impl Player {
2644 }2713 }
2645 2714
2646 /// The same line for a library row on its way to a lane: it goes down at2715 /// The same line for a library row on its way to a lane: it goes down at
2647- /// the frame it is let go on ([`Player::insert_source`]), so that frame is2716+ /// the frame it is let go on ([`Player::place_frame`]), so that frame is
2648- /// what snaps and what is drawn. No length to snap by -- the file's own is2717+ /// what snaps and what is drawn.
2649- /// not known until the engine has placed it -- so only its head lands.
2650 fn preview_place(&mut self, x: Pixels, cx: &mut Context<Self>) {2718 fn preview_place(&mut self, x: Pixels, cx: &mut Context<Self>) {
2651- let marks = self.snap_targets(None);2719+ let cue = self.place_frame(x).1;
2652- let cue = self.snap_to(self.frame_under(x), 0, &marks).1;
2653 self.set_cue(cue, x, cx);2720 self.set_cue(cue, x, cx);
2654 }2721 }
2655 2722
2723+ /// The shadow the clip in the hand would fill, on the lane the pointer is
2724+ /// over: its head where [`Player::drop_frame`] says the release will put it
2725+ /// -- the same call the drop makes, so the box drawn and the box committed
2726+ /// are one answer -- and its own length at this zoom. A lane of the other
2727+ /// kind refuses the drop ([`Project::move_clip`]), and the shadow says so
2728+ /// before the release does.
2729+ fn preview_ghost(&mut self, drag: &ClipDrag, to: Lane, x: Pixels, cx: &mut Context<Self>) {
2730+ let ghost = self
2731+ .dragged(drag)
2732+ .and_then(|idx| self.drop_frame(drag.lane, idx, x))
2733+ .map(|(start, _)| Ghost {
2734+ lane: to,
2735+ start,
2736+ frames: drag.clip.frames(),
2737+ tint: self.clip_tint(drag.clip.source),
2738+ refused: drag.lane.kind != to.kind,
2739+ });
2740+ self.set_ghost(ghost, cx);
2741+ }
2742+
2743+ /// The same shadow for a library row: its head at [`Player::place_frame`],
2744+ /// which is where the drop inserts it, and the file's own length for its
2745+ /// width -- the length the library row already reports. A file this lane
2746+ /// cannot hold ([`lane_refuses`]) is tinted as refused, which is the answer
2747+ /// the release would give in words.
2748+ fn preview_ghost_asset(&mut self, path: &Path, to: Lane, x: Pixels, cx: &mut Context<Self>) {
2749+ let ghost = Ghost {
2750+ lane: to,
2751+ start: self.place_frame(x).0,
2752+ frames: self
2753+ .session
2754+ .as_ref()
2755+ .map_or(0, |session| session.file_frames(path)),
2756+ tint: self.file_tint(path),
2757+ refused: lane_refuses(path, to).is_some(),
2758+ };
2759+ self.set_ghost(Some(ghost), cx);
2760+ }
2761+
2762+ /// Sets the shadow, or takes it away, repainting only when it moved -- the
2763+ /// listeners below run it on every pointer sample of a drag. Cleared by the
2764+ /// root and set again by the lane under the pointer, in that order (gpui
2765+ /// runs the capture phase parent-first), so a pointer over no lane at all
2766+ /// leaves nothing drawn.
2767+ fn set_ghost(&mut self, ghost: Option<Ghost>, cx: &mut Context<Self>) {
2768+ if ghost != self.ghost {
2769+ self.ghost = ghost;
2770+ cx.notify();
2771+ }
2772+ }
2773+
2774+ /// The swatch a clip from source `n` wears: [`source_tint`] over the first
2775+ /// source entry naming that *file*, since two audio streams of one file are
2776+ /// two sources and one colour. Every box on a lane and every ghost a drag
2777+ /// draws asks this, so the shadow is recognisably the thing in the hand.
2778+ fn clip_tint(&self, source: usize) -> u32 {
2779+ match self.sources().get(source) {
2780+ Some(entry) => self.file_tint(&entry.path),
2781+ None => source_tint(source),
2782+ }
2783+ }
2784+
2785+ /// The same swatch asked by path, which is what a library row is named by.
2786+ fn file_tint(&self, path: &Path) -> u32 {
2787+ source_tint(
2788+ self.sources()
2789+ .iter()
2790+ .position(|s| s.path == path)
2791+ .unwrap_or(0),
2792+ )
2793+ }
2794+
2795+ fn sources(&self) -> &[Source] {
2796+ self.session
2797+ .as_ref()
2798+ .map_or(&[][..], PlaybackSession::sources)
2799+ }
2800+
2656 /// Sets the line, or takes it away, and repaints only when it moved: a2801 /// Sets the line, or takes it away, and repaints only when it moved: a
2657 /// pointer dragged off the bed (up to the library, say) is not promising a2802 /// pointer dragged off the bed (up to the library, say) is not promising a
2658 /// landing any more.2803 /// landing any more.
@@ -2876,28 +3021,13 @@ impl Player {
2876 if self.exporting().is_some() {3021 if self.exporting().is_some() {
2877 return;3022 return;
2878 }3023 }
2879- // A file with no picture belongs on an audio lane and nowhere else:3024+ // The lane the pointer named cannot hold this kind of file: refused by
2880- // dropped on a video lane it is refused by name, and asked for by the3025+ // name, in the same words the ghost was tinted by on the way down
2881- // Add button (which names no lane) it goes to the audio one -- which is3026+ // ([`lane_refuses`]). The Add button names no lane and so is never
2882- // the engine's choice, in `place_stream_at`, not one made twice here.3027+ // refused here -- where a file goes when nobody says is the engine's
2883- if engine::is_audio(path) && onto.is_some_and(|lane| lane.kind == LaneKind::Video) {3028+ // choice, in `place_stream_at`, not one made twice here.
2884- let name = file_name(path);3029+ if let Some(why) = onto.and_then(|lane| lane_refuses(path, lane)) {
2885- let lane = onto.expect("checked above").label();3030+ self.notice = Some(why.into());
2886- self.notice = Some(
2887- format!("NOT ON {lane} — {name} has no picture; drop it on an audio lane").into(),
2888- );
2889- cx.notify();
2890- return;
2891- }
2892- // ...and the mirror of it: a still is silent, so an audio lane is the
2893- // one place it cannot go. The engine puts it on `V1` regardless
2894- // (`place_stream_at`); this is the word that says why it moved.
2895- if engine::is_image(path) && onto.is_some_and(|lane| lane.kind == LaneKind::Audio) {
2896- let name = file_name(path);
2897- let lane = onto.expect("checked above").label();
2898- self.notice = Some(
2899- format!("NOT ON {lane} — {name} is a still image; drop it on a video lane").into(),
2900- );
2901 cx.notify();3031 cx.notify();
2902 return;3032 return;
2903 }3033 }
@@ -4058,10 +4188,18 @@ impl Render for Player {
4058 if let Some(idx) = this.dragged(&drag) {4188 if let Some(idx) = this.dragged(&drag) {
4059 this.preview_drop(drag.lane, idx, event.event.position.x, cx);4189 this.preview_drop(drag.lane, idx, event.event.position.x, cx);
4060 }4190 }
4191+ // The shadow belongs to a *lane*, and which lane the pointer is
4192+ // over is the one thing this element cannot see. Cleared here
4193+ // and drawn again by the lane the pointer is actually inside
4194+ // (`lane_row`), which gpui runs straight after this one: the
4195+ // capture phase goes parent first, so a pointer over no lane at
4196+ // all -- up in the library, say -- promises nothing.
4197+ this.set_ghost(None, cx);
4061 }))4198 }))
4062 .on_drag_move(4199 .on_drag_move(
4063 cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| {4200 cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| {
4064 this.preview_place(event.event.position.x, cx);4201 this.preview_place(event.event.position.x, cx);
4202+ this.set_ghost(None, cx);
4065 }),4203 }),
4066 )4204 )
4067 // Scrubbing is tracked on the root because the pointer leaves the4205 // Scrubbing is tracked on the root because the pointer leaves the
@@ -7179,6 +7317,11 @@ impl Player {
7179 .snap_cue7317 .snap_cue
7180 .filter(|_| self.trim.is_some() || cx.has_active_drag())7318 .filter(|_| self.trim.is_some() || cx.has_active_drag())
7181 .map(|frame| scale.px_at(f64::from(frame) / self.fps));7319 .map(|frame| scale.px_at(f64::from(frame) / self.fps));
7320+ // The shadow, on the one lane the pointer is over -- and, like the line,
7321+ // only while the drag that asked for it is still in flight.
7322+ let ghost = self
7323+ .ghost
7324+ .filter(|g| g.lane == lane && cx.has_active_drag());
7182 let clips = self7325 let clips = self
7183 .session7326 .session
7184 .as_ref()7327 .as_ref()
@@ -7328,12 +7471,26 @@ impl Player {
7328 // Onto the edges near it, exactly as a clip carried by7471 // Onto the edges near it, exactly as a clip carried by
7329 // hand lands: the line drawn while it was in flight is7472 // hand lands: the line drawn while it was in flight is
7330 // the frame it goes down on.7473 // the frame it goes down on.
7331- let x = window.mouse_position().x;7474+ let at = this.place_frame(window.mouse_position().x).0;
7332- let marks = this.snap_targets(None);
7333- let (at, _) = this.snap_to(this.frame_under(x), 0, &marks);
7334 this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx)7475 this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx)
7335 }))7476 }))
7336 .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM)))7477 .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM)))
7478+ // The shadow of the row in flight, drawn by the lane the
7479+ // pointer is inside: `on_drag_move` fires on every painted
7480+ // element while a drag of its type is live, wherever the
7481+ // pointer is, and hands each one its own box -- which is how
7482+ // a lane knows the pointer is over *it* (gpui div.rs:282).
7483+ // The root cleared it a moment ago, so exactly one lane
7484+ // draws one.
7485+ .on_drag_move(cx.listener(
7486+ move |this, event: &DragMoveEvent<AssetDrag>, _, cx| {
7487+ if !event.bounds.contains(&event.event.position) {
7488+ return;
7489+ }
7490+ let path = event.drag(cx).0.clone();
7491+ this.preview_ghost_asset(&path, lane, event.event.position.x, cx);
7492+ },
7493+ ))
7337 // ...and a clip let go over a lane lands the same way: on7494 // ...and a clip let go over a lane lands the same way: on
7338 // the track it was dropped on, at the frame it was carried7495 // the track it was dropped on, at the frame it was carried
7339 // to -- its own included, which is the drag that moves a7496 // to -- its own included, which is the drag that moves a
@@ -7349,6 +7506,17 @@ impl Player {
7349 this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx)7506 this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx)
7350 }))7507 }))
7351 .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM)))7508 .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM)))
7509+ // ...and the same shadow for the clip in the hand, seated on
7510+ // this lane when the pointer is inside it.
7511+ .on_drag_move(cx.listener(
7512+ move |this, event: &DragMoveEvent<ClipDrag>, _, cx| {
7513+ if !event.bounds.contains(&event.event.position) {
7514+ return;
7515+ }
7516+ let drag = *event.drag(cx);
7517+ this.preview_ghost(&drag, lane, event.event.position.x, cx);
7518+ },
7519+ ))
7352 .children(clips.iter().enumerate().map(|(i, clip)| {7520 .children(clips.iter().enumerate().map(|(i, clip)| {
7353 // The clip as the lane holds it, for the drag payload:7521 // The clip as the lane holds it, for the drag payload:
7354 // what a drop looks itself up by has to be the placed7522 // what a drop looks itself up by has to be the placed
@@ -7372,12 +7540,7 @@ impl Player {
7372 // Tinted by *file*, not by source entry: two audio7540 // Tinted by *file*, not by source entry: two audio
7373 // streams of one file are two sources, and the library7541 // streams of one file are two sources, and the library
7374 // gives them one swatch because they are one file.7542 // gives them one swatch because they are one file.
7375- let tint = source_tint(7543+ let tint = self.clip_tint(clip.source);
7376- sources
7377- .get(clip.source)
7378- .and_then(|s| sources.iter().position(|o| o.path == s.path))
7379- .unwrap_or(clip.source),
7380- );
7381 let width = scale.width_px(len);7544 let width = scale.width_px(len);
7382 let left = scale.px_at(start);7545 let left = scale.px_at(start);
7383 // The slice of this box that is on the bed: where its7546 // The slice of this box that is on the bed: where its
@@ -7625,6 +7788,34 @@ impl Player {
7625 .bg(rgba(0x4a9effaa))7788 .bg(rgba(0x4a9effaa))
7626 }),7789 }),
7627 )7790 )
7791+ // Where the thing in the hand would come to rest, at the size
7792+ // it would come to rest at: the shadow a proper editor draws
7793+ // under a drag. Over the clips (it is translucent, so what
7794+ // it would cover shows through) and under the line, which
7795+ // marks the frame this box merely fills.
7796+ .children(ghost.map(|g| {
7797+ div()
7798+ .absolute()
7799+ .top_0()
7800+ .h_full()
7801+ .left(px(scale.px_at(f64::from(g.start) / self.fps)))
7802+ // A row whose length the engine has not measured
7803+ // draws a head marker rather than nothing: where it
7804+ // lands is known, how long it is is not.
7805+ .w(px(scale
7806+ .width_px(f64::from(g.frames) / self.fps)
7807+ .max(GHOST_MIN)))
7808+ .rounded(px(3.))
7809+ .border_1()
7810+ .border_color(rgb(if g.refused { REFUSE } else { INK }))
7811+ // The file's own swatch at a third of its weight, so
7812+ // the box beneath is still legible through it -- and
7813+ // the refusal red instead, for a lane that will not
7814+ // take this drop at all.
7815+ .bg(rgba(
7816+ ((if g.refused { REFUSE } else { g.tint }) << 8) | GHOST_ALPHA,
7817+ ))
7818+ }))
7628 // What the gesture in flight is about to land on, drawn on7819 // What the gesture in flight is about to land on, drawn on
7629 // every lane so a clip lining up with a take one track over7820 // every lane so a clip lining up with a take one track over
7630 // can be seen to line up with it. Under the playhead's line7821 // can be seen to line up with it. Under the playhead's line
@@ -9568,6 +9759,44 @@ fn snap_cue(on: bool, raw: u32, len: u32, tol: u32, marks: &[u32]) -> (u32, Opti
9568 (start, mark)9759 (start, mark)
9569 }9760 }
9570 9761
9762+/// Where a drag lands and the mark that pulled it there: the frame under the
9763+/// pointer, less however far into the box the hand grabbed it (so a clip travels
9764+/// with the pointer rather than jumping its head under it), snapped by
9765+/// [`snap_cue`]. One answer, asked by the shadow drawn in flight
9766+/// ([`Player::preview_ghost`]), by the line ([`Player::preview_drop`]) and by
9767+/// the drop that commits ([`Player::move_clip`]) -- which is what makes the
9768+/// promise and the landing the same frame.
9769+fn landing(
9770+ under: u32,
9771+ grab: u32,
9772+ len: u32,
9773+ on: bool,
9774+ tol: u32,
9775+ marks: &[u32],
9776+) -> (u32, Option<u32>) {
9777+ snap_cue(on, under.saturating_sub(grab), len, tol, marks)
9778+}
9779+
9780+/// Why this file may not go on that lane, in the words the refusal is told in --
9781+/// `None` when it may. A file with no picture belongs on an audio lane and
9782+/// nowhere else, and a still is silent, so an audio lane is the one place it
9783+/// cannot go. Asked twice: by the ghost tinting itself as refused on the way
9784+/// down, and by the insert that commits ([`Player::insert_source`]), so what is
9785+/// shown as impossible is exactly what is refused.
9786+fn lane_refuses(path: &Path, lane: Lane) -> Option<String> {
9787+ let name = file_name(path);
9788+ let label = lane.label();
9789+ match lane.kind {
9790+ LaneKind::Video if engine::is_audio(path) => {
9791+ Some(format!("NOT ON {label} — {name} has no picture; drop it on an audio lane"))
9792+ }
9793+ LaneKind::Audio if engine::is_image(path) => {
9794+ Some(format!("NOT ON {label} — {name} is a still image; drop it on a video lane"))
9795+ }
9796+ _ => None,
9797+ }
9798+}
9799+
9571 /// Where down an element a pointer sits, 0..1 from the top: the vertical twin9800 /// Where down an element a pointer sits, 0..1 from the top: the vertical twin
9572 /// of [`frac_along`], for the equalizer, whose gain axis is the y one. An9801 /// of [`frac_along`], for the equalizer, whose gain axis is the y one. An
9573 /// element that was never painted reads as its middle -- flat, the one answer9802 /// element that was never painted reads as its middle -- flat, the one answer
@@ -9944,8 +10173,8 @@ mod tests {
9944 };10173 };
9945 use super::{10174 use super::{
9946 Edge, LaneKind, PPS_DEFAULT, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES,10175 Edge, LaneKind, PPS_DEFAULT, Repeat, Scale, View, ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES,
9947- ZOOM_STEP, file_name, file_uri, library_rows, live_idx, px_along, repeats, span_label,10176+ ZOOM_STEP, file_name, file_uri, landing, lane_refuses, library_rows, live_idx, px_along,
9948- trimmed_clip, unscannable, visible_slice,10177+ repeats, span_label, trimmed_clip, unscannable, visible_slice,
9949 };10178 };
9950 10179
9951 /// What the file manager is handed: the parts a path keeps as they are, and10180 /// What the file manager is handed: the parts a path keeps as they are, and
@@ -11130,6 +11359,64 @@ mod tests {
11130 assert_eq!(snapped(2, 40, 4, &marks), 0);11359 assert_eq!(snapped(2, 40, 4, &marks), 0);
11131 }11360 }
11132 11361
11362+ /// The shadow a drag draws and the drop that commits are one answer: both
11363+ /// ask [`landing`], so the box seen in flight is the box the release leaves
11364+ /// behind. What this pins down is the composition around the snap -- the
11365+ /// grab offset comes off *before* the magnet, or a clip taken by its tail
11366+ /// would land a boxful late.
11367+ #[test]
11368+ fn a_ghost_and_a_drop_are_one_landing() {
11369+ // A neighbour covering [100, 160), the playhead at 300, and a 40 frame
11370+ // clip taken hold of 12 frames in.
11371+ let marks = [100, 160, 300, 0];
11372+ let (len, grab, tol) = (40, 12, 4);
11373+ // Pointer at frame 170: the head is 12 frames behind it, at 158, which
11374+ // is a frame short of the neighbour's tail -- so both the ghost and the
11375+ // drop say 160, and the line stands on the mark that pulled it.
11376+ assert_eq!(landing(170, grab, len, true, tol, &marks), (160, Some(160)));
11377+ // Without the grab taken off first, the same pointer would land the
11378+ // box at 170 and no mark would be in reach: the offset is not cosmetic.
11379+ assert_eq!(landing(170, 0, len, true, tol, &marks), (170, None));
11380+ // A library row carries no grab and no length the engine has measured,
11381+ // which is how `Player::place_frame` asks: only its head lands, on the
11382+ // playhead here.
11383+ assert_eq!(landing(298, 0, 0, true, tol, &marks), (300, Some(300)));
11384+ // The magnet off, ghost and drop agree on the raw frame and no line is
11385+ // drawn -- the frame-by-frame placement the switch is for.
11386+ assert_eq!(landing(170, grab, len, false, tol, &marks), (158, None));
11387+ // A pointer nearer the bed's start than the hand is into the box cannot
11388+ // pull a head below zero.
11389+ assert_eq!(landing(3, grab, len, true, tol, &marks), (0, Some(0)));
11390+ }
11391+
11392+ /// Which lanes tint that shadow as refused: the two kinds of file a lane
11393+ /// cannot hold, in the words the release would say them in -- one rule, so
11394+ /// what is shown as impossible is exactly what is refused.
11395+ #[test]
11396+ fn a_lane_refuses_the_files_it_cannot_hold_before_the_release_says_so() {
11397+ let (video, audio) = (Lane::V1, Lane::A1);
11398+ let sound = Path::new("/media/take.mp3");
11399+ let still = Path::new("/media/card.png");
11400+ let movie = Path::new("/media/take.mp4");
11401+ assert_eq!(
11402+ lane_refuses(sound, video).as_deref(),
11403+ Some("NOT ON V1 — take.mp3 has no picture; drop it on an audio lane")
11404+ );
11405+ assert_eq!(
11406+ lane_refuses(still, audio).as_deref(),
11407+ Some("NOT ON A1 — card.png is a still image; drop it on a video lane")
11408+ );
11409+ // ...and every lane a file *can* go on says nothing at all, which is a
11410+ // ghost drawn in the file's own colour.
11411+ assert_eq!(lane_refuses(sound, audio), None);
11412+ assert_eq!(lane_refuses(still, video), None);
11413+ assert_eq!(lane_refuses(movie, video), None);
11414+ // A file with a picture is not refused by an audio lane here: the
11415+ // engine takes its sound onto one, and the words for a video-only file
11416+ // are its own.
11417+ assert_eq!(lane_refuses(movie, audio), None);
11418+ }
11419+
11133 /// Where those edges come from: every lane, not the one being dropped on --11420 /// Where those edges come from: every lane, not the one being dropped on --
11134 /// and never the clip in the hand or the half of it one track down.11421 /// and never the clip in the hand or the half of it one track down.
11135 #[test]11422 #[test]
@@ -13389,6 +13676,7 @@ fn main() {
13389 grab: 0,13676 grab: 0,
13390 snap: true,13677 snap: true,
13391 snap_cue: None,13678 snap_cue: None,
13679+ ghost: None,
13392 last_scrub: Instant::now(),13680 last_scrub: Instant::now(),
13393 last_target: 0,13681 last_target: 0,
13394 export: None,13682 export: None,