From aaf986f816b850410366a24ebb30b82da8a6c731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 16:31:42 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(ui):=20the=20bench=20answers?= =?UTF-8?q?=20the=20mouse=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dragging did not work, zoom did not work, and there was no way to seek through the project. All three were the same omission: the bench got the drop from the dock and nothing else, while every other pointer gesture stayed behind in the old room. A clip drags along its lane and onto another one, its edges trim under the pointer at any width the aim allows, the wheel pans and zooms about the cursor as it always did, and a track head drags to reorder. None of this is new machinery — it is the timeline's own doors, finally called from the new room. Zoom had no home: the actions existed and worked, but nothing in the room showed them, so the only way in was a memorised key. The spine has a VIEW group now, ranked below cutting and above the once-a-project lane adds. The contact strip becomes the seek instrument it was meant to be: a drag along it scrubs the film continuously rather than sliding the bench window, it carries the playhead as a lamp-white mark so it reads as a slider with a handle, and panning moves to the viewport bracket's own grips. --- crates/app/src/ui/bench_stance.rs | 115 +++++++++++++++++-- crates/app/src/ui/spine_stance.rs | 14 +++ crates/app/src/ui/timeband_stance.rs | 158 +++++++++++++++++---------- 3 files changed, 220 insertions(+), 67 deletions(-) diff --git a/crates/app/src/ui/bench_stance.rs b/crates/app/src/ui/bench_stance.rs index 9da68b3..6a6f617 100644 --- a/crates/app/src/ui/bench_stance.rs +++ b/crates/app/src/ui/bench_stance.rs @@ -18,17 +18,29 @@ //! trace, name plate, splice gaps) and the width ladder that degrades it //! (DESIGN §7) -- neither existed on the legacy timeline in this shape. //! -//! Not reused, deferred: `ClipDrag` (moving a placed clip to another lane by -//! hand), the mouse edge-trim strips, fades/dissolve glyphs and the lane -//! header reorder drag. The cut grammar (`,` `.` `[` `]` `/` `s`) never needs -//! any of them -- `nudge_cut` and friends act on `Player::selected` directly, -//! with no element under the pointer required -- so they are out of this -//! slice's reach; `Player::pick` (click-select) and the asset drop (place) -//! are the two pointer gestures the charter actually asked this surface to -//! answer for. +//! Now also reused: `ClipDrag` (moving a placed clip along its lane and onto +//! another, `Player::dragged`/`Player::move_clip`), the mouse edge-trim +//! strips (`Player::start_trim`/`trims(span)`, the same minimum-width rule +//! the legacy strips use), `Player::timeline_wheel` (ctrl+wheel zooms about +//! the pointer, a bare wheel scrolls the bed -- the same mapping on the +//! ruler and on every bed) and `LaneDrag`/`Player::reorder_lane` (drag a +//! track head onto another to swap their order). `Player::drag_move`/ +//! `Player::drag_release`, wired once on the window's own root +//! (`render.rs`), already carry a trim or a scroll off the 6px strip that +//! started it, for the darkroom tree exactly as for the legacy one -- no +//! root wiring lives here. +//! +//! Still deferred: fades/dissolve glyphs, and the lane header's own +//! drop-line cue (the legacy `LaneDrop` preview) -- a plain drag_over +//! highlight stands in for it here, since the cue itself is display-only and +//! `reorder_lane` at the release does not need it. +//! +//! `nudge_cut` and friends still act on `Player::selected` directly, with no +//! element under the pointer required, and stay untouched by any of this. use crate::*; use crate::ui::type_scale::{self, Typeset}; +use crate::ui::widgets::*; /// The pinned ruler's own height, above the lane stack -- tall enough for a /// tick line plus a mono `MM:SS` label under it (DESIGN §5's "tick marks with @@ -149,6 +161,11 @@ fn clip_box( pick_links: &[Option], cx: &mut Context, ) -> impl IntoElement + use<> { + // The placed clip, for the drag payload -- and the clip as an in-flight + // edge trim is showing it, for the box (`Player::trimmed`, the same + // split `ui/timeline.rs`'s own clip box makes). + let placed = *clip; + let clip = &player.trimmed(lane, idx, placed); let (start, len) = ( f64::from(clip.start) / player.fps, f64::from(clip.frames()) / player.fps, @@ -191,6 +208,9 @@ fn clip_box( } _ => format!("{len:.1}s"), }; + // For the drag ghost and the fallback label both -- kept before `label` + // is consumed by the name plate below. + let ghost: SharedString = label.clone().unwrap_or_else(|| lane.label()).into(); div() .id(("bench-clip", lane.ord * 1000 + lane.kind as usize * 100 + idx)) .absolute() @@ -213,6 +233,44 @@ fn clip_box( this.pick((lane, idx), event.modifiers.control, cx); }), ) + // Dragged, it moves: to the frame and the lane it is let go over + // (`Player::move_clip`, `ClipDrag`) -- the same payload and the same + // ghost tooltip `ui/timeline.rs`'s own clip box drags. + .on_drag(ClipDrag { lane, idx, clip: placed }, { + let ghost = ghost.clone(); + move |_, _, _, cx| cx.new(|_| Tip(ghost.clone())) + }) + // The two edge strips a drag lengthens or shortens the clip by + // (`Player::start_trim`), gated on the same `trims(span)` floor the + // legacy strips use -- a clip too narrow to aim at keeps its whole + // padded box as a body to select and drag by instead (the `[`/`]` + // chords still trim it either way). + .children( + [Edge::Start, Edge::End] + .into_iter() + .filter(|_| trims(span)) + .map(|edge| { + let mut zone = div() + .absolute() + .top_0() + .h_full() + .w(px(EDGE_W)) + .occlude() + .cursor(CursorStyle::ResizeLeftRight) + .hover(|s| s.bg(rgb(INK1()))) + .on_mouse_down( + MouseButton::Left, + cx.listener(move |this, event: &MouseDownEvent, _, cx| { + this.start_trim(lane, idx, edge, event.modifiers.control, cx); + }), + ); + zone = match edge { + Edge::Start => zone.left_0(), + Edge::End => zone.right_0(), + }; + zone + }), + ) // Ink spine: 3px left edge, the source's own ink (hook above). .when(has_spine, |d| { d.child( @@ -354,14 +412,25 @@ fn lane_row( let dot = clips .first() .map_or_else(INK4, |clip| source_tint(clip.source)); + let head_ghost: SharedString = lane.label().into(); div() .id(("bench-lane", lane.ord * 10 + lane.kind as usize)) .flex_none() .h(px(h)) .flex() + // Dragged, the whole track moves in the stack (`LaneDrag`, + // `Player::reorder_lane`) -- let go anywhere along the row, not just + // over the head column, since a slot is what is being aimed at. + // corner-cut: no drop-line cue (module doc) -- a plain highlight + // while the pointer is over the row stands in for it. + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &LaneDrag, _, cx| { + this.reorder_lane(drag.0, lane, cx); + })) .child( // Pinned track head. div() + .id(("bench-lane-head", lane.ord * 10 + lane.kind as usize)) .flex_none() .w(px(HEAD_W)) .h_full() @@ -371,6 +440,10 @@ fn lane_row( .justify_center() .gap(px(2.)) .bg(rgb(DARK_PANEL())) + .cursor(CursorStyle::OpenHand) + .on_drag(LaneDrag(lane), move |_, _, _, cx| { + cx.new(|_| Tip(head_ghost.clone())) + }) // MOCK-SPEC.md "Bench": "V1, A1 in mono". .type_style(type_scale::mono( type_scale::CHORD_METADATA_MIN_PX, @@ -382,7 +455,8 @@ fn lane_row( ) .child( // The bed: a drop target for the Sources tab (`AssetDrag`, - // reused from `ui/timeline.rs`) and every clip on it. + // reused from `ui/timeline.rs`), a placed clip (`ClipDrag`) and + // every clip on it. div() .id(("bench-bed", lane.ord * 10 + lane.kind as usize)) .relative() @@ -397,6 +471,22 @@ fn lane_row( let at = this.place_frame(window.mouse_position().x).0; this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) })) + .drag_over::(|d, _, _, _| d.bg(rgb(DARK_RAISED()))) + .on_drop(cx.listener(move |this, drag: &ClipDrag, window, cx| { + let Some(idx) = this.dragged(drag) else { + return; + }; + this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx) + })) + // The wheel, matched to the legacy timeline's own mapping: + // ctrl+wheel zooms about the pointer, a bare wheel scrolls + // the bed along the film (`Player::timeline_wheel`). Stopped + // here so gpui's own overflow scroll on the lane column + // (`bench-lanes`) never answers the same notch a second time. + .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { + cx.stop_propagation(); + this.timeline_wheel(event, cx); + })) .children(boxes), ) } @@ -471,6 +561,13 @@ pub(crate) fn render(player: &mut Player, box_h: f32, cx: &mut Context) this.scrub_to(event.position.x, true, cx); }), ) + // Ctrl+wheel zooms about the pointer, a bare one scrolls the + // bed along -- the same mapping every bed below gives, and + // the legacy ruler's own (`ui/timeline.rs`'s + // `on_scroll_wheel` at its ruler strip). + .on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| { + this.timeline_wheel(event, cx); + })) .children(ticks.into_iter().map(|(x, label)| { div() .absolute() diff --git a/crates/app/src/ui/spine_stance.rs b/crates/app/src/ui/spine_stance.rs index e44b938..f8c6e85 100644 --- a/crates/app/src/ui/spine_stance.rs +++ b/crates/app/src/ui/spine_stance.rs @@ -226,6 +226,20 @@ pub(crate) fn render(player: &Player, cx: &mut Context) -> impl IntoElem player, cx, )) + // VIEW group, added this task: ZoomIn/ZoomOut/ZoomFit (keymap.rs) had + // real, already-working handlers (`Player::zoom`/`zoom_fit`, wired + // into the legacy `ui/toolbar.rs`) but no home anywhere in the + // darkroom -- a DESIGN §9 "nothing lives only on a key" violation. + // Placed between CUT and TRACK per §11 check 1 (task frequency): + // reading the timeline at a different scale happens many times a + // session (more than the once-per-project lane add below it), but + // less than walking/trimming cuts above it. + .child(group_head("view")) + .child(pair( + glyph("spine-zoom-out", "−", ActionId::ZoomOut, false, player, cx), + glyph("spine-zoom-in", "+", ActionId::ZoomIn, false, player, cx), + )) + .child(glyph("spine-zoom-fit", "⊡", ActionId::ZoomFit, false, player, cx)) .child(group_head("track")) .child(glyph("spine-add-video", "+V", ActionId::AddVideoLane, false, player, cx)) .child(glyph("spine-add-audio", "+A", ActionId::AddAudioLane, false, player, cx)) diff --git a/crates/app/src/ui/timeband_stance.rs b/crates/app/src/ui/timeband_stance.rs index fbe917a..241bd68 100644 --- a/crates/app/src/ui/timeband_stance.rs +++ b/crates/app/src/ui/timeband_stance.rs @@ -173,7 +173,7 @@ fn cut_readout(player: &Player) -> impl IntoElement { /// instead of `bench_stance`'s per-lane pixel scale -- the cheapest honest /// whole-film trace this app can draw without a new decode pass. Splice /// ticks (video-lane clip boundaries) still mark cut points on top of it. -fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement { +fn contact_strip(player: &Player, position: f64, cx: &mut Context) -> impl IntoElement { let duration = player.drawn_duration(); let view = player.view(); let (left_frac, width_frac) = if duration > 0. { @@ -230,9 +230,17 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement .h(px(28.)) .cursor_pointer() .tooltip(|_, cx| { - cx.new(|_| Tip("Contact strip — click jumps, drag pans the bench".into())) + cx.new(|_| Tip("Contact strip — drag scrubs the playhead, click jumps; drag the bracket's grips to pan the bench".into())) .into() }) + // Division of the plain drag (MOCK-SPEC "Contact strip", task's own + // instruction to decide honestly): a person reaches for this strip to + // move through the FILM far more often than to slide the bench's own + // viewport window, so the strip's own drag now scrubs the playhead + // continuously -- press-and-move is not just a jump on release. The + // bracket keeps panning, but only from its own grip notches + // (`viewport_bracket` below), which `stop_propagation` on their own + // press so a pan-start never also fires a scrub-jump underneath it. .on_mouse_down( MouseButton::Left, cx.listener({ @@ -243,30 +251,43 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement let frac = frac_along(event.position.x, bounds.get()); this.seek(f64::from(frac) * duration, cx); } - PAN_ANCHOR.with(|a| a.set(Some(f32::from(event.position.x)))); } }), ) - .on_mouse_move(cx.listener(move |this, event: &MouseMoveEvent, _, cx| { - let Some(last_x) = PAN_ANCHOR.with(Cell::get) else { - return; - }; - match event.pressed_button { - Some(MouseButton::Left) => { - let bounds = STRIP_BOUNDS.with(Rc::clone).get(); - let w = f32::from(bounds.size.width).max(1.); - let dx = f32::from(event.position.x) - last_x; - let duration = this.drawn_duration(); - if duration > 0. { - let delta = f64::from(dx / w) * duration; - let span = this.view().span(); - let max_start = (duration - span).max(0.); - this.scale.start = (this.scale.start + delta).clamp(0., max_start); + .on_mouse_move(cx.listener({ + let bounds = strip_bounds.clone(); + move |this, event: &MouseMoveEvent, _, cx| { + if event.pressed_button != Some(MouseButton::Left) { + PAN_ANCHOR.with(|a| a.set(None)); + return; + } + match PAN_ANCHOR.with(Cell::get) { + // A pan is live (started on the bracket's own grips): slide + // the bench viewport instead of the playhead. + Some(last_x) => { + let b = STRIP_BOUNDS.with(Rc::clone).get(); + let w = f32::from(b.size.width).max(1.); + let dx = f32::from(event.position.x) - last_x; + let duration = this.drawn_duration(); + if duration > 0. { + let delta = f64::from(dx / w) * duration; + let span = this.view().span(); + let max_start = (duration - span).max(0.); + this.scale.start = (this.scale.start + delta).clamp(0., max_start); + } + PAN_ANCHOR.with(|a| a.set(Some(f32::from(event.position.x)))); + } + // No pan armed: the plain drag scrubs, continuously + // reseeking to wherever the hand is along the strip. + None => { + let duration = this.drawn_duration(); + if duration > 0. { + let frac = frac_along(event.position.x, bounds.get()); + this.seek(f64::from(frac) * duration, cx); + } } - PAN_ANCHOR.with(|a| a.set(Some(f32::from(event.position.x)))); - cx.notify(); } - _ => PAN_ANCHOR.with(|a| a.set(None)), + cx.notify(); } })) .on_mouse_up( @@ -323,42 +344,63 @@ fn contact_strip(player: &Player, cx: &mut Context) -> impl IntoElement .border_l_1() .border_r_1() .border_color(rgb(INK1())) - .child( - div() - .absolute() - .left_0() - .top_0() - .w(px(2.)) - .h(px(6.)) - .bg(rgb(INK1())), - ) - .child( - div() - .absolute() - .left_0() - .bottom_0() - .w(px(2.)) - .h(px(6.)) - .bg(rgb(INK1())), - ) - .child( - div() - .absolute() - .right_0() - .top_0() - .w(px(2.)) - .h(px(6.)) - .bg(rgb(INK1())), - ) - .child( - div() - .absolute() - .right_0() - .bottom_0() - .w(px(2.)) - .h(px(6.)) - .bg(rgb(INK1())), - ), + .child(grip("stance-strip-grip-lt", true, true)) + .child(grip("stance-strip-grip-lb", true, false)) + .child(grip("stance-strip-grip-rt", false, true)) + .child(grip("stance-strip-grip-rb", false, false)), + ) + // The lamp-white playhead marker: this is what turns the strip from + // a trace into a slider with a handle (task's own wording) -- the + // one 1px line on the whole band that names *this* film moment, + // drawn last so it always sits above the trace and the bracket. + .when(duration > 0., |el| { + let frac = ((position / duration).clamp(0., 1.)) as f32; + el.child( + div() + .id("stance-strip-playhead") + .absolute() + .left(relative(frac)) + .top_0() + .h_full() + .w(px(1.)) + .bg(rgb(LAMP_WHITE())), + ) + }) +} + +/// One grip notch on the viewport bracket (MOCK-SPEC "grip notches"): the +/// only part of the contact strip that pans the bench window rather than +/// scrubbing the playhead (see [`contact_strip`]'s own doc on that split). +/// `stop_propagation` on its own press so starting a pan here never also +/// fires the strip's scrub-jump underneath it. +fn grip(id: &'static str, left: bool, top: bool) -> impl IntoElement { + div() + .id(id) + .absolute() + .when(left, |d| d.left(px(-3.))) + .when(!left, |d| d.right(px(-3.))) + .when(top, |d| d.top_0()) + .when(!top, |d| d.bottom_0()) + .w(px(8.)) + .h(px(10.)) + .cursor_col_resize() + .child( + div() + .absolute() + .when(left, |d| d.left(px(3.))) + .when(!left, |d| d.right(px(3.))) + .when(top, |d| d.top_0()) + .when(!top, |d| d.bottom_0()) + .w(px(2.)) + .h(px(6.)) + .bg(rgb(INK1())), + ) + .on_mouse_down( + MouseButton::Left, + move |event: &MouseDownEvent, _, cx| { + PAN_ANCHOR.with(|a| a.set(Some(f32::from(event.position.x)))); + cx.stop_propagation(); + }, ) } @@ -480,6 +522,6 @@ pub(crate) fn render(player: &mut Player, position: f64, cx: &mut Context