From e9c5f4b98b0fb750b3b297d172cf443354bf0f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 19 Aug 2026 23:28:19 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20the=20preview=20gets?= =?UTF-8?q?=20a=20scrub=20bar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The preview picture now carries its own seek track along its bottom: the played share drawn as a fill, a WCAG-tall hit area over a 6 px rail, and click or drag to jump anywhere in the file. It seeks through the ordinary `Player::seek`, so it lands on the preview session the way the keyboard step does and never disturbs the timeline underneath. Driven headlessly against a 100 s H.264 mp4: the fill advanced 1:35:01 -> 1:39:18 between two shots, a click at the bar's midpoint moved the clock 1:39:18 -> 0:50:02 with the picture changing, a drag 850 -> 300 px landed 0:09:01, and esc left the timeline region pixel-identical to its pre-preview shot (compare -metric AE = 0). --- crates/app/src/main.rs | 8 ++++ crates/app/src/player/library.rs | 1 + crates/app/src/player/timeline_edit.rs | 14 +++++++ crates/app/src/player/transport.rs | 20 +++++++++ crates/app/src/render.rs | 6 +++ crates/app/src/transport.rs | 57 ++++++++++++++++++++++++++ crates/app/src/ui/preview.rs | 53 ++++++++++++++++++++++++ 7 files changed, 159 insertions(+) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 2e1e893..4051f12 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -383,6 +383,12 @@ struct Player { /// arrive at the root, so the bar's own geometry has to be readable there. volume_bar: Rc>>, volume_dragging: bool, + /// Where the preview's own seek bar was last painted, and whether a hand + /// is on it -- `volume_bar`'s pair and `scrubbing`'s reason: the bar + /// spans the preview's whole length rather than a zoomed [`Scale`], so + /// it needs no `ruler` of its own, only its geometry. + preview_bar: Rc>>, + preview_scrubbing: bool, /// The two stand-in switches ([`engine::proxy`]) as this window has them /// set: whether the picture is cut on the stand-ins, and whether an /// arriving film gets one made for it. Kept here for the volume's reason @@ -720,6 +726,8 @@ fn main() { // handed is already set to: nothing to push at startup. volume: Volume::default(), volume_bar: Rc::default(), + preview_bar: Rc::default(), + preview_scrubbing: false, volume_dragging: false, // What a session comes up at, so the first one opened is // pushed the values it already holds. diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 2fad9fc..3126edf 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -185,6 +185,7 @@ impl Player { // timeline that has just stopped existing. self.scrubbing = false; self.volume_dragging = false; + self.preview_scrubbing = false; self.eq_dragging = false; self.speed_dragging = false; self.color_dragging = false; diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index f8aec6c..7ec5053 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1398,6 +1398,16 @@ impl Player { } return; } + // The preview's own scrub bar, tracked on the root for `scrubbing`'s + // reason: it is a short bar and the pointer leaves it at once. + if self.preview_scrubbing { + if event.pressed_button == Some(MouseButton::Left) { + self.preview_scrub_to(event.position.x, false, cx); + } else { + self.preview_scrubbing = false; + } + return; + } if !self.scrubbing { return; } @@ -1469,6 +1479,10 @@ impl Player { self.drag_volume(event.position.x, cx); return; } + if std::mem::take(&mut self.preview_scrubbing) { + self.preview_scrub_to(event.position.x, true, cx); + return; + } if std::mem::take(&mut self.scrubbing) { self.scrub_to(event.position.x, true, cx); } diff --git a/crates/app/src/player/transport.rs b/crates/app/src/player/transport.rs index 8ff02bd..5578750 100644 --- a/crates/app/src/player/transport.rs +++ b/crates/app/src/player/transport.rs @@ -252,6 +252,26 @@ impl Player { self.seek(target as f64 / fps, cx); } + /// [`scrub_to`](Player::scrub_to) for the preview's own seek bar: the + /// mapping is `preview_seek_seconds` rather than a `Scale`, because a + /// preview bar spans the file's whole length and never zooms. Seeks + /// through the ordinary [`Player::seek`], so it lands on + /// `preview_session` the same way the keyboard step does + /// ([`Player::active_session_mut`]) -- a preview's scrub never reaches + /// the timeline underneath it. + pub(crate) fn preview_scrub_to(&mut self, x: Pixels, commit: bool, cx: &mut Context) { + let Some(session) = self.preview_session.as_ref() else { + return; + }; + let t = preview_seek_seconds(x, self.preview_bar.get(), session.timeline_duration()); + let target = (t * self.active_fps()) as u32; + if commit || scrub_due(target, self.last_target, self.last_scrub.elapsed()) { + self.last_target = target; + self.last_scrub = Instant::now(); + self.seek(t, cx); + } + } + /// Seeks to where the pointer sits along the ruler. `commit` is the press /// and the release, which must land exactly even when the throttle below /// would have skipped them. diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index c76da72..a2e0105 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -656,6 +656,12 @@ impl Render for Player { // over it rather than under. .children(self.subtitle_overlay(position, window)) .children(self.preview_badge(cx)) + // The preview's own scrub bar, low over + // the picture the badge is drawn over the + // top of: drawn after both, so it sits + // above the subtitle plate and never + // under the badge's banner. + .children(self.preview_scrub_bar(cx)) // The three transient lines hang off the // bottom of the picture rather than taking // a row of the column: a notice that diff --git a/crates/app/src/transport.rs b/crates/app/src/transport.rs index ba11a20..4087ede 100644 --- a/crates/app/src/transport.rs +++ b/crates/app/src/transport.rs @@ -214,3 +214,60 @@ pub(crate) fn seek_line(standing: Option) -> Option { clock(since.as_secs_f32()) )) } + +/// Where along the preview's own seek bar a click landed, in seconds from +/// the start: [`frac_along`]'s fraction of `duration`, since the bar spans +/// the preview's whole length rather than a zoomed timeline `Scale` -- a +/// preview does not zoom, so there is no bed narrower than the file to map +/// into. +pub(crate) fn preview_seek_seconds(x: Pixels, bar: Bounds, duration: f64) -> f64 { + f64::from(frac_along(x, bar)) * duration.max(0.) +} + +/// How full the preview's seek bar is drawn, 0..1: the played share of the +/// duration, clamped for the same reason [`frac_along`] clamps a click -- a +/// clock a frame past the end must not overhang the track it is drawn on. +/// Zero for a duration of nothing, rather than a NaN from dividing by it. +pub(crate) fn preview_progress_along(now: f64, duration: f64) -> f32 { + if duration <= 0. { + return 0.; + } + (now / duration).clamp(0., 1.) as f32 +} + +#[cfg(test)] +mod tests { + use super::*; + + /// A click at either end of the bar lands exactly on the file's own + /// ends, the middle lands at half the duration, and a click past either + /// edge clamps to it rather than reading negative or past the end -- + /// `frac_along`'s own clamp, carried through. + #[test] + fn preview_seek_seconds_maps_the_bar_to_the_file() { + let bar = Bounds { + origin: point(px(100.), px(0.)), + size: size(px(200.), px(HIT_MIN)), + }; + assert_eq!(preview_seek_seconds(px(100.), bar, 60.), 0.); + assert_eq!(preview_seek_seconds(px(300.), bar, 60.), 60.); + assert_eq!(preview_seek_seconds(px(200.), bar, 60.), 30.); + // Off both ends -- the pointer left the bar, and the seek clamps to + // the end it left through. + assert_eq!(preview_seek_seconds(px(0.), bar, 60.), 0.); + assert_eq!(preview_seek_seconds(px(500.), bar, 60.), 60.); + } + + /// The fill tracks the played share exactly, and a duration of nothing + /// -- no file open yet -- reads as an empty bar rather than a divide by + /// zero. + #[test] + fn preview_progress_along_is_the_played_share() { + assert_eq!(preview_progress_along(0., 60.), 0.); + assert_eq!(preview_progress_along(30., 60.), 0.5); + assert_eq!(preview_progress_along(60., 60.), 1.); + // Past the end clamps rather than overhanging the track. + assert_eq!(preview_progress_along(61., 60.), 1.); + assert_eq!(preview_progress_along(5., 0.), 0.); + } +} diff --git a/crates/app/src/ui/preview.rs b/crates/app/src/ui/preview.rs index a7bc3a1..019220f 100644 --- a/crates/app/src/ui/preview.rs +++ b/crates/app/src/ui/preview.rs @@ -37,6 +37,59 @@ impl Player { }) } + /// The preview's own scrub bar, drawn low over the picture the way the + /// badge is drawn over its top: a preview has a duration and a playhead + /// like anything else on screen, and unlike the timeline's ruler + /// ([`Player::seek_bar`] is a different bar entirely, the "still + /// seeking" status line) it is the only way to jump around one with a + /// mouse -- `esc` and the arrow keys are the keyboard's own doors. + /// + /// The hit area is `RULER_HIT_H` (`HIT_MIN`, WCAG 2.5.8) tall and centred + /// on a 6 px track, the ruler's own idiom: a bar thin enough to read is + /// too thin to reliably click. + pub(crate) fn preview_scrub_bar(&self, cx: &mut Context) -> Option { + let session = self.preview_session.as_ref()?; + let filled = preview_progress_along(session.now(), session.timeline_duration()); + Some( + div() + .id("preview-scrub") + .absolute() + .left_0() + .right_0() + .bottom_0() + .h(px(RULER_HIT_H)) + .flex() + .flex_col() + .justify_center() + .px(px(8.)) + .cursor_pointer() + .tooltip(|_, cx| cx.new(|_| Tip("Seek — click or drag".into())).into()) + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, event: &MouseDownEvent, _, cx| { + this.preview_scrubbing = true; + this.preview_scrub_to(event.position.x, true, cx); + }), + ) + .child( + div() + .relative() + .w_full() + .h(px(6.)) + .rounded(px(3.)) + .bg(rgba(SUB_SHADE())) + .child(bounds_probe(self.preview_bar.clone())) + .child( + div() + .h_full() + .w(relative(filled)) + .rounded(px(3.)) + .bg(rgb(ACCENT_PRIMARY())), + ), + ), + ) + } + /// The frame on screen right now, written to a PNG: `image` and its /// `as_bytes` are gpui's own cached copy of what was last handed to the /// atlas ([`Player::pump`]), so this reads no decoder and races nothing --