forge
Explore
Log in

Don't you dare go Hollow

The bench shows the shadow before the clip lands

Browse files at this commit

1c0246b8f3521d8c338f2a6edb690bc66368837aAhmet Kaan GümüşParent: 9585160
  • feat
    • the bench shows the shadow before the clip lands
Show full message
✨ feat(ui): the bench shows the shadow before the clip lands

The darkroom bench's lane bed wired on_drag_move for AssetDrag,
ClipDrag, SubDrag and SubPick to the existing preview_ghost* setters
(Player::preview_ghost_asset/preview_ghost/preview_ghost_sub/
preview_ghost_pick), and paints the ghost box + snap-cue line as
absolute children of the bed -- the same reused state and math the
legacy ui/timeline.rs bed already draws with, filtered to the lane the
pointer is over and only while a drag is live.
crates/app/src/ui/bench_stance.rsmodified+88 -1
@@ -629,6 +629,20 @@ fn lane_row(
629629 let at = this.place_frame(window.mouse_position().x).0;
630630 this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx)
631631 }))
632+ // The landing shadow (`Player::preview_ghost_asset`, the same
633+ // setter `ui/timeline.rs`'s own bed calls) -- guarded on the
634+ // pointer actually being inside this bed's own bounds, since
635+ // `on_drag_move` fires on every painted element of the drag's
636+ // type, not just the one under the pointer.
637+ .on_drag_move(cx.listener(
638+ move |this, event: &DragMoveEvent<AssetDrag>, _, cx| {
639+ if !event.bounds.contains(&event.event.position) {
640+ return;
641+ }
642+ let path = event.drag(cx).0.clone();
643+ this.preview_ghost_asset(&path, lane, event.event.position.x, cx);
644+ },
645+ ))
632646 .drag_over::<ClipDrag>(|d, _, _, _| d.bg(rgb(DARK_RAISED())))
633647 .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| {
634648 let Some(idx) = this.dragged(drag) else {
@@ -636,6 +650,15 @@ fn lane_row(
636650 };
637651 this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx)
638652 }))
653+ .on_drag_move(cx.listener(
654+ move |this, event: &DragMoveEvent<ClipDrag>, _, cx| {
655+ if !event.bounds.contains(&event.event.position) {
656+ return;
657+ }
658+ let drag = *event.drag(cx);
659+ this.preview_ghost(&drag, lane, event.event.position.x, cx);
660+ },
661+ ))
639662 // A caption already on a lane moves along it, or onto another
640663 // subtitle track, exactly as a clip does (`Player::move_sub`,
641664 // the same call `ui/timeline.rs`'s own bed makes).
@@ -643,6 +666,25 @@ fn lane_row(
643666 .on_drop(cx.listener(move |this, drag: &SubDrag, window, cx| {
644667 this.move_sub(drag, lane, window.mouse_position().x, cx);
645668 }))
669+ .on_drag_move(cx.listener(
670+ move |this, event: &DragMoveEvent<SubDrag>, _, cx| {
671+ if !event.bounds.contains(&event.event.position) {
672+ return;
673+ }
674+ let drag = *event.drag(cx);
675+ this.preview_ghost_sub(&drag, lane, event.event.position.x, cx);
676+ },
677+ ))
678+ .drag_over::<SubPick>(|d, _, _, _| d.bg(rgb(DARK_RAISED())))
679+ .on_drag_move(cx.listener(
680+ move |this, event: &DragMoveEvent<SubPick>, _, cx| {
681+ if !event.bounds.contains(&event.event.position) {
682+ return;
683+ }
684+ let track = event.drag(cx).0;
685+ this.preview_ghost_pick(track, lane, event.event.position.x, cx);
686+ },
687+ ))
646688 // The wheel, matched to the legacy timeline's own mapping:
647689 // ctrl+wheel zooms about the pointer, a bare wheel scrolls
648690 // the bed along the film (`Player::timeline_wheel`). Stopped
@@ -653,7 +695,52 @@ fn lane_row(
653695 this.timeline_wheel(event, cx);
654696 }))
655697 .children(boxes)
656- .children(sub_boxes),
698+ .children(sub_boxes)
699+ // The shadow of the row in flight (`Player::ghost`, set by
700+ // the `on_drag_move` handlers above) -- the same box
701+ // `ui/timeline.rs`'s own bed draws, only while a drag of its
702+ // kind is actually live (`App::has_active_drag`: gpui drops a
703+ // drag without telling anyone) and only on the one lane the
704+ // pointer is over.
705+ .children(
706+ player
707+ .ghost
708+ .filter(|g| g.lane == lane && cx.has_active_drag())
709+ .map(|g| {
710+ div()
711+ .absolute()
712+ .top_0()
713+ .h_full()
714+ .left(px(scale.px_at(f64::from(g.start) / player.fps)))
715+ .w(px(scale
716+ .width_px(f64::from(g.frames) / player.fps)
717+ .max(GHOST_MIN)))
718+ .rounded(px(3.))
719+ .border_1()
720+ .border_color(rgb(if g.refused { DROP_REFUSE() } else { INK1() }))
721+ .bg(rgba(
722+ ((if g.refused { DROP_REFUSE() } else { g.tint }) << 8)
723+ | GHOST_ALPHA,
724+ ))
725+ }),
726+ )
727+ // Where it would land, drawn on every lane so a clip lining
728+ // up with a take one track over can be seen to line up with
729+ // it -- the same cue `ui/timeline.rs` draws.
730+ .children(
731+ player
732+ .snap_cue
733+ .filter(|_| player.trim.is_some() || cx.has_active_drag())
734+ .map(|frame| {
735+ div()
736+ .absolute()
737+ .top_0()
738+ .h_full()
739+ .left(px(scale.px_at(f64::from(frame) / player.fps)))
740+ .w(px(1.))
741+ .bg(rgb(INK1()))
742+ }),
743+ ),
657744 )
658745 }
659746