wip(bench): drag feel — clamp, snap targets, preview — capped mid-work
Browse files at this commita35a1ff4c43adc1436a6d40e54c57ed760488560Parent: 1c2894a4 changed files +247 -89
- crates/app/src/main.rs +16 -0
- crates/app/src/player/timeline_edit.rs +20 -5
- crates/app/src/timeline_math.rs +84 -0
- crates/app/src/ui/bench_stance.rs +127 -84
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 |
| @@ -928,6 +942,7 @@ fn main() { | |||
| 928 | fade_drag: None, | 942 | fade_drag: None, |
| 929 | grab: 0, | 943 | grab: 0, |
| 930 | snap: true, | 944 | snap: true, |
| 945 | + drag_alt: false, | ||
| 931 | subs_on: true, | 946 | subs_on: true, |
| 932 | sub_track: 0, | 947 | sub_track: 0, |
| 933 | sub_folded: HashSet::new(), | 948 | sub_folded: HashSet::new(), |
| @@ -935,6 +950,7 @@ fn main() { | |||
| 935 | snap_cue: None, | 950 | snap_cue: None, |
| 936 | ghost: Vec::new(), | 951 | ghost: Vec::new(), |
| 937 | drag_x: None, | 952 | drag_x: None, |
| 953 | + drag_lane: None, | ||
| 938 | lane_drop: None, | 954 | lane_drop: None, |
| 939 | last_scrub: Instant::now(), | 955 | last_scrub: Instant::now(), |
| 940 | last_target: 0, | 956 | last_target: 0, |
crates/app/src/player/timeline_edit.rsmodified+20 -5
| @@ -751,7 +751,7 @@ impl Player { | |||
| 751 | self.frame_under(x), | 751 | self.frame_under(x), |
| 752 | self.grab, | 752 | self.grab, |
| 753 | sub.frames, | 753 | sub.frames, |
| 754 | - self.snap, | 754 | + self.snap_live(), |
| 755 | self.drop_snap_frames(), | 755 | self.drop_snap_frames(), |
| 756 | &marks, | 756 | &marks, |
| 757 | ) | 757 | ) |
| @@ -824,7 +824,7 @@ impl Player { | |||
| 824 | self.frame_under(x), | 824 | self.frame_under(x), |
| 825 | self.grab, | 825 | self.grab, |
| 826 | clip.frames(), | 826 | clip.frames(), |
| 827 | - self.snap, | 827 | + self.snap_live(), |
| 828 | self.drop_snap_frames(), | 828 | self.drop_snap_frames(), |
| 829 | &marks, | 829 | &marks, |
| 830 | )) | 830 | )) |
| @@ -841,7 +841,7 @@ impl Player { | |||
| 841 | self.frame_under(x), | 841 | self.frame_under(x), |
| 842 | 0, | 842 | 0, |
| 843 | 0, | 843 | 0, |
| 844 | - self.snap, | 844 | + self.snap_live(), |
| 845 | self.drop_snap_frames(), | 845 | self.drop_snap_frames(), |
| 846 | &marks, | 846 | &marks, |
| 847 | ) | 847 | ) |
| @@ -1052,7 +1052,7 @@ impl Player { | |||
| 1052 | /// Where a gesture at `raw` lands and the mark that pulled it there, with | 1052 | /// Where a gesture at `raw` lands and the mark that pulled it there, with |
| 1053 | /// the switch honoured: snapping off, nothing moves and no line is drawn. | 1053 | /// the switch honoured: snapping off, nothing moves and no line is drawn. |
| 1054 | pub(crate) fn snap_to(&self, raw: u32, len: u32, marks: &[u32]) -> (u32, Option<u32>) { | 1054 | pub(crate) fn snap_to(&self, raw: u32, len: u32, marks: &[u32]) -> (u32, Option<u32>) { |
| 1055 | - snap_cue(self.snap, raw, len, self.snap_frames(), marks) | 1055 | + snap_cue(self.snap_live(), raw, len, self.snap_frames(), marks) |
| 1056 | } | 1056 | } |
| 1057 | 1057 | ||
| 1058 | /// Every timeline frame that is a *source* sync point: each clip's own | 1058 | /// Every timeline frame that is a *source* sync point: each clip's own |
| @@ -1148,6 +1148,17 @@ impl Player { | |||
| 1148 | /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the bed's | 1148 | /// [`SNAP_PX`] in timeline frames at the scale the bed is drawn at: the bed's |
| 1149 | /// own width drops out of it, since a pixel is now worth the same stretch of | 1149 | /// own width drops out of it, since a pixel is now worth the same stretch of |
| 1150 | /// timeline wherever the view sits. | 1150 | /// timeline wherever the view sits. |
| 1151 | + /// Whether the magnet is on for the gesture happening *now*: the switch | ||
| 1152 | + /// ([`Player::snap`]) unless `alt` is held ([`Player::drag_alt`]), which | ||
| 1153 | + /// turns it off for this drag or trim alone -- the temporary override | ||
| 1154 | + /// Resolve, Premiere and Final Cut all put on the same key. The switch is | ||
| 1155 | + /// not touched, so the stroke that follows the drag finds it where it was. | ||
| 1156 | + /// Every landing on this timeline asks it, so the shadow, the line and the | ||
| 1157 | + /// drop can never disagree about whether a magnet was on. | ||
| 1158 | + pub(crate) fn snap_live(&self) -> bool { | ||
| 1159 | + snap_live(self.snap, self.drag_alt) | ||
| 1160 | + } | ||
| 1161 | + | ||
| 1151 | pub(crate) fn snap_frames(&self) -> u32 { | 1162 | pub(crate) fn snap_frames(&self) -> u32 { |
| 1152 | self.scale.snap_frames(self.fps) | 1163 | self.scale.snap_frames(self.fps) |
| 1153 | } | 1164 | } |
| @@ -2005,7 +2016,10 @@ impl Player { | |||
| 2005 | // outside the window, still owing its one edit. | 2016 | // outside the window, still owing its one edit. |
| 2006 | if self.trim.is_some() { | 2017 | if self.trim.is_some() { |
| 2007 | match event.pressed_button { | 2018 | match event.pressed_button { |
| 2008 | - Some(MouseButton::Left) => self.trim_to(event.position.x, cx), | 2019 | + Some(MouseButton::Left) => { |
| 2020 | + self.drag_alt = event.modifiers.alt; | ||
| 2021 | + self.trim_to(event.position.x, cx); | ||
| 2022 | + } | ||
| 2009 | _ => self.commit_trim(cx), | 2023 | _ => self.commit_trim(cx), |
| 2010 | } | 2024 | } |
| 2011 | return; | 2025 | return; |
| @@ -2131,6 +2145,7 @@ impl Player { | |||
| 2131 | if self.trim.is_some() { | 2145 | if self.trim.is_some() { |
| 2132 | // The release lands exactly, then the gesture is | 2146 | // The release lands exactly, then the gesture is |
| 2133 | // written once -- one edit, one undo step. | 2147 | // written once -- one edit, one undo step. |
| 2148 | + self.drag_alt = event.modifiers.alt; | ||
| 2134 | self.trim_to(event.position.x, cx); | 2149 | self.trim_to(event.position.x, cx); |
| 2135 | self.commit_trim(cx); | 2150 | self.commit_trim(cx); |
| 2136 | return; | 2151 | return; |
crates/app/src/timeline_math.rsmodified+84 -0
| @@ -626,6 +626,15 @@ pub(crate) fn snap_cue( | |||
| 626 | (start, mark) | 626 | (start, mark) |
| 627 | } | 627 | } |
| 628 | 628 | ||
| 629 | +/// Whether the magnet is on for the gesture in flight: the switch, unless | ||
| 630 | +/// `alt` is held -- the temporary override Resolve, Premiere and Final Cut all | ||
| 631 | +/// put on that key, off for this one drag and leaving the switch where the hand | ||
| 632 | +/// left it. [`Player::snap_live`]'s whole rule, here so it can be read without | ||
| 633 | +/// a window. | ||
| 634 | +pub(crate) fn snap_live(on: bool, alt: bool) -> bool { | ||
| 635 | + on && !alt | ||
| 636 | +} | ||
| 637 | + | ||
| 629 | /// Where a drag lands and the mark that pulled it there: the frame under the | 638 | /// 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 | 639 | /// 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 | 640 | /// with the pointer rather than jumping its head under it), snapped by |
| @@ -723,4 +732,79 @@ mod drop_landing_tests { | |||
| 723 | assert!(marks.contains(&500)); | 732 | assert!(marks.contains(&500)); |
| 724 | assert_eq!(snapped(493, 0, 10, &marks), 500); | 733 | assert_eq!(snapped(493, 0, 10, &marks), 500); |
| 725 | } | 734 | } |
| 735 | + | ||
| 736 | + /// The user's own repro: a clip dragged left through the lane-head column | ||
| 737 | + /// -- window x *left of the bed* -- lands on frame 0 rather than nowhere. | ||
| 738 | + /// Two clamps do it, and both are on the path the bench now takes for a | ||
| 739 | + /// drop over the head ([`Player::frame_under`]): [`px_along`] pins an x | ||
| 740 | + /// before the bed's left edge to 0 px, [`Scale::time_at`] pins the moment | ||
| 741 | + /// to 0 s, and the grab offset comes off with a saturating subtraction, so | ||
| 742 | + /// even a clip held by its tail cannot ask for a negative frame. | ||
| 743 | + #[test] | ||
| 744 | + fn a_drag_out_over_the_lane_head_lands_on_frame_0() { | ||
| 745 | + let bed = Bounds { | ||
| 746 | + origin: point(px(100.), px(0.)), | ||
| 747 | + size: size(px(900.), px(60.)), | ||
| 748 | + }; | ||
| 749 | + let scale = Scale::default(); | ||
| 750 | + // 40 px into the head column, and off the window entirely. | ||
| 751 | + for x in [px(60.), px(-400.)] { | ||
| 752 | + assert_eq!(px_along(x, bed), 0.); | ||
| 753 | + let under = frame_at(scale.time_at(px_along(x, bed)), 25.); | ||
| 754 | + assert_eq!(under, 0); | ||
| 755 | + // Grabbed 30 frames into the box: still frame 0, never a refusal. | ||
| 756 | + assert_eq!(landing(under, 30, 50, true, 10, &[0, 300]), (0, Some(0))); | ||
| 757 | + } | ||
| 758 | + } | ||
| 759 | + | ||
| 760 | + /// Both edges of the clip in the hand are candidates and the nearest one | ||
| 761 | + /// wins: a tail 2 frames short of a neighbour's head beats a head 8 frames | ||
| 762 | + /// from the timeline's start. | ||
| 763 | + #[test] | ||
| 764 | + fn the_nearer_of_the_two_edges_wins() { | ||
| 765 | + let marks = [0, 300, 500]; | ||
| 766 | + // len 292: the tail wants 300 (2 away), the head 0 (8 away). | ||
| 767 | + // The tail already sits exactly on 300, so the head is left alone. | ||
| 768 | + assert_eq!(snapped(8, 292, 10, &marks), 8); | ||
| 769 | + assert_eq!(snapped(6, 292, 10, &marks), 8, "tail meets 300, head stays"); | ||
| 770 | + } | ||
| 771 | + | ||
| 772 | + /// The threshold is a distance on *screen*: the same 10 px of aim at two | ||
| 773 | + /// zooms is a different number of frames, which is what makes the magnet | ||
| 774 | + /// feel identical zoomed in and zoomed out ([`Scale::drop_snap_frames`]). | ||
| 775 | + /// Outside it the drag follows the pointer exactly. | ||
| 776 | + #[test] | ||
| 777 | + fn the_threshold_is_ten_pixels_at_any_zoom() { | ||
| 778 | + let fps = 25.; | ||
| 779 | + for pps in [50., 400.] { | ||
| 780 | + let scale = Scale { pps, start: 0. }; | ||
| 781 | + let tol = scale.drop_snap_frames(fps); | ||
| 782 | + // 10 px worth of frames, and one frame more than that is not near. | ||
| 783 | + let near = (DROP_SNAP_PX / pps * fps) as u32; | ||
| 784 | + assert_eq!(tol, near); | ||
| 785 | + assert_eq!(snapped(500 + tol, 0, tol, &[500]), 500); | ||
| 786 | + assert_eq!( | ||
| 787 | + snapped(500 + tol + 1, 0, tol, &[500]), | ||
| 788 | + 500 + tol + 1, | ||
| 789 | + "past the window the pointer is obeyed exactly" | ||
| 790 | + ); | ||
| 791 | + } | ||
| 792 | + } | ||
| 793 | + | ||
| 794 | + /// `alt` held turns the magnet off for the gesture and nothing else: the | ||
| 795 | + /// same raw ask, no line, and [`Player::snap`] itself untouched. | ||
| 796 | + #[test] | ||
| 797 | + fn alt_turns_the_magnet_off_for_this_drag_only() { | ||
| 798 | + let on = true; | ||
| 799 | + assert!(snap_live(on, false)); | ||
| 800 | + assert!(!snap_live(on, true)); | ||
| 801 | + let marks = [0, 300]; | ||
| 802 | + assert_eq!( | ||
| 803 | + snap_cue(snap_live(on, true), 297, 0, 10, &marks), | ||
| 804 | + (297, None) | ||
| 805 | + ); | ||
| 806 | + assert_eq!(snap_cue(snap_live(on, false), 297, 0, 10, &marks), (300, Some(300))); | ||
| 807 | + // The switch off stays off however the modifier is held. | ||
| 808 | + assert!(!snap_live(false, false)); | ||
| 809 | + } | ||
| 726 | } | 810 | } |
crates/app/src/ui/bench_stance.rsmodified+127 -84
| @@ -877,6 +877,111 @@ fn lane_row( | |||
| 877 | this.preview_lane_drop(event.drag(cx).0, lane, cx); | 877 | this.preview_lane_drop(event.drag(cx).0, lane, cx); |
| 878 | }), | 878 | }), |
| 879 | ) | 879 | ) |
| 880 | + .drag_over::<AssetDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 881 | + .on_drop(cx.listener(move |this, drag: &AssetDrag, window, cx| { | ||
| 882 | + this.drag_alt = window.modifiers().alt; | ||
| 883 | + let x = this | ||
| 884 | + .drag_x | ||
| 885 | + .take() | ||
| 886 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 887 | + let at = this.place_frame(x).0; | ||
| 888 | + this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) | ||
| 889 | + })) | ||
| 890 | + // The landing shadow (`Player::preview_ghost_asset`, the same | ||
| 891 | + // setter `ui/timeline.rs`'s own bed calls) -- guarded on the | ||
| 892 | + // pointer actually being inside this *row's* bounds, since | ||
| 893 | + // `on_drag_move` fires on every painted element of the drag's | ||
| 894 | + // type, not just the one under the pointer. The row and not the | ||
| 895 | + // bed: the head column is 72px of this lane too, and a clip | ||
| 896 | + // dragged out over it is aiming at frame 0 -- the drop it used to | ||
| 897 | + // fall through (nothing under the pointer answered `ClipDrag`) is | ||
| 898 | + // the "I have to be pixel perfect to snap to 0" complaint. | ||
| 899 | + // `Player::frame_under` clamps an x left of the bed to the head of | ||
| 900 | + // the view (`px_along`), so the head column reads as frame 0. | ||
| 901 | + .on_drag_move( | ||
| 902 | + cx.listener(move |this, event: &DragMoveEvent<AssetDrag>, _, cx| { | ||
| 903 | + if !event.bounds.contains(&event.event.position) { | ||
| 904 | + return; | ||
| 905 | + } | ||
| 906 | + let path = event.drag(cx).0.clone(); | ||
| 907 | + this.drag_x = Some(event.event.position.x); | ||
| 908 | + this.drag_alt = event.event.modifiers.alt; | ||
| 909 | + this.preview_ghost_asset(&path, lane, event.event.position.x, cx); | ||
| 910 | + }), | ||
| 911 | + ) | ||
| 912 | + .drag_over::<ClipDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 913 | + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { | ||
| 914 | + this.drag_alt = window.modifiers().alt; | ||
| 915 | + let Some(idx) = this.dragged(drag) else { | ||
| 916 | + return; | ||
| 917 | + }; | ||
| 918 | + let x = this | ||
| 919 | + .drag_x | ||
| 920 | + .take() | ||
| 921 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 922 | + this.move_clip(drag.lane, idx, lane, x, cx) | ||
| 923 | + })) | ||
| 924 | + .on_drag_move( | ||
| 925 | + cx.listener(move |this, event: &DragMoveEvent<ClipDrag>, _, cx| { | ||
| 926 | + if !event.bounds.contains(&event.event.position) { | ||
| 927 | + return; | ||
| 928 | + } | ||
| 929 | + let drag = *event.drag(cx); | ||
| 930 | + this.drag_x = Some(event.event.position.x); | ||
| 931 | + // The last lane this clip could actually land on: a picture | ||
| 932 | + // clip dragged down across A1 on its way to the empty bench | ||
| 933 | + // below is still aiming at V1, and the catch-all release must | ||
| 934 | + // not hand it the audio lane that refused it on the way past. | ||
| 935 | + if drag.lane.kind == lane.kind { | ||
| 936 | + this.drag_lane = Some(lane); | ||
| 937 | + } | ||
| 938 | + this.drag_alt = event.event.modifiers.alt; | ||
| 939 | + this.preview_ghost(&drag, lane, event.event.position.x, cx); | ||
| 940 | + }), | ||
| 941 | + ) | ||
| 942 | + // A caption already on a lane moves along it, or onto another | ||
| 943 | + // subtitle track, exactly as a clip does (`Player::move_sub`, | ||
| 944 | + // the same call `ui/timeline.rs`'s own bed makes). | ||
| 945 | + .drag_over::<SubDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 946 | + .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| { | ||
| 947 | + this.drag_alt = window.modifiers().alt; | ||
| 948 | + let x = this | ||
| 949 | + .drag_x | ||
| 950 | + .take() | ||
| 951 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 952 | + this.move_sub(drag, lane, x, cx); | ||
| 953 | + })) | ||
| 954 | + .on_drag_move( | ||
| 955 | + cx.listener(move |this, event: &DragMoveEvent<SubDrag>, _, cx| { | ||
| 956 | + if !event.bounds.contains(&event.event.position) { | ||
| 957 | + return; | ||
| 958 | + } | ||
| 959 | + let drag = *event.drag(cx); | ||
| 960 | + this.drag_x = Some(event.event.position.x); | ||
| 961 | + this.drag_alt = event.event.modifiers.alt; | ||
| 962 | + this.preview_ghost_sub(&drag, lane, event.event.position.x, cx); | ||
| 963 | + }), | ||
| 964 | + ) | ||
| 965 | + .drag_over::<SubPick>(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) | ||
| 966 | + .on_drop(cx.listener(move |this, drag: &SubPick, window, cx| { | ||
| 967 | + this.drag_alt = window.modifiers().alt; | ||
| 968 | + let x = this | ||
| 969 | + .drag_x | ||
| 970 | + .take() | ||
| 971 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 972 | + this.place_sub(drag.0, lane, x, cx); | ||
| 973 | + })) | ||
| 974 | + .on_drag_move( | ||
| 975 | + cx.listener(move |this, event: &DragMoveEvent<SubPick>, _, cx| { | ||
| 976 | + if !event.bounds.contains(&event.event.position) { | ||
| 977 | + return; | ||
| 978 | + } | ||
| 979 | + let track = event.drag(cx).0; | ||
| 980 | + this.drag_x = Some(event.event.position.x); | ||
| 981 | + this.drag_alt = event.event.modifiers.alt; | ||
| 982 | + this.preview_ghost_pick(track, lane, event.event.position.x, cx); | ||
| 983 | + }), | ||
| 984 | + ) | ||
| 880 | .child( | 985 | .child( |
| 881 | // Pinned track head: its drag handle remains the lane label; verbs | 986 | // Pinned track head: its drag handle remains the lane label; verbs |
| 882 | // stay separate pointer targets so a mix/remove click never starts | 987 | // stay separate pointer targets so a mix/remove click never starts |
| @@ -1019,15 +1124,6 @@ fn lane_row( | |||
| 1019 | .h_full() | 1124 | .h_full() |
| 1020 | .bg(rgba(DARK_SEAM())), | 1125 | .bg(rgba(DARK_SEAM())), |
| 1021 | ) | 1126 | ) |
| 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 | 1127 | // Right-click on empty bed space: the "Close Gap" door. A |
| 1032 | // clip's own right-click handler (`clip_box`/`sub_box`) never | 1128 | // clip's own right-click handler (`clip_box`/`sub_box`) never |
| 1033 | // stops propagation, so this fires on that press too -- | 1129 | // stops propagation, so this fires on that press too -- |
| @@ -1060,81 +1156,6 @@ fn lane_row( | |||
| 1060 | } | 1156 | } |
| 1061 | }), | 1157 | }), |
| 1062 | ) | 1158 | ) |
| 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)) | 1159 | .tooltip(crate::ui::widgets::tip_hover("Lane bed", "drop media here", None)) |
| 1139 | .children(hitmap::dynamic( | 1160 | .children(hitmap::dynamic( |
| 1140 | move || { | 1161 | move || { |
| @@ -1273,6 +1294,28 @@ pub(crate) fn render( | |||
| 1273 | .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { | 1294 | .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { |
| 1274 | this.timeline_wheel(event, cx); | 1295 | this.timeline_wheel(event, cx); |
| 1275 | })) | 1296 | })) |
| 1297 | + // The catch-all release: a clip let go of anywhere on the bench that is | ||
| 1298 | + // not a lane row -- left of the tracks, in the gap between two rows, on | ||
| 1299 | + // the empty bench below the last one -- lands on the lane and the x the | ||
| 1300 | + // last live sample of that same drag was over (`Player::drag_lane`, | ||
| 1301 | + // `Player::drag_x`), which is exactly what the shadow was drawn at. A | ||
| 1302 | + // release that reaches no drop target at all is the one thing a drag | ||
| 1303 | + // may never do: a hand that has aimed a clip and let go has made an | ||
| 1304 | + // edit, and "nothing happened" is not one of the answers an editor | ||
| 1305 | + // accepts. A row's own listener stops propagation when it answers, so | ||
| 1306 | + // this only ever runs when none did -- and it would answer with the | ||
| 1307 | + // same frame if it did run, since both read the one sample. | ||
| 1308 | + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { | ||
| 1309 | + let (Some(lane), Some(idx)) = (this.drag_lane, this.dragged(drag)) else { | ||
| 1310 | + return; | ||
| 1311 | + }; | ||
| 1312 | + let x = this | ||
| 1313 | + .drag_x | ||
| 1314 | + .take() | ||
| 1315 | + .unwrap_or_else(|| window.mouse_position().x); | ||
| 1316 | + this.drag_alt = window.modifiers().alt; | ||
| 1317 | + this.move_clip(drag.lane, idx, lane, x, cx); | ||
| 1318 | + })) | ||
| 1276 | .child( | 1319 | .child( |
| 1277 | // Pinned ruler: click/drag to seek (reuses `Player::scrub_to`, | 1320 | // Pinned ruler: click/drag to seek (reuses `Player::scrub_to`, |
| 1278 | // the same call the legacy ruler makes), tick marks with mono | 1321 | // the same call the legacy ruler makes), tick marks with mono |