A shadow that lies is a broken drag — clamp the landing, keep the lane
Browse files at this commit8bd7e0cec2640bd1fa3eb1332ded2d76142b6186Parent: def69ad- fix
- a shadow that lies is a broken drag — clamp the landing, keep the lane
2 changed files +51 -3
crates/app/src/player/timeline_edit.rsmodified+13 -3
| @@ -909,13 +909,23 @@ impl Player { | |||
| 909 | .collect() | 909 | .collect() |
| 910 | }) | 910 | }) |
| 911 | .unwrap_or_default(); | 911 | .unwrap_or_default(); |
| 912 | + // Staying on its own lane, the engine clamps the travel into the gap | ||
| 913 | + // the clip sits in rather than refusing it, so the shadow rests where | ||
| 914 | + // the release will: flush against the take it was dragged into. Landing | ||
| 915 | + // on *another* lane it is refused outright when a take is already | ||
| 916 | + // there, and the shadow says so before the hand lets go -- never a | ||
| 917 | + // silent no-op. | ||
| 918 | + let len = drag.clip.frames(); | ||
| 919 | + let (start, refused) = match to == drag.lane { | ||
| 920 | + true => (gap_clamp(drag.clip.start, len, start, &neighbours), false), | ||
| 921 | + false => (start, collides(start, len, &neighbours)), | ||
| 922 | + }; | ||
| 912 | let anchor = Ghost { | 923 | let anchor = Ghost { |
| 913 | lane: to, | 924 | lane: to, |
| 914 | start, | 925 | start, |
| 915 | - frames: drag.clip.frames(), | 926 | + frames: len, |
| 916 | tint: self.clip_tint(drag.clip.source), | 927 | tint: self.clip_tint(drag.clip.source), |
| 917 | - refused: drag.lane.kind != to.kind | 928 | + refused: drag.lane.kind != to.kind || refused, |
| 918 | - || collides(start, drag.clip.frames(), &neighbours), | ||
| 919 | }; | 929 | }; |
| 920 | let mut ghosts = vec![anchor]; | 930 | let mut ghosts = vec![anchor]; |
| 921 | if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 { | 931 | if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 { |
crates/app/src/timeline_math.rsmodified+38 -0
| @@ -677,6 +677,29 @@ pub(crate) fn collides(start: u32, len: u32, others: &[(u32, u32)]) -> bool { | |||
| 677 | .any(|&(other_start, other_end)| start < other_end && other_start < end) | 677 | .any(|&(other_start, other_end)| start < other_end && other_start < end) |
| 678 | } | 678 | } |
| 679 | 679 | ||
| 680 | +/// Where a clip staying on its own lane really comes to rest: `want`, clamped | ||
| 681 | +/// into the gap it is sitting in -- the take behind it and the take in front of | ||
| 682 | +/// it are walls ([`Project::move_selection`] clamps the delta by exactly these, | ||
| 683 | +/// it does not refuse), so a clip dragged hard left past its neighbour lands | ||
| 684 | +/// flush against that neighbour's tail rather than nowhere. `now` is its head | ||
| 685 | +/// today, which is what names the gap. The shadow reads this, so the box drawn | ||
| 686 | +/// in flight is the box the release leaves behind. | ||
| 687 | +pub(crate) fn gap_clamp(now: u32, len: u32, want: u32, others: &[(u32, u32)]) -> u32 { | ||
| 688 | + let lo = others | ||
| 689 | + .iter() | ||
| 690 | + .filter(|&&(_, end)| end <= now) | ||
| 691 | + .map(|&(_, end)| end) | ||
| 692 | + .max() | ||
| 693 | + .unwrap_or(0); | ||
| 694 | + let hi = others | ||
| 695 | + .iter() | ||
| 696 | + .filter(|&&(start, _)| start >= now.saturating_add(len)) | ||
| 697 | + .map(|&(start, _)| start) | ||
| 698 | + .min() | ||
| 699 | + .unwrap_or(u32::MAX); | ||
| 700 | + want.clamp(lo, hi.saturating_sub(len).max(lo)) | ||
| 701 | +} | ||
| 702 | + | ||
| 680 | /// The lane a release lands on when the pointer is off the rows themselves: | 703 | /// The lane a release lands on when the pointer is off the rows themselves: |
| 681 | /// the row under it while its kind can hold what is in the hand, and otherwise | 704 | /// the row under it while its kind can hold what is in the hand, and otherwise |
| 682 | /// the last one that could -- a picture clip carried down across A1 on its way | 705 | /// the last one that could -- a picture clip carried down across A1 on its way |
| @@ -891,6 +914,21 @@ mod drop_landing_tests { | |||
| 891 | assert_eq!(held_lane(None, a1, v1), None); | 914 | assert_eq!(held_lane(None, a1, v1), None); |
| 892 | } | 915 | } |
| 893 | 916 | ||
| 917 | + /// A clip dragged hard left past the take in front of it comes to rest | ||
| 918 | + /// flush against that take -- the walls of its own gap, which is what the | ||
| 919 | + /// engine clamps the drag by -- and one dragged off the head of the | ||
| 920 | + /// timeline rests on frame 0. | ||
| 921 | + #[test] | ||
| 922 | + fn a_drag_past_a_neighbour_rests_flush_against_it() { | ||
| 923 | + let others = [(0, 375), (900, 1000)]; | ||
| 924 | + assert_eq!(gap_clamp(375, 500, 0, &others), 375, "flush with its tail"); | ||
| 925 | + assert_eq!(gap_clamp(375, 500, 380, &others), 380, "room to spare"); | ||
| 926 | + assert_eq!(gap_clamp(375, 500, 800, &others), 400, "flush with the next"); | ||
| 927 | + // An empty lane clamps at the head of the timeline and nowhere else. | ||
| 928 | + assert_eq!(gap_clamp(500, 100, 0, &[]), 0); | ||
| 929 | + assert_eq!(gap_clamp(500, 100, 9_000, &[]), 9_000); | ||
| 930 | + } | ||
| 931 | + | ||
| 894 | /// The refused state the shadow draws: a head let go on top of a take | 932 | /// The refused state the shadow draws: a head let go on top of a take |
| 895 | /// already on the lane, which the engine changes nothing for. Laid exactly | 933 | /// already on the lane, which the engine changes nothing for. Laid exactly |
| 896 | /// against one -- what the magnet is for -- is not a collision. | 934 | /// against one -- what the magnet is for -- is not a collision. |