FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Timeline: a press on the ruler moves the playhead at once (#1090)
MarekSpodBiedryc05040c1c042
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex d5766c0bb..69271c7ad 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -1942,6 +1942,20 @@ pub(crate) fn wheel_input(ctx: &egui::Context) -> WheelInput {})}+/// Puts the playhead where the pointer is on the ruler: what a press does before any drag (#1090).+fn scrub_playhead(app: &mut FilmcraftApp, seq: &Sequence, layout: &Layout, p: Pos2, shift: bool) {+ app.stop();+ let mut tt = seq.settings.frame_rate.snap_nearest(layout.tick_at(p.x).max(Tick::ZERO));+ if shift || app.session.prefs.timeline.snap_playhead {+ tt = snap_playhead(app, seq, layout, tt);+ }+ // a press on a marker selects it: the playhead goes exactly onto it (#695)+ if let Some(m) = marker_at(seq, layout, p) {+ tt = m.max(Tick::ZERO);+ }+ app.session.set_playhead(tt);+}+fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &Layout, rect: Rect) {let ctx = ui.ctx().clone();let area = Rect::from_min_max(pos2(layout.content.min.x, layout.ruler.min.y), layout.content.max);@@ -1960,7 +1974,12 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &&& ctx.input(|i| i.pointer.primary_pressed())&& let Some(p) = ctx.input(|i| i.pointer.press_origin()){- app.tl.pressed = Some(Pressed { pos: p, tick: layout.tick_at(p.x), grab: grab_at(seq, layout, p, tool, mods, roll_ripple) });+ let grab = grab_at(seq, layout, p, tool, mods, roll_ripple);+ // the playhead jumps to a press on the ruler at once, not only once the pointer has moved (#1090)+ if matches!(grab, Grab::Other(Hit::Ruler)) {+ scrub_playhead(app, seq, layout, p, mods.shift);+ }+ app.tl.pressed = Some(Pressed { pos: p, tick: layout.tick_at(p.x), grab });}// ---- wheel, as in Premiere Pro on macOS (checked in 26.5.2):@@ -2183,16 +2202,7 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &};if let Some(d) = started {if matches!(d, Drag::Scrub) {- app.stop();- let mut tt = rate.snap_nearest(layout.tick_at(p.x).max(Tick::ZERO));- if mods.shift || app.session.prefs.timeline.snap_playhead {- tt = snap_playhead(app, seq, layout, tt);- }- // a press on a marker selects it: the playhead goes exactly onto it (#695)- if let Some(m) = marker_at(seq, layout, p) {- tt = m.max(Tick::ZERO);- }- app.session.set_playhead(tt);+ scrub_playhead(app, seq, layout, p, mods.shift);}if resp.drag_started() {app.tl.drag = Some(d);diff --git a/crates/ui-egui/tests/settings_ui.rs b/crates/ui-egui/tests/settings_ui.rsindex eca13d504..e82677464 100644--- a/crates/ui-egui/tests/settings_ui.rs+++ b/crates/ui-egui/tests/settings_ui.rs@@ -426,3 +426,38 @@ fn playhead_drag_snaps_to_cuts() {let ph = d.harness.state().session.playhead();assert!(ph > cut, "moves off the cut freely: {ph:?} vs {cut:?}");}++/// #1090: a press on the ruler moves the playhead there at once, before the pointer moves or the+/// button comes up, as in Premiere Pro.+#[test]+fn playhead_jumps_to_a_press_on_the_ruler() {+ let mut d = Driver::demo();+ d.frames(2);+ let seq = d.harness.state().session.active_sequence().unwrap().clone();+ let v1 = &seq.video_tracks[0];+ let cut = v1.items[1].start;+ let id = v1.items[1].id.0;+ let rect = |d: &mut Driver, id: &str| -> [f64; 4] {+ let v = d.ok("ui.elements", json!({"prefix": id}));+ let e = v.as_array().unwrap().iter().find(|e| e["id"] == id).unwrap_or_else(|| panic!("no element {id}")).clone();+ let r: Vec<f64> = e["rect"].as_array().unwrap().iter().map(|x| x.as_f64().unwrap()).collect();+ [r[0], r[1], r[2], r[3]]+ };+ let clip = rect(&mut d, &format!("timeline.clip.{id}"));+ let ruler = rect(&mut d, "timeline.ruler");+ d.exec("playhead.set", json!({"time": 0}));+ d.frames(2);+ assert_eq!(d.harness.state().session.playhead().0, 0);+ let p = egui::pos2((clip[0] + 40.0) as f32, (ruler[1] + ruler[3] / 2.0) as f32);+ let button = |d: &mut Driver, pressed: bool| {+ d.harness.input_mut().events.push(egui::Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() });+ d.frames(2);+ };+ d.harness.input_mut().events.push(egui::Event::PointerMoved(p));+ d.frames(1);+ button(&mut d, true);+ let ph = d.harness.state().session.playhead();+ assert!(ph > cut, "the playhead is under the pressed button: {ph:?} vs {cut:?}");+ button(&mut d, false);+ assert_eq!(d.harness.state().session.playhead(), ph, "the release leaves it there");+}