Merge branch 'worktree-agent-a590d0f29d58dcad2'
Browse files at this commit9 changed files +591 -118
- crates/app/src/main.rs +16 -0
- crates/app/src/player/timeline_edit.rs +87 -18
- crates/app/src/tests/editing.rs +5 -2
- crates/app/src/tests/layout.rs +1 -1
- crates/app/src/tests/view.rs +3 -3
- crates/app/src/timeline_math.rs +237 -2
- crates/app/src/ui/bench_stance.rs +206 -87
- crates/app/src/ui/dock_stance.rs +28 -4
- crates/app/src/ui/stance.rs +8 -1
crates/app/src/main.rsmodified+16 -0
| @@ -333,6 +333,14 @@ struct Player { | |||
| 333 | /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement | 333 | /// by one stroke ([`ActionId::ToggleSnap`]) for the frame-by-frame placement |
| 334 | /// no magnet may take away. | 334 | /// no magnet may take away. |
| 335 | snap: bool, | 335 | snap: bool, |
| 336 | + /// Whether `alt` was down on the last sample of the gesture in flight: | ||
| 337 | + /// snapping off for *this* drag only, the override every NLE has for the | ||
| 338 | + /// one clip that has to sit a frame off an edge, leaving [`Player::snap`] | ||
| 339 | + /// -- the switch -- exactly as the hand left it. Read by | ||
| 340 | + /// [`Player::snap_live`], written by the bench's own drag samples and by | ||
| 341 | + /// the trim's, and stale between gestures, which costs nothing: every | ||
| 342 | + /// gesture writes it before it asks. | ||
| 343 | + drag_alt: bool, | ||
| 336 | /// Whether the subtitle lanes draw at all -- the mute over the shown lane | 344 | /// Whether the subtitle lanes draw at all -- the mute over the shown lane |
| 337 | /// ([`Player::sub_lane`]), not a lane of its own. On by default and off by | 345 | /// ([`Player::sub_lane`]), not a lane of its own. On by default and off by |
| 338 | /// one stroke | 346 | /// one stroke |
| @@ -398,6 +406,12 @@ struct Player { | |||
| 398 | /// the pointer is not guaranteed to answer what the ghost just showed | 406 | /// the pointer is not guaranteed to answer what the ghost just showed |
| 399 | /// (DESIGN: "drop == shadow, by construction"). `None` between drags. | 407 | /// (DESIGN: "drop == shadow, by construction"). `None` between drags. |
| 400 | drag_x: Option<Pixels>, | 408 | drag_x: Option<Pixels>, |
| 409 | + /// The lane the last live sample of the drag in flight was over -- the one | ||
| 410 | + /// a release off the rows themselves (left of the heads, between two rows, | ||
| 411 | + /// below the last track) lands on, so a gesture that has already promised a | ||
| 412 | + /// landing in the shadow cannot end in nothing. `None` before the pointer | ||
| 413 | + /// has been over any lane, where there is no landing to promise. | ||
| 414 | + drag_lane: Option<Lane>, | ||
| 401 | /// The slot a track header being dragged is about to drop into, or `None` | 415 | /// The slot a track header being dragged is about to drop into, or `None` |
| 402 | /// while the pointer is over no lane: the line drawn between two headers, | 416 | /// while the pointer is over no lane: the line drawn between two headers, |
| 403 | /// for the reason [`Player::ghost`] draws a shadow -- where a gesture lands | 417 | /// for the reason [`Player::ghost`] draws a shadow -- where a gesture lands |
| @@ -935,6 +949,7 @@ fn main() { | |||
| 935 | fade_drag: None, | 949 | fade_drag: None, |
| 936 | grab: 0, | 950 | grab: 0, |
| 937 | snap: true, | 951 | snap: true, |
| 952 | + drag_alt: false, | ||
| 938 | subs_on: true, | 953 | subs_on: true, |
| 939 | sub_track: 0, | 954 | sub_track: 0, |
| 940 | sub_folded: HashSet::new(), | 955 | sub_folded: HashSet::new(), |
| @@ -942,6 +957,7 @@ fn main() { | |||
| 942 | snap_cue: None, | 957 | snap_cue: None, |
| 943 | ghost: Vec::new(), | 958 | ghost: Vec::new(), |
| 944 | drag_x: None, | 959 | drag_x: None, |
| 960 | + drag_lane: None, | ||
| 945 | lane_drop: None, | 961 | lane_drop: None, |
| 946 | last_scrub: Instant::now(), | 962 | last_scrub: Instant::now(), |
| 947 | last_target: 0, | 963 | last_target: 0, |
crates/app/src/player/timeline_edit.rsmodified+87 -18
| @@ -399,6 +399,10 @@ impl Player { | |||
| 399 | self.selected.clear(); | 399 | self.selected.clear(); |
| 400 | } | 400 | } |
| 401 | self.reset_after_reseek(); | 401 | self.reset_after_reseek(); |
| 402 | + // The strip names the edit that just happened: a move that | ||
| 403 | + // lands silently leaves the last word (`SPLIT`) standing, and | ||
| 404 | + // an editor reads that as the drag having done nothing. | ||
| 405 | + self.notify_user("MOVED".into()); | ||
| 402 | } | 406 | } |
| 403 | // The three ways a drag is refused, told apart by what the | 407 | // The three ways a drag is refused, told apart by what the |
| 404 | // front-end already knows: a lane's kind, and where the clip was. | 408 | // front-end already knows: a lane's kind, and where the clip was. |
| @@ -431,6 +435,9 @@ impl Player { | |||
| 431 | .into(), | 435 | .into(), |
| 432 | ), | 436 | ), |
| 433 | } | 437 | } |
| 438 | + // The gesture is over: the lane it ended over is nobody's answer any | ||
| 439 | + // more (`Player::drag_lane`, read by `bench-content`'s catch-all). | ||
| 440 | + self.drag_lane = None; | ||
| 434 | cx.notify(); | 441 | cx.notify(); |
| 435 | } | 442 | } |
| 436 | 443 | ||
| @@ -751,7 +758,7 @@ impl Player { | |||
| 751 | self.frame_under(x), | 758 | self.frame_under(x), |
| 752 | self.grab, | 759 | self.grab, |
| 753 | sub.frames, | 760 | sub.frames, |
| 754 | - self.snap, | 761 | + self.snap_live(), |
| 755 | self.drop_snap_frames(), | 762 | self.drop_snap_frames(), |
| 756 | &marks, | 763 | &marks, |
| 757 | ) | 764 | ) |
| @@ -802,7 +809,7 @@ impl Player { | |||
| 802 | /// Where a clip let go at window `x` over lane `to` wants its head: the | 809 | /// Where a clip let go at window `x` over lane `to` wants its head: the |
| 803 | /// frame under the pointer, less however far into the box the hand grabbed | 810 | /// frame under the pointer, less however far into the box the hand grabbed |
| 804 | /// it (so the clip does not jump under the pointer), pulled onto a | 811 | /// it (so the clip does not jump under the pointer), pulled onto a |
| 805 | - /// neighbouring edge when it lands within [`SNAP_PX`] of one. `None` when | 812 | + /// neighbouring edge when it lands within [`Player::drop_snap_frames`] of one. `None` when |
| 806 | /// there is no such clip to move. The engine has the last word on where it | 813 | /// there is no such clip to move. The engine has the last word on where it |
| 807 | /// may actually go -- this is the ask, not the answer. | 814 | /// may actually go -- this is the ask, not the answer. |
| 808 | /// | 815 | /// |
| @@ -824,7 +831,7 @@ impl Player { | |||
| 824 | self.frame_under(x), | 831 | self.frame_under(x), |
| 825 | self.grab, | 832 | self.grab, |
| 826 | clip.frames(), | 833 | clip.frames(), |
| 827 | - self.snap, | 834 | + self.snap_live(), |
| 828 | self.drop_snap_frames(), | 835 | self.drop_snap_frames(), |
| 829 | &marks, | 836 | &marks, |
| 830 | )) | 837 | )) |
| @@ -841,7 +848,7 @@ impl Player { | |||
| 841 | self.frame_under(x), | 848 | self.frame_under(x), |
| 842 | 0, | 849 | 0, |
| 843 | 0, | 850 | 0, |
| 844 | - self.snap, | 851 | + self.snap_live(), |
| 845 | self.drop_snap_frames(), | 852 | self.drop_snap_frames(), |
| 846 | &marks, | 853 | &marks, |
| 847 | ) | 854 | ) |
| @@ -887,12 +894,49 @@ impl Player { | |||
| 887 | self.set_ghost(Vec::new(), cx); | 894 | self.set_ghost(Vec::new(), cx); |
| 888 | return; | 895 | return; |
| 889 | }; | 896 | }; |
| 897 | + // What the release would refuse: a lane of the other kind, and a head | ||
| 898 | + // let go on top of a take already there ([`Project::move_selection`] | ||
| 899 | + // changes nothing rather than overwrite one). Drawn as refused so a | ||
| 900 | + // drop that will not happen is seen before the hand lets go, never as a | ||
| 901 | + // silent no-op. The neighbours are the destination lane's clips less | ||
| 902 | + // whatever travels with this one -- itself and its link group. | ||
| 903 | + let neighbours: Vec<(u32, u32)> = self | ||
| 904 | + .session | ||
| 905 | + .as_ref() | ||
| 906 | + .map(|session| { | ||
| 907 | + session | ||
| 908 | + .lane_clips(to) | ||
| 909 | + .iter() | ||
| 910 | + .enumerate() | ||
| 911 | + .filter(|&(i, clip)| { | ||
| 912 | + (to, i) != (drag.lane, idx) | ||
| 913 | + && !(clip.link.is_some() && clip.link == drag.clip.link) | ||
| 914 | + }) | ||
| 915 | + .map(|(_, clip)| (clip.start, clip.end())) | ||
| 916 | + .collect() | ||
| 917 | + }) | ||
| 918 | + .unwrap_or_default(); | ||
| 919 | + // Staying on its own lane, the engine clamps the travel into the gap | ||
| 920 | + // the clip sits in rather than refusing it, so the shadow rests where | ||
| 921 | + // the release will: flush against the take it was dragged into. Landing | ||
| 922 | + // on *another* lane it clamps too ([`cross_room`], the engine's own | ||
| 923 | + // `move_room` rule) and refuses only a head let go *inside* a take or a | ||
| 924 | + // gap too narrow to hold the clip -- the shadow says so before the hand | ||
| 925 | + // lets go, and never claims a refusal the release would not make. | ||
| 926 | + let len = drag.clip.frames(); | ||
| 927 | + let (start, refused) = match to == drag.lane { | ||
| 928 | + true => (gap_clamp(drag.clip.start, len, start, &neighbours), false), | ||
| 929 | + false => match cross_room(start, len, &neighbours) { | ||
| 930 | + Some(landed) => (landed, false), | ||
| 931 | + None => (start, true), | ||
| 932 | + }, | ||
| 933 | + }; | ||
| 890 | let anchor = Ghost { | 934 | let anchor = Ghost { |
| 891 | lane: to, | 935 | lane: to, |
| 892 | start, | 936 | start, |
| 893 | - frames: drag.clip.frames(), | 937 | + frames: len, |
| 894 | tint: self.clip_tint(drag.clip.source), | 938 | tint: self.clip_tint(drag.clip.source), |
| 895 | - refused: drag.lane.kind != to.kind, | 939 | + refused: drag.lane.kind != to.kind || refused, |
| 896 | }; | 940 | }; |
| 897 | let mut ghosts = vec![anchor]; | 941 | let mut ghosts = vec![anchor]; |
| 898 | if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 { | 942 | if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 { |
| @@ -1046,13 +1090,13 @@ impl Player { | |||
| 1046 | .flatten() | 1090 | .flatten() |
| 1047 | }); | 1091 | }); |
| 1048 | let skip = skip.and_then(|(lane, idx)| Some((lanes.iter().position(|&l| l == lane)?, idx))); | 1092 | let skip = skip.and_then(|(lane, idx)| Some((lanes.iter().position(|&l| l == lane)?, idx))); |
| 1049 | - snap_marks(&clips, skip, skip_link, frame_at(session.now(), self.fps)) | 1093 | + snap_marks( |
| 1050 | - } | 1094 | + &clips, |
| 1051 | - | 1095 | + skip, |
| 1052 | - /// Where a gesture at `raw` lands and the mark that pulled it there, with | 1096 | + skip_link, |
| 1053 | - /// the switch honoured: snapping off, nothing moves and no line is drawn. | 1097 | + frame_at(session.now(), self.fps), |
| 1054 | - pub(crate) fn snap_to(&self, raw: u32, len: u32, marks: &[u32]) -> (u32, Option<u32>) { | 1098 | + self.range, |
| 1055 | - snap_cue(self.snap, raw, len, self.snap_frames(), marks) | 1099 | + ) |
| 1056 | } | 1100 | } |
| 1057 | 1101 | ||
| 1058 | /// Every timeline frame that is a *source* sync point: each clip's own | 1102 | /// Every timeline frame that is a *source* sync point: each clip's own |
| @@ -1145,9 +1189,21 @@ impl Player { | |||
| 1145 | } | 1189 | } |
| 1146 | } | 1190 | } |
| 1147 | 1191 | ||
| 1148 | - /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the bed's | 1192 | + /// Whether the magnet is on for the gesture happening *now*: the switch |
| 1149 | - /// own width drops out of it, since a pixel is now worth the same stretch of | 1193 | + /// ([`Player::snap`]) unless `alt` is held ([`Player::drag_alt`]), which |
| 1150 | - /// timeline wherever the view sits. | 1194 | + /// turns it off for this drag or trim alone -- the temporary override |
| 1195 | + /// Resolve, Premiere and Final Cut all put on the same key. The switch is | ||
| 1196 | + /// not touched, so the stroke that follows the drag finds it where it was. | ||
| 1197 | + /// Every landing on this timeline asks it, so the shadow, the line and the | ||
| 1198 | + /// drop can never disagree about whether a magnet was on. | ||
| 1199 | + pub(crate) fn snap_live(&self) -> bool { | ||
| 1200 | + snap_live(self.snap, self.drag_alt) | ||
| 1201 | + } | ||
| 1202 | + | ||
| 1203 | + /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the | ||
| 1204 | + /// bed's own width drops out of it, since a pixel is now worth the same | ||
| 1205 | + /// stretch of timeline wherever the view sits. The edge trims' magnet -- | ||
| 1206 | + /// a drop asks [`Player::drop_snap_frames`]. | ||
| 1151 | pub(crate) fn snap_frames(&self) -> u32 { | 1207 | pub(crate) fn snap_frames(&self) -> u32 { |
| 1152 | self.scale.snap_frames(self.fps) | 1208 | self.scale.snap_frames(self.fps) |
| 1153 | } | 1209 | } |
| @@ -1448,7 +1504,16 @@ impl Player { | |||
| 1448 | // The edge is pulled onto the same marks a whole clip is, by itself: | 1504 | // The edge is pulled onto the same marks a whole clip is, by itself: |
| 1449 | // there is no other end travelling with it, so it snaps at length zero. | 1505 | // there is no other end travelling with it, so it snaps at length zero. |
| 1450 | let marks = self.snap_targets(Some((trim.lane, trim.idx))); | 1506 | let marks = self.snap_targets(Some((trim.lane, trim.idx))); |
| 1451 | - let (at, cue) = self.snap_to(self.frame_under(x), 0, &marks); | 1507 | + // The same 10 px of aim a drop is given ([`DROP_SNAP_PX`]): one |
| 1508 | + // threshold for every gesture on this bed, so an edge and a whole clip | ||
| 1509 | + // grip a cut at the same distance from it. | ||
| 1510 | + let (at, cue) = snap_cue( | ||
| 1511 | + self.snap_live(), | ||
| 1512 | + self.frame_under(x), | ||
| 1513 | + 0, | ||
| 1514 | + self.drop_snap_frames(), | ||
| 1515 | + &marks, | ||
| 1516 | + ); | ||
| 1452 | let Some((lo, hi)) = self.session.as_ref().and_then(|session| { | 1517 | let Some((lo, hi)) = self.session.as_ref().and_then(|session| { |
| 1453 | match trim.lane.kind == LaneKind::Subtitle { | 1518 | match trim.lane.kind == LaneKind::Subtitle { |
| 1454 | // The walls a caption's edge has -- its neighbour, its own | 1519 | // The walls a caption's edge has -- its neighbour, its own |
| @@ -2005,7 +2070,10 @@ impl Player { | |||
| 2005 | // outside the window, still owing its one edit. | 2070 | // outside the window, still owing its one edit. |
| 2006 | if self.trim.is_some() { | 2071 | if self.trim.is_some() { |
| 2007 | match event.pressed_button { | 2072 | match event.pressed_button { |
| 2008 | - Some(MouseButton::Left) => self.trim_to(event.position.x, cx), | 2073 | + Some(MouseButton::Left) => { |
| 2074 | + self.drag_alt = event.modifiers.alt; | ||
| 2075 | + self.trim_to(event.position.x, cx); | ||
| 2076 | + } | ||
| 2009 | _ => self.commit_trim(cx), | 2077 | _ => self.commit_trim(cx), |
| 2010 | } | 2078 | } |
| 2011 | return; | 2079 | return; |
| @@ -2131,6 +2199,7 @@ impl Player { | |||
| 2131 | if self.trim.is_some() { | 2199 | if self.trim.is_some() { |
| 2132 | // The release lands exactly, then the gesture is | 2200 | // The release lands exactly, then the gesture is |
| 2133 | // written once -- one edit, one undo step. | 2201 | // written once -- one edit, one undo step. |
| 2202 | + self.drag_alt = event.modifiers.alt; | ||
| 2134 | self.trim_to(event.position.x, cx); | 2203 | self.trim_to(event.position.x, cx); |
| 2135 | self.commit_trim(cx); | 2204 | self.commit_trim(cx); |
| 2136 | return; | 2205 | return; |
crates/app/src/tests/editing.rsmodified+5 -2
| @@ -1670,9 +1670,12 @@ fn a_row_dropped_on_the_open_bed_lands_under_the_pointer() { | |||
| 1670 | // bed: ten seconds in, five seconds past the end of the timeline, and | 1670 | // bed: ten seconds in, five seconds past the end of the timeline, and |
| 1671 | // no mark anywhere near enough to pull it back. | 1671 | // no mark anywhere near enough to pull it back. |
| 1672 | let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)]; | 1672 | let clips = [session.lane_clips(Lane::V1), session.lane_clips(Lane::A1)]; |
| 1673 | - let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps)); | 1673 | + let marks = snap_marks(&clips, None, None, frame_at(session.now(), fps), None); |
| 1674 | let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps); | 1674 | let under = frame_at(scale.time_at(px_along(px(212.), bed)), fps); |
| 1675 | - let (at, cue) = landing(under, 0, 0, true, scale.snap_frames(fps), &marks); | 1675 | + // The drop's own magnet, not the trims' finer one -- `Player::place_frame` |
| 1676 | + // ships `drop_snap_frames`, and a test computing with `snap_frames` stops | ||
| 1677 | + // mirroring production the moment the two differ. | ||
| 1678 | + let (at, cue) = landing(under, 0, 0, true, scale.drop_snap_frames(fps), &marks); | ||
| 1676 | assert_eq!((at, cue), (300, None), "the pointer is on frame 300"); | 1679 | assert_eq!((at, cue), (300, None), "the pointer is on frame 300"); |
| 1677 | 1680 | ||
| 1678 | // ...and what the release does with it: the frame back through the same | 1681 | // ...and what the release does with it: the frame back through the same |
crates/app/src/tests/layout.rsmodified+1 -1
| @@ -3072,7 +3072,7 @@ fn the_bench_seam_stops_at_its_floor_and_its_ceiling() { | |||
| 3072 | /// DESIGN §7: "lanes scroll behind the pinned ruler and track heads" -- pinned | 3072 | /// DESIGN §7: "lanes scroll behind the pinned ruler and track heads" -- pinned |
| 3073 | /// means pinned. A clip that starts left of the view sits at a negative `left` | 3073 | /// means pinned. A clip that starts left of the view sits at a negative `left` |
| 3074 | /// inside its bed, and with no clip mask gpui paints it (and its hitbox) over | 3074 | /// inside its bed, and with no clip mask gpui paints it (and its hitbox) over |
| 3075 | -/// the 72 px head column, so V1/A1 and their verbs disappear under the first | 3075 | +/// the `HEAD_W` px head column, so V1/A1 and their verbs disappear under the first |
| 3076 | /// take as soon as the bench is wheeled past frame 0. The mask belongs on the | 3076 | /// take as soon as the bench is wheeled past frame 0. The mask belongs on the |
| 3077 | /// bed itself so a half-scrolled clip still drags on the half that shows. | 3077 | /// bed itself so a half-scrolled clip still drags on the half that shows. |
| 3078 | #[test] | 3078 | #[test] |
crates/app/src/tests/view.rsmodified+3 -3
| @@ -175,7 +175,7 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { | |||
| 175 | let lanes: [&[Clip]; 2] = [&video, &audio]; | 175 | let lanes: [&[Clip]; 2] = [&video, &audio]; |
| 176 | 176 | ||
| 177 | // Nothing in the hand: both lanes' edges, the playhead, and 0. | 177 | // Nothing in the hand: both lanes' edges, the playhead, and 0. |
| 178 | - let mut all = snap_marks(&lanes, None, None, 300); | 178 | + let mut all = snap_marks(&lanes, None, None, 300, None); |
| 179 | all.sort_unstable(); | 179 | all.sort_unstable(); |
| 180 | assert_eq!(all, [0, 100, 100, 160, 160, 300, 400, 430]); | 180 | assert_eq!(all, [0, 100, 100, 160, 160, 300, 400, 430]); |
| 181 | 181 | ||
| @@ -184,12 +184,12 @@ fn the_marks_are_every_lane_the_playhead_and_the_start() { | |||
| 184 | // other lane -- both boxes travel with the drag. The lone audio clip is | 184 | // other lane -- both boxes travel with the drag. The lone audio clip is |
| 185 | // still a target, which is the whole point: a take being carried on V1 | 185 | // still a target, which is the whole point: a take being carried on V1 |
| 186 | // lands flush with a sound on A1. | 186 | // lands flush with a sound on A1. |
| 187 | - let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300); | 187 | + let mut carried = snap_marks(&lanes, Some((0, 0)), Some(7), 300, None); |
| 188 | carried.sort_unstable(); | 188 | carried.sort_unstable(); |
| 189 | assert_eq!(carried, [0, 300, 400, 430]); | 189 | assert_eq!(carried, [0, 300, 400, 430]); |
| 190 | 190 | ||
| 191 | // An index that names no clip skips nothing and still answers. | 191 | // An index that names no clip skips nothing and still answers. |
| 192 | - assert_eq!(snap_marks(&[], Some((3, 9)), None, 0), [0, 0]); | 192 | + assert_eq!(snap_marks(&[], Some((3, 9)), None, 0, None), [0, 0]); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | /// The line the bed draws, and the switch that turns the whole thing off. | 195 | /// The line the bed draws, and the switch that turns the whole thing off. |
crates/app/src/timeline_math.rsmodified+237 -2
| @@ -583,6 +583,7 @@ pub(crate) fn snap_marks( | |||
| 583 | skip: Option<(usize, usize)>, | 583 | skip: Option<(usize, usize)>, |
| 584 | skip_link: Option<u32>, | 584 | skip_link: Option<u32>, |
| 585 | playhead: u32, | 585 | playhead: u32, |
| 586 | + range: Option<(u32, u32)>, | ||
| 586 | ) -> Vec<u32> { | 587 | ) -> Vec<u32> { |
| 587 | let mut marks: Vec<u32> = lanes | 588 | let mut marks: Vec<u32> = lanes |
| 588 | .iter() | 589 | .iter() |
| @@ -599,6 +600,13 @@ pub(crate) fn snap_marks( | |||
| 599 | .collect(); | 600 | .collect(); |
| 600 | marks.push(playhead); | 601 | marks.push(playhead); |
| 601 | marks.push(0); | 602 | marks.push(0); |
| 603 | + // The in and out points ([`Player::range`]): a hand that has marked a | ||
| 604 | + // stretch is working to it, and a clip meets its brackets as readily as it | ||
| 605 | + // meets a cut. | ||
| 606 | + if let Some((in_, out)) = range { | ||
| 607 | + marks.push(in_); | ||
| 608 | + marks.push(out); | ||
| 609 | + } | ||
| 602 | marks | 610 | marks |
| 603 | } | 611 | } |
| 604 | 612 | ||
| @@ -626,6 +634,15 @@ pub(crate) fn snap_cue( | |||
| 626 | (start, mark) | 634 | (start, mark) |
| 627 | } | 635 | } |
| 628 | 636 | ||
| 637 | +/// Whether the magnet is on for the gesture in flight: the switch, unless | ||
| 638 | +/// `alt` is held -- the temporary override Resolve, Premiere and Final Cut all | ||
| 639 | +/// put on that key, off for this one drag and leaving the switch where the hand | ||
| 640 | +/// left it. [`Player::snap_live`]'s whole rule, here so it can be read without | ||
| 641 | +/// a window. | ||
| 642 | +pub(crate) fn snap_live(on: bool, alt: bool) -> bool { | ||
| 643 | + on && !alt | ||
| 644 | +} | ||
| 645 | + | ||
| 629 | /// Where a drag lands and the mark that pulled it there: the frame under the | 646 | /// Where a drag lands and the mark that pulled it there: the frame under the |
| 630 | /// pointer, less however far into the box the hand grabbed it (so a clip travels | 647 | /// pointer, less however far into the box the hand grabbed it (so a clip travels |
| 631 | /// with the pointer rather than jumping its head under it), snapped by | 648 | /// with the pointer rather than jumping its head under it), snapped by |
| @@ -644,6 +661,70 @@ pub(crate) fn landing( | |||
| 644 | snap_cue(on, under.saturating_sub(grab), len, tol, marks) | 661 | snap_cue(on, under.saturating_sub(grab), len, tol, marks) |
| 645 | } | 662 | } |
| 646 | 663 | ||
| 664 | +/// Where a clip `len` frames long, let go over *another* lane with its head | ||
| 665 | +/// asked at `at`, really comes to rest -- `None` when the engine refuses the | ||
| 666 | +/// drop outright. A mirror of [`Project::move_room`]: the release is refused | ||
| 667 | +/// only when the asked head sits *inside* a take already there (a clamp has no | ||
| 668 | +/// answer for that), or when the gap it names is narrower than the clip; | ||
| 669 | +/// otherwise the head is clamped into that gap exactly as a same-lane move is | ||
| 670 | +/// ([`gap_clamp`]). `others` is `(start, end)` of every clip already on the | ||
| 671 | +/// destination lane, less the ones travelling with this one. | ||
| 672 | +/// | ||
| 673 | +/// The shadow reads this, so a landing the release *will* make is never drawn | ||
| 674 | +/// as refused -- a whole-span overlap test refuses far more than the engine | ||
| 675 | +/// does, and a shadow that lies about a refusal reads as a broken timeline. | ||
| 676 | +pub(crate) fn cross_room(at: u32, len: u32, others: &[(u32, u32)]) -> Option<u32> { | ||
| 677 | + let (mut lo, mut hi) = (0, u32::MAX); | ||
| 678 | + for &(other_start, other_end) in others { | ||
| 679 | + if other_start <= at && at < other_end { | ||
| 680 | + return None; | ||
| 681 | + } | ||
| 682 | + match other_end <= at { | ||
| 683 | + true => lo = lo.max(other_end), | ||
| 684 | + false => hi = hi.min(other_start), | ||
| 685 | + } | ||
| 686 | + } | ||
| 687 | + match hi - lo < len { | ||
| 688 | + true => None, | ||
| 689 | + false => Some(at.clamp(lo, hi - len)), | ||
| 690 | + } | ||
| 691 | +} | ||
| 692 | + | ||
| 693 | +/// Where a clip staying on its own lane really comes to rest: `want`, clamped | ||
| 694 | +/// into the gap it is sitting in -- the take behind it and the take in front of | ||
| 695 | +/// it are walls ([`Project::move_selection`] clamps the delta by exactly these, | ||
| 696 | +/// it does not refuse), so a clip dragged hard left past its neighbour lands | ||
| 697 | +/// flush against that neighbour's tail rather than nowhere. `now` is its head | ||
| 698 | +/// today, which is what names the gap. The shadow reads this, so the box drawn | ||
| 699 | +/// in flight is the box the release leaves behind. | ||
| 700 | +pub(crate) fn gap_clamp(now: u32, len: u32, want: u32, others: &[(u32, u32)]) -> u32 { | ||
| 701 | + let lo = others | ||
| 702 | + .iter() | ||
| 703 | + .filter(|&&(_, end)| end <= now) | ||
| 704 | + .map(|&(_, end)| end) | ||
| 705 | + .max() | ||
| 706 | + .unwrap_or(0); | ||
| 707 | + let hi = others | ||
| 708 | + .iter() | ||
| 709 | + .filter(|&&(start, _)| start >= now.saturating_add(len)) | ||
| 710 | + .map(|&(start, _)| start) | ||
| 711 | + .min() | ||
| 712 | + .unwrap_or(u32::MAX); | ||
| 713 | + want.clamp(lo, hi.saturating_sub(len).max(lo)) | ||
| 714 | +} | ||
| 715 | + | ||
| 716 | +/// The lane a release lands on when the pointer is off the rows themselves: | ||
| 717 | +/// the row under it while its kind can hold what is in the hand, and otherwise | ||
| 718 | +/// the last one that could -- a picture clip carried down across A1 on its way | ||
| 719 | +/// to the empty bench below is still aiming at V1. [`Player::drag_lane`]'s | ||
| 720 | +/// whole rule. | ||
| 721 | +pub(crate) fn held_lane(prev: Option<Lane>, over: Lane, from: Lane) -> Option<Lane> { | ||
| 722 | + match over.kind == from.kind { | ||
| 723 | + true => Some(over), | ||
| 724 | + false => prev, | ||
| 725 | + } | ||
| 726 | +} | ||
| 727 | + | ||
| 647 | /// Why this file may not go on that lane, in the words the refusal is told in -- | 728 | /// Why this file may not go on that lane, in the words the refusal is told in -- |
| 648 | /// `None` when it may. A file with no picture belongs on an audio lane and | 729 | /// `None` when it may. A file with no picture belongs on an audio lane and |
| 649 | /// nowhere else, and a still is silent, so an audio lane is the one place it | 730 | /// nowhere else, and a still is silent, so an audio lane is the one place it |
| @@ -697,7 +778,7 @@ mod drop_landing_tests { | |||
| 697 | /// missing mark. | 778 | /// missing mark. |
| 698 | #[test] | 779 | #[test] |
| 699 | fn a_pull_near_the_head_of_an_empty_timeline_snaps_to_frame_0() { | 780 | fn a_pull_near_the_head_of_an_empty_timeline_snaps_to_frame_0() { |
| 700 | - let marks = snap_marks(&[&[]], None, None, 0); | 781 | + let marks = snap_marks(&[&[]], None, None, 0, None); |
| 701 | assert!(marks.contains(&0), "an empty timeline still offers frame 0"); | 782 | assert!(marks.contains(&0), "an empty timeline still offers frame 0"); |
| 702 | assert_eq!(snapped(4, 0, 10, &marks), 0); | 783 | assert_eq!(snapped(4, 0, 10, &marks), 0); |
| 703 | // Outside the tolerance, the raw ask stands: this is a magnet, not a | 784 | // Outside the tolerance, the raw ask stands: this is a magnet, not a |
| @@ -719,8 +800,162 @@ mod drop_landing_tests { | |||
| 719 | /// where the timeline is parked. | 800 | /// where the timeline is parked. |
| 720 | #[test] | 801 | #[test] |
| 721 | fn a_pull_near_the_playhead_snaps_onto_it() { | 802 | fn a_pull_near_the_playhead_snaps_onto_it() { |
| 722 | - let marks = snap_marks(&[&[]], None, None, 500); | 803 | + let marks = snap_marks(&[&[]], None, None, 500, None); |
| 723 | assert!(marks.contains(&500)); | 804 | assert!(marks.contains(&500)); |
| 724 | assert_eq!(snapped(493, 0, 10, &marks), 500); | 805 | assert_eq!(snapped(493, 0, 10, &marks), 500); |
| 725 | } | 806 | } |
| 807 | + | ||
| 808 | + /// The user's own repro: a clip dragged left through the lane-head column | ||
| 809 | + /// -- window x *left of the bed* -- lands on frame 0 rather than nowhere. | ||
| 810 | + /// Two clamps do it, and both are on the path the bench now takes for a | ||
| 811 | + /// drop over the head ([`Player::frame_under`]): [`px_along`] pins an x | ||
| 812 | + /// before the bed's left edge to 0 px, [`Scale::time_at`] pins the moment | ||
| 813 | + /// to 0 s, and the grab offset comes off with a saturating subtraction, so | ||
| 814 | + /// even a clip held by its tail cannot ask for a negative frame. | ||
| 815 | + #[test] | ||
| 816 | + fn a_drag_out_over_the_lane_head_lands_on_frame_0() { | ||
| 817 | + let bed = Bounds { | ||
| 818 | + origin: point(px(100.), px(0.)), | ||
| 819 | + size: size(px(900.), px(60.)), | ||
| 820 | + }; | ||
| 821 | + let scale = Scale::default(); | ||
| 822 | + // 40 px into the head column, and off the window entirely. | ||
| 823 | + for x in [px(60.), px(-400.)] { | ||
| 824 | + assert_eq!(px_along(x, bed), 0.); | ||
| 825 | + let under = frame_at(scale.time_at(px_along(x, bed)), 25.); | ||
| 826 | + assert_eq!(under, 0); | ||
| 827 | + // Grabbed 30 frames into the box: still frame 0, never a refusal. | ||
| 828 | + assert_eq!(landing(under, 30, 50, true, 10, &[0, 300]), (0, Some(0))); | ||
| 829 | + } | ||
| 830 | + } | ||
| 831 | + | ||
| 832 | + /// Both edges of the clip in the hand are candidates and the nearest one | ||
| 833 | + /// wins: a tail 2 frames short of a neighbour's head beats a head 8 frames | ||
| 834 | + /// from the timeline's start. | ||
| 835 | + #[test] | ||
| 836 | + fn the_nearer_of_the_two_edges_wins() { | ||
| 837 | + let marks = [0, 300, 500]; | ||
| 838 | + // len 292: the tail wants 300 (2 away), the head 0 (8 away). | ||
| 839 | + // The tail already sits exactly on 300, so the head is left alone. | ||
| 840 | + assert_eq!(snapped(8, 292, 10, &marks), 8); | ||
| 841 | + assert_eq!(snapped(6, 292, 10, &marks), 8, "tail meets 300, head stays"); | ||
| 842 | + } | ||
| 843 | + | ||
| 844 | + /// The threshold is a distance on *screen*: the same 10 px of aim at two | ||
| 845 | + /// zooms is a different number of frames, which is what makes the magnet | ||
| 846 | + /// feel identical zoomed in and zoomed out ([`Scale::drop_snap_frames`]). | ||
| 847 | + /// Outside it the drag follows the pointer exactly. | ||
| 848 | + #[test] | ||
| 849 | + fn the_threshold_is_ten_pixels_at_any_zoom() { | ||
| 850 | + let fps = 25.; | ||
| 851 | + for pps in [50., 400.] { | ||
| 852 | + let scale = Scale { pps, start: 0. }; | ||
| 853 | + let tol = scale.drop_snap_frames(fps); | ||
| 854 | + // 10 px worth of frames, and one frame more than that is not near. | ||
| 855 | + let near = (DROP_SNAP_PX / pps * fps) as u32; | ||
| 856 | + assert_eq!(tol, near); | ||
| 857 | + assert_eq!(snapped(500 + tol, 0, tol, &[500]), 500); | ||
| 858 | + assert_eq!( | ||
| 859 | + snapped(500 + tol + 1, 0, tol, &[500]), | ||
| 860 | + 500 + tol + 1, | ||
| 861 | + "past the window the pointer is obeyed exactly" | ||
| 862 | + ); | ||
| 863 | + } | ||
| 864 | + } | ||
| 865 | + | ||
| 866 | + /// `alt` held turns the magnet off for the gesture and nothing else: the | ||
| 867 | + /// same raw ask, no line, and [`Player::snap`] itself untouched. | ||
| 868 | + #[test] | ||
| 869 | + fn alt_turns_the_magnet_off_for_this_drag_only() { | ||
| 870 | + let on = true; | ||
| 871 | + assert!(snap_live(on, false)); | ||
| 872 | + assert!(!snap_live(on, true)); | ||
| 873 | + let marks = [0, 300]; | ||
| 874 | + assert_eq!( | ||
| 875 | + snap_cue(snap_live(on, true), 297, 0, 10, &marks), | ||
| 876 | + (297, None) | ||
| 877 | + ); | ||
| 878 | + assert_eq!(snap_cue(snap_live(on, false), 297, 0, 10, &marks), (300, Some(300))); | ||
| 879 | + // The switch off stays off however the modifier is held. | ||
| 880 | + assert!(!snap_live(false, false)); | ||
| 881 | + } | ||
| 882 | + | ||
| 883 | + /// Every target an NLE offers is on the list: frame 0, the playhead, both | ||
| 884 | + /// edges of every clip on *every* lane, and the in/out brackets. | ||
| 885 | + #[test] | ||
| 886 | + fn the_targets_are_zero_the_playhead_the_edges_and_the_marks() { | ||
| 887 | + let clip = |start: u32, frames: u32| Clip { | ||
| 888 | + fade_in: 0, | ||
| 889 | + fade_out: 0, | ||
| 890 | + transition_out: 0, | ||
| 891 | + start, | ||
| 892 | + in_frame: 0, | ||
| 893 | + out_frame: frames, | ||
| 894 | + source: 0, | ||
| 895 | + link: None, | ||
| 896 | + eq: None, | ||
| 897 | + color: None, | ||
| 898 | + transform: None, | ||
| 899 | + fit: Default::default(), | ||
| 900 | + speed: Default::default(), | ||
| 901 | + }; | ||
| 902 | + let v1 = [clip(100, 50), clip(400, 50)]; | ||
| 903 | + let a1 = [clip(700, 20)]; | ||
| 904 | + let marks = snap_marks(&[&v1, &a1], None, None, 900, Some((250, 600))); | ||
| 905 | + for want in [0, 900, 100, 150, 400, 450, 700, 720, 250, 600] { | ||
| 906 | + assert!(marks.contains(&want), "{want} is not a snap target"); | ||
| 907 | + } | ||
| 908 | + // And each of them actually pulls a drag onto itself. | ||
| 909 | + for target in [0, 250, 600, 900] { | ||
| 910 | + assert_eq!(snapped(target + 4, 0, 10, &marks), target); | ||
| 911 | + } | ||
| 912 | + } | ||
| 913 | + | ||
| 914 | + /// A release on the empty bench below the last row, or left of the heads, | ||
| 915 | + /// lands on the lane the last live sample was over -- and a lane of the | ||
| 916 | + /// wrong kind crossed on the way down never steals it. | ||
| 917 | + #[test] | ||
| 918 | + fn the_last_lane_that_could_hold_it_keeps_the_drag() { | ||
| 919 | + let v1 = Lane::V1; | ||
| 920 | + let v2 = Lane::new(LaneKind::Video, 1); | ||
| 921 | + let a1 = Lane::A1; | ||
| 922 | + // The head column is part of the row, so the row over it is the answer. | ||
| 923 | + assert_eq!(held_lane(None, v1, v1), Some(v1)); | ||
| 924 | + assert_eq!(held_lane(Some(v1), v2, v1), Some(v2)); | ||
| 925 | + assert_eq!(held_lane(Some(v2), a1, v1), Some(v2), "audio cannot hold it"); | ||
| 926 | + // Nothing promised yet and nothing that can hold it: no landing. | ||
| 927 | + assert_eq!(held_lane(None, a1, v1), None); | ||
| 928 | + } | ||
| 929 | + | ||
| 930 | + /// A clip dragged hard left past the take in front of it comes to rest | ||
| 931 | + /// flush against that take -- the walls of its own gap, which is what the | ||
| 932 | + /// engine clamps the drag by -- and one dragged off the head of the | ||
| 933 | + /// timeline rests on frame 0. | ||
| 934 | + #[test] | ||
| 935 | + fn a_drag_past_a_neighbour_rests_flush_against_it() { | ||
| 936 | + let others = [(0, 375), (900, 1000)]; | ||
| 937 | + assert_eq!(gap_clamp(375, 500, 0, &others), 375, "flush with its tail"); | ||
| 938 | + assert_eq!(gap_clamp(375, 500, 380, &others), 380, "room to spare"); | ||
| 939 | + assert_eq!(gap_clamp(375, 500, 800, &others), 400, "flush with the next"); | ||
| 940 | + // An empty lane clamps at the head of the timeline and nowhere else. | ||
| 941 | + assert_eq!(gap_clamp(500, 100, 0, &[]), 0); | ||
| 942 | + assert_eq!(gap_clamp(500, 100, 9_000, &[]), 9_000); | ||
| 943 | + } | ||
| 944 | + | ||
| 945 | + /// The cross-lane shadow's rule, mirroring the engine: refused only when | ||
| 946 | + /// the asked head is inside a take or the gap is too narrow, and otherwise | ||
| 947 | + /// clamped into the gap rather than refused. The middle case is the | ||
| 948 | + /// verifier's repro -- an obstacle at (360, 420), a 90-frame clip asked at | ||
| 949 | + /// 315, which the engine lands at 270. | ||
| 950 | + #[test] | ||
| 951 | + fn a_cross_lane_landing_clamps_into_the_gap_the_engine_leaves() { | ||
| 952 | + let others = [(360, 420)]; | ||
| 953 | + assert_eq!(cross_room(315, 90, &others), Some(270), "clamped, not refused"); | ||
| 954 | + assert_eq!(cross_room(380, 90, &others), None, "head inside the take"); | ||
| 955 | + assert_eq!(cross_room(100, 90, &others), Some(100), "room to spare"); | ||
| 956 | + let tight = [(0, 100), (150, 300)]; | ||
| 957 | + assert_eq!(cross_room(120, 90, &tight), None, "the gap is 50 frames wide"); | ||
| 958 | + assert_eq!(cross_room(120, 50, &tight), Some(100), "and holds a 50-frame clip"); | ||
| 959 | + assert_eq!(cross_room(500, 90, &[]), Some(500), "an empty lane takes it as asked"); | ||
| 960 | + } | ||
| 726 | } | 961 | } |
crates/app/src/ui/bench_stance.rsmodified+206 -87
| @@ -328,7 +328,19 @@ fn clip_box( | |||
| 328 | }, | 328 | }, |
| 329 | { | 329 | { |
| 330 | let ghost = ghost.clone(); | 330 | let ghost = ghost.clone(); |
| 331 | - move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) | 331 | + let me = cx.entity(); |
| 332 | + move |_, _, _, cx| { | ||
| 333 | + // A fresh gesture inherits nothing: `Player::drag_lane` | ||
| 334 | + // and `Player::drag_x` are the *last live sample* of the | ||
| 335 | + // drag being made, and a drag whose first sample lands | ||
| 336 | + // outside every row would otherwise be let go onto the | ||
| 337 | + // lane the previous one ended over. | ||
| 338 | + me.update(cx, |this, _| { | ||
| 339 | + this.drag_lane = None; | ||
| 340 | + this.drag_x = None; | ||
| 341 | + }); | ||
| 342 | + cx.new(|_| Tip(ghost.clone())) | ||
| 343 | + } | ||
| 332 | }, | 344 | }, |
| 333 | ) | 345 | ) |
| 334 | .tooltip(crate::ui::widgets::tip_hover("Clip", "drag to move", None)) | 346 | .tooltip(crate::ui::widgets::tip_hover("Clip", "drag to move", None)) |
| @@ -717,7 +729,19 @@ fn sub_box( | |||
| 717 | }, | 729 | }, |
| 718 | { | 730 | { |
| 719 | let ghost = ghost.clone(); | 731 | let ghost = ghost.clone(); |
| 720 | - move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) | 732 | + let me = cx.entity(); |
| 733 | + move |_, _, _, cx| { | ||
| 734 | + // A fresh gesture inherits nothing: `Player::drag_lane` | ||
| 735 | + // and `Player::drag_x` are the *last live sample* of the | ||
| 736 | + // drag being made, and a drag whose first sample lands | ||
| 737 | + // outside every row would otherwise be let go onto the | ||
| 738 | + // lane the previous one ended over. | ||
| 739 | + me.update(cx, |this, _| { | ||
| 740 | + this.drag_lane = None; | ||
| 741 | + this.drag_x = None; | ||
| 742 | + }); | ||
| 743 | + cx.new(|_| Tip(ghost.clone())) | ||
| 744 | + } | ||
| 721 | }, | 745 | }, |
| 722 | ) | 746 | ) |
| 723 | .tooltip(crate::ui::widgets::tip_hover("Subtitle", "drag to move", None)) | 747 | .tooltip(crate::ui::widgets::tip_hover("Subtitle", "drag to move", None)) |
| @@ -877,6 +901,116 @@ fn lane_row( | |||
| 877 | this.preview_lane_drop(event.drag(cx).0, lane, cx); | 901 | this.preview_lane_drop(event.drag(cx).0, lane, cx); |
| 878 | }), | 902 | }), |
| 879 | ) | 903 | ) |
| 904 | + .drag_over::<AssetDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 905 | + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { | ||
| 906 | + this.drag_alt = window.modifiers().alt; | ||
| 907 | + let x = this | ||
| 908 | + .drag_x | ||
| 909 | + .take() | ||
| 910 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 911 | + let at = this.place_frame(x).0; | ||
| 912 | + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) | ||
| 913 | + })) | ||
| 914 | + // The landing shadow (`Player::preview_ghost_asset`, the same | ||
| 915 | + // setter `ui/timeline.rs`'s own bed calls) -- guarded on the | ||
| 916 | + // pointer actually being inside this *row's* bounds, since | ||
| 917 | + // `on_drag_move` fires on every painted element of the drag's | ||
| 918 | + // type, not just the one under the pointer. The row and not the | ||
| 919 | + // bed: the head column is `HEAD_W` px of this lane too, and a clip | ||
| 920 | + // dragged out over it is aiming at frame 0 -- the drop it used to | ||
| 921 | + // fall through (nothing under the pointer answered `ClipDrag`) is | ||
| 922 | + // the "I have to be pixel perfect to snap to 0" complaint. | ||
| 923 | + // `Player::frame_under` clamps an x left of the bed to the head of | ||
| 924 | + // the view (`px_along`), so the head column reads as frame 0. | ||
| 925 | + .on_drag_move( | ||
| 926 | + cx.listener(move |this, event: &DragMoveEvent<AssetDrag>, _, cx| { | ||
| 927 | + if !event.bounds.contains(&event.event.position) { | ||
| 928 | + return; | ||
| 929 | + } | ||
| 930 | + let path = event.drag(cx).0.clone(); | ||
| 931 | + this.drag_x = Some(event.event.position.x); | ||
| 932 | + // The row the catch-all release below aims at. A file's own | ||
| 933 | + // kind is not known until the engine has placed it, so the | ||
| 934 | + // last row hovered is the answer and `Player::insert_source` | ||
| 935 | + // words the refusal if it cannot hold this file. | ||
| 936 | + this.drag_lane = Some(lane); | ||
| 937 | + this.drag_alt = event.event.modifiers.alt; | ||
| 938 | + this.preview_ghost_asset(&path, lane, event.event.position.x, cx); | ||
| 939 | + }), | ||
| 940 | + ) | ||
| 941 | + .drag_over::<ClipDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 942 | + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { | ||
| 943 | + this.drag_alt = window.modifiers().alt; | ||
| 944 | + let Some(idx) = this.dragged(drag) else { | ||
| 945 | + return; | ||
| 946 | + }; | ||
| 947 | + let x = this | ||
| 948 | + .drag_x | ||
| 949 | + .take() | ||
| 950 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 951 | + this.move_clip(drag.lane, idx, lane, x, cx) | ||
| 952 | + })) | ||
| 953 | + .on_drag_move( | ||
| 954 | + cx.listener(move |this, event: &DragMoveEvent<ClipDrag>, _, cx| { | ||
| 955 | + if !event.bounds.contains(&event.event.position) { | ||
| 956 | + return; | ||
| 957 | + } | ||
| 958 | + let drag = *event.drag(cx); | ||
| 959 | + this.drag_x = Some(event.event.position.x); | ||
| 960 | + // The last lane this clip could actually land on: a picture | ||
| 961 | + // clip dragged down across A1 on its way to the empty bench | ||
| 962 | + // below is still aiming at V1, and the catch-all release must | ||
| 963 | + // not hand it the audio lane that refused it on the way past. | ||
| 964 | + this.drag_lane = held_lane(this.drag_lane, lane, drag.lane); | ||
| 965 | + this.drag_alt = event.event.modifiers.alt; | ||
| 966 | + this.preview_ghost(&drag, lane, event.event.position.x, cx); | ||
| 967 | + }), | ||
| 968 | + ) | ||
| 969 | + // A caption already on a lane moves along it, or onto another | ||
| 970 | + // subtitle track, exactly as a clip does (`Player::move_sub`, | ||
| 971 | + // the same call `ui/timeline.rs`'s own bed makes). | ||
| 972 | + .drag_over::<SubDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 973 | + .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { | ||
| 974 | + this.drag_alt = window.modifiers().alt; | ||
| 975 | + let x = this | ||
| 976 | + .drag_x | ||
| 977 | + .take() | ||
| 978 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 979 | + this.move_sub(drag, lane, x, cx); | ||
| 980 | + })) | ||
| 981 | + .on_drag_move( | ||
| 982 | + cx.listener(move |this, event: &DragMoveEvent<SubDrag>, _, cx| { | ||
| 983 | + if !event.bounds.contains(&event.event.position) { | ||
| 984 | + return; | ||
| 985 | + } | ||
| 986 | + let drag = *event.drag(cx); | ||
| 987 | + this.drag_x = Some(event.event.position.x); | ||
| 988 | + this.drag_lane = held_lane(this.drag_lane, lane, drag.lane); | ||
| 989 | + this.drag_alt = event.event.modifiers.alt; | ||
| 990 | + this.preview_ghost_sub(&drag, lane, event.event.position.x, cx); | ||
| 991 | + }), | ||
| 992 | + ) | ||
| 993 | + .drag_over::<SubPick>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 994 | + .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { | ||
| 995 | + this.drag_alt = window.modifiers().alt; | ||
| 996 | + let x = this | ||
| 997 | + .drag_x | ||
| 998 | + .take() | ||
| 999 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 1000 | + this.place_sub(drag.0, lane, x, cx); | ||
| 1001 | + })) | ||
| 1002 | + .on_drag_move( | ||
| 1003 | + cx.listener(move |this, event: &DragMoveEvent<SubPick>, _, cx| { | ||
| 1004 | + if !event.bounds.contains(&event.event.position) { | ||
| 1005 | + return; | ||
| 1006 | + } | ||
| 1007 | + let track = event.drag(cx).0; | ||
| 1008 | + this.drag_x = Some(event.event.position.x); | ||
| 1009 | + this.drag_lane = Some(lane); | ||
| 1010 | + this.drag_alt = event.event.modifiers.alt; | ||
| 1011 | + this.preview_ghost_pick(track, lane, event.event.position.x, cx); | ||
| 1012 | + }), | ||
| 1013 | + ) | ||
| 880 | .child( | 1014 | .child( |
| 881 | // Pinned track head: its drag handle remains the lane label; verbs | 1015 | // Pinned track head: its drag handle remains the lane label; verbs |
| 882 | // stay separate pointer targets so a mix/remove click never starts | 1016 | // stay separate pointer targets so a mix/remove click never starts |
| @@ -993,7 +1127,7 @@ fn lane_row( | |||
| 993 | // DESIGN §7: the lanes scroll BEHIND the pinned heads. A | 1127 | // DESIGN §7: the lanes scroll BEHIND the pinned heads. A |
| 994 | // clip whose start is left of the view sits at a negative | 1128 | // clip whose start is left of the view sits at a negative |
| 995 | // `left`, and without a clip mask gpui paints it -- and its | 1129 | // `left`, and without a clip mask gpui paints it -- and its |
| 996 | - // hitbox -- straight over the 72px head column, so V1/A1 and | 1130 | + // hitbox -- straight over the `HEAD_W` px head column, so V1/A1 and |
| 997 | // their verbs vanish under it. The mask cuts painting and | 1131 | // their verbs vanish under it. The mask cuts painting and |
| 998 | // hit-testing at the bed's own edges together, so the visible | 1132 | // hit-testing at the bed's own edges together, so the visible |
| 999 | // half of a half-scrolled clip still drags and trims and the | 1133 | // half of a half-scrolled clip still drags and trims and the |
| @@ -1019,15 +1153,6 @@ fn lane_row( | |||
| 1019 | .h_full() | 1153 | .h_full() |
| 1020 | .bg(rgba(DARK_SEAM())), | 1154 | .bg(rgba(DARK_SEAM())), |
| 1021 | ) | 1155 | ) |
| 1022 | - .drag_over::<AssetDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 1023 | - .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { | ||
| 1024 | - let x = this | ||
| 1025 | - .drag_x | ||
| 1026 | - .take() | ||
| 1027 | - .unwrap_or_else(|| window.mouse_position().x); | ||
| 1028 | - let at = this.place_frame(x).0; | ||
| 1029 | - this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) | ||
| 1030 | - })) | ||
| 1031 | // Right-click on empty bed space: the "Close Gap" door. A | 1156 | // Right-click on empty bed space: the "Close Gap" door. A |
| 1032 | // clip's own right-click handler (`clip_box`/`sub_box`) never | 1157 | // clip's own right-click handler (`clip_box`/`sub_box`) never |
| 1033 | // stops propagation, so this fires on that press too -- | 1158 | // stops propagation, so this fires on that press too -- |
| @@ -1060,81 +1185,6 @@ fn lane_row( | |||
| 1060 | } | 1185 | } |
| 1061 | }), | 1186 | }), |
| 1062 | ) | 1187 | ) |
| 1063 | - // The landing shadow (`Player::preview_ghost_asset`, the same | ||
| 1064 | - // setter `ui/timeline.rs`'s own bed calls) -- guarded on the | ||
| 1065 | - // pointer actually being inside this bed's own bounds, since | ||
| 1066 | - // `on_drag_move` fires on every painted element of the drag's | ||
| 1067 | - // type, not just the one under the pointer. | ||
| 1068 | - .on_drag_move( | ||
| 1069 | - cx.listener(move |this, event: &DragMoveEvent<AssetDrag>, _, cx| { | ||
| 1070 | - if !event.bounds.contains(&event.event.position) { | ||
| 1071 | - return; | ||
| 1072 | - } | ||
| 1073 | - let path = event.drag(cx).0.clone(); | ||
| 1074 | - this.drag_x = Some(event.event.position.x); | ||
| 1075 | - this.preview_ghost_asset(&path, lane, event.event.position.x, cx); | ||
| 1076 | - }), | ||
| 1077 | - ) | ||
| 1078 | - .drag_over::<ClipDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 1079 | - .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { | ||
| 1080 | - let Some(idx) = this.dragged(drag) else { | ||
| 1081 | - return; | ||
| 1082 | - }; | ||
| 1083 | - let x = this | ||
| 1084 | - .drag_x | ||
| 1085 | - .take() | ||
| 1086 | - .unwrap_or_else(|| window.mouse_position().x); | ||
| 1087 | - this.move_clip(drag.lane, idx, lane, x, cx) | ||
| 1088 | - })) | ||
| 1089 | - .on_drag_move( | ||
| 1090 | - cx.listener(move |this, event: &DragMoveEvent<ClipDrag>, _, cx| { | ||
| 1091 | - if !event.bounds.contains(&event.event.position) { | ||
| 1092 | - return; | ||
| 1093 | - } | ||
| 1094 | - let drag = *event.drag(cx); | ||
| 1095 | - this.drag_x = Some(event.event.position.x); | ||
| 1096 | - this.preview_ghost(&drag, lane, event.event.position.x, cx); | ||
| 1097 | - }), | ||
| 1098 | - ) | ||
| 1099 | - // A caption already on a lane moves along it, or onto another | ||
| 1100 | - // subtitle track, exactly as a clip does (`Player::move_sub`, | ||
| 1101 | - // the same call `ui/timeline.rs`'s own bed makes). | ||
| 1102 | - .drag_over::<SubDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 1103 | - .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { | ||
| 1104 | - let x = this | ||
| 1105 | - .drag_x | ||
| 1106 | - .take() | ||
| 1107 | - .unwrap_or_else(|| window.mouse_position().x); | ||
| 1108 | - this.move_sub(drag, lane, x, cx); | ||
| 1109 | - })) | ||
| 1110 | - .on_drag_move( | ||
| 1111 | - cx.listener(move |this, event: &DragMoveEvent<SubDrag>, _, cx| { | ||
| 1112 | - if !event.bounds.contains(&event.event.position) { | ||
| 1113 | - return; | ||
| 1114 | - } | ||
| 1115 | - let drag = *event.drag(cx); | ||
| 1116 | - this.drag_x = Some(event.event.position.x); | ||
| 1117 | - this.preview_ghost_sub(&drag, lane, event.event.position.x, cx); | ||
| 1118 | - }), | ||
| 1119 | - ) | ||
| 1120 | - .drag_over::<SubPick>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 1121 | - .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { | ||
| 1122 | - let x = this | ||
| 1123 | - .drag_x | ||
| 1124 | - .take() | ||
| 1125 | - .unwrap_or_else(|| window.mouse_position().x); | ||
| 1126 | - this.place_sub(drag.0, lane, x, cx); | ||
| 1127 | - })) | ||
| 1128 | - .on_drag_move( | ||
| 1129 | - cx.listener(move |this, event: &DragMoveEvent<SubPick>, _, cx| { | ||
| 1130 | - if !event.bounds.contains(&event.event.position) { | ||
| 1131 | - return; | ||
| 1132 | - } | ||
| 1133 | - let track = event.drag(cx).0; | ||
| 1134 | - this.drag_x = Some(event.event.position.x); | ||
| 1135 | - this.preview_ghost_pick(track, lane, event.event.position.x, cx); | ||
| 1136 | - }), | ||
| 1137 | - ) | ||
| 1138 | .tooltip(crate::ui::widgets::tip_hover("Lane bed", "drop media here", None)) | 1188 | .tooltip(crate::ui::widgets::tip_hover("Lane bed", "drop media here", None)) |
| 1139 | .children(hitmap::dynamic( | 1189 | .children(hitmap::dynamic( |
| 1140 | move || { | 1190 | move || { |
| @@ -1210,6 +1260,9 @@ fn lane_row( | |||
| 1210 | 1260 | ||
| 1211 | /// The bench's content: pinned ruler, pinned heads, lane stack -- compressed | 1261 | /// The bench's content: pinned ruler, pinned heads, lane stack -- compressed |
| 1212 | /// evenly to [`LANES_COMPRESS`] rows and then scrolling (DESIGN §7). | 1262 | /// evenly to [`LANES_COMPRESS`] rows and then scrolling (DESIGN §7). |
| 1263 | +/// The bench's side gutter, spent inside [`render`]'s own content box. | ||
| 1264 | +const BENCH_GUTTER: f32 = 12.; | ||
| 1265 | + | ||
| 1213 | pub(crate) fn render( | 1266 | pub(crate) fn render( |
| 1214 | player: &mut Player, | 1267 | player: &mut Player, |
| 1215 | box_h: f32, | 1268 | box_h: f32, |
| @@ -1273,6 +1326,72 @@ pub(crate) fn render( | |||
| 1273 | .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { | 1326 | .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { |
| 1274 | this.timeline_wheel(event, cx); | 1327 | this.timeline_wheel(event, cx); |
| 1275 | })) | 1328 | })) |
| 1329 | + // The bench's side gutter, spent here rather than by the `bench` div | ||
| 1330 | + // above, so this element's bounds -- and the catch-all release below | ||
| 1331 | + // with them -- reach the window edge (note at `ui::stance::bench`). | ||
| 1332 | + .px(px(BENCH_GUTTER)) | ||
| 1333 | + // The catch-all release: a clip let go of anywhere on the bench that is | ||
| 1334 | + // not a lane row -- left of the tracks, in the gap between two rows, on | ||
| 1335 | + // the empty bench below the last one -- lands on the lane and the x the | ||
| 1336 | + // last live sample of that same drag was over (`Player::drag_lane`, | ||
| 1337 | + // `Player::drag_x`), which is exactly what the shadow was drawn at. A | ||
| 1338 | + // release that reaches no drop target at all is the one thing a drag | ||
| 1339 | + // may never do: a hand that has aimed a clip and let go has made an | ||
| 1340 | + // edit, and "nothing happened" is not one of the answers an editor | ||
| 1341 | + // accepts. A row's own listener stops propagation when it answers, so | ||
| 1342 | + // this only ever runs when none did -- and it would answer with the | ||
| 1343 | + // same frame if it did run, since both read the one sample. | ||
| 1344 | + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { | ||
| 1345 | + let (Some(lane), Some(idx)) = (this.drag_lane, this.dragged(drag)) else { | ||
| 1346 | + return; | ||
| 1347 | + }; | ||
| 1348 | + let x = this | ||
| 1349 | + .drag_x | ||
| 1350 | + .take() | ||
| 1351 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 1352 | + this.drag_alt = window.modifiers().alt; | ||
| 1353 | + this.move_clip(drag.lane, idx, lane, x, cx); | ||
| 1354 | + })) | ||
| 1355 | + // The same catch-all for the other three things a hand can be holding | ||
| 1356 | + // over the bench -- a library row, a caption already down, a palette | ||
| 1357 | + // row. Each lands on the lane its last live sample was over, through | ||
| 1358 | + // the very door that row's own release uses, so the engine words the | ||
| 1359 | + // refusal when that lane cannot hold it. Without these, letting one go | ||
| 1360 | + // off the rows reached nothing at all. | ||
| 1361 | + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { | ||
| 1362 | + let Some(lane) = this.drag_lane else { | ||
| 1363 | + return; | ||
| 1364 | + }; | ||
| 1365 | + let x = this | ||
| 1366 | + .drag_x | ||
| 1367 | + .take() | ||
| 1368 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 1369 | + this.drag_alt = window.modifiers().alt; | ||
| 1370 | + let at = this.place_frame(x).0; | ||
| 1371 | + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx); | ||
| 1372 | + })) | ||
| 1373 | + .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { | ||
| 1374 | + let Some(lane) = this.drag_lane else { | ||
| 1375 | + return; | ||
| 1376 | + }; | ||
| 1377 | + let x = this | ||
| 1378 | + .drag_x | ||
| 1379 | + .take() | ||
| 1380 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 1381 | + this.drag_alt = window.modifiers().alt; | ||
| 1382 | + this.move_sub(drag, lane, x, cx); | ||
| 1383 | + })) | ||
| 1384 | + .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { | ||
| 1385 | + let Some(lane) = this.drag_lane else { | ||
| 1386 | + return; | ||
| 1387 | + }; | ||
| 1388 | + let x = this | ||
| 1389 | + .drag_x | ||
| 1390 | + .take() | ||
| 1391 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 1392 | + this.drag_alt = window.modifiers().alt; | ||
| 1393 | + this.place_sub(drag.0, lane, x, cx); | ||
| 1394 | + })) | ||
| 1276 | .child( | 1395 | .child( |
| 1277 | // Pinned ruler: click/drag to seek (reuses `Player::scrub_to`, | 1396 | // Pinned ruler: click/drag to seek (reuses `Player::scrub_to`, |
| 1278 | // the same call the legacy ruler makes), tick marks with mono | 1397 | // the same call the legacy ruler makes), tick marks with mono |
crates/app/src/ui/dock_stance.rsmodified+28 -4
| @@ -376,8 +376,20 @@ fn source_row( | |||
| 376 | // drag media in timeline") was the dock showing the *legacy* | 376 | // drag media in timeline") was the dock showing the *legacy* |
| 377 | // panel, which the darkroom bench was never wired against; | 377 | // panel, which the darkroom bench was never wired against; |
| 378 | // this row is the darkroom's own half of that pairing. | 378 | // this row is the darkroom's own half of that pairing. |
| 379 | - .on_drag(AssetDrag(dragged.0, dragged.1), move |_, _, _, cx| { | 379 | + .on_drag(AssetDrag(dragged.0, dragged.1), { |
| 380 | - cx.new(|_| Tip(ghost.clone())) | 380 | + let me = cx.entity(); |
| 381 | + move |_, _, _, cx| { | ||
| 382 | + // A fresh gesture inherits nothing: `Player::drag_lane` | ||
| 383 | + // and `Player::drag_x` are the *last live sample* of the | ||
| 384 | + // drag being made, and a drag whose first sample lands | ||
| 385 | + // outside every row would otherwise be let go onto the | ||
| 386 | + // lane the previous one ended over. | ||
| 387 | + me.update(cx, |this, _| { | ||
| 388 | + this.drag_lane = None; | ||
| 389 | + this.drag_x = None; | ||
| 390 | + }); | ||
| 391 | + cx.new(|_| Tip(ghost.clone())) | ||
| 392 | + } | ||
| 381 | }) | 393 | }) |
| 382 | }) | 394 | }) |
| 383 | .tooltip(crate::ui::widgets::tip_hover("Source", "drag to a lane", None)) | 395 | .tooltip(crate::ui::widgets::tip_hover("Source", "drag to a lane", None)) |
| @@ -675,8 +687,20 @@ fn subtitle_tab_rows( | |||
| 675 | .when(usable, |d| { | 687 | .when(usable, |d| { |
| 676 | d.cursor_pointer() | 688 | d.cursor_pointer() |
| 677 | .hover(|s| s.bg(rgb(DARK_RAISED()))) | 689 | .hover(|s| s.bg(rgb(DARK_RAISED()))) |
| 678 | - .on_drag(SubPick(track), move |_, _, _, cx| { | 690 | + .on_drag(SubPick(track), { |
| 679 | - cx.new(|_| Tip(ghost.clone())) | 691 | + let me = cx.entity(); |
| 692 | + move |_, _, _, cx| { | ||
| 693 | + // A fresh gesture inherits nothing: `Player::drag_lane` | ||
| 694 | + // and `Player::drag_x` are the *last live sample* of the | ||
| 695 | + // drag being made, and a drag whose first sample lands | ||
| 696 | + // outside every row would otherwise be let go onto the | ||
| 697 | + // lane the previous one ended over. | ||
| 698 | + me.update(cx, |this, _| { | ||
| 699 | + this.drag_lane = None; | ||
| 700 | + this.drag_x = None; | ||
| 701 | + }); | ||
| 702 | + cx.new(|_| Tip(ghost.clone())) | ||
| 703 | + } | ||
| 680 | }) | 704 | }) |
| 681 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | 705 | .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { |
| 682 | this.sub_track = track; | 706 | this.sub_track = track; |
crates/app/src/ui/stance.rsmodified+8 -1
| @@ -615,7 +615,14 @@ fn bench( | |||
| 615 | // the bench is the selection one a picked clip draws (DESIGN §2/§4). | 615 | // the bench is the selection one a picked clip draws (DESIGN §2/§4). |
| 616 | .flex() | 616 | .flex() |
| 617 | .flex_col() | 617 | .flex_col() |
| 618 | - .px(px(12.)) | 618 | + // The 12px side gutter is spent INSIDE `bench_stance`'s own content |
| 619 | + // box, not here: gpui fires `on_drop` only on an element whose own | ||
| 620 | + // hitbox holds the pointer (`div.rs:2089`), and padding on this | ||
| 621 | + // parent left the gutter outside every registered target -- a clip | ||
| 622 | + // let go at x < 12, hard against the left edge where a hand aiming | ||
| 623 | + // at frame 0 puts it, reached nothing at all and moved nothing, | ||
| 624 | + // silently (DESIGN §8: a release that has aimed has made an edit). | ||
| 625 | + // Same box, same pixels; only the catch-all's bounds grow. | ||
| 619 | .py(px(4.)) | 626 | .py(px(4.)) |
| 620 | .child(bench_stance::render(player, bench_h - BENCH_CHROME_H, cx)) | 627 | .child(bench_stance::render(player, bench_h - BENCH_CHROME_H, cx)) |
| 621 | } | 628 | } |