Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat(phone): the lanes glide after a throw, pinch to zoom, and a tap selects without seeking (#350, #243, #221)

Jareer6016c01d6988
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 10f5caa1..64604b93 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -969,7 +969,13 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::
state.move_keys_at(from, to);
}));
editor.on_scrubbed(on_lanes!(|state, seconds: f32| {
- state.seek(seconds.max(0.0));
+ state.scrub(seconds);
+ }));
+ editor.on_finger_held(on_lanes!(|state| {
+ state.finger_held();
+ }));
+ editor.on_finger_lifted(on_lanes!(|state| {
+ state.finger_lifted();
}));
editor.on_scrolled(on_lanes!(|state, seconds: f32| {
state.handle(Msg::Timeline(TimelineMsg::Scrolled(seconds)));
@@ -1228,10 +1234,12 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::
// ── the monitor ──
editor.on_seek(on_lanes!(|state, seconds: f32| {
+ state.stop_glide();
state.pause();
state.seek(seconds);
}));
editor.on_step_frames(on_lanes!(|state, frames: f32| {
+ state.stop_glide();
state.pause();
let fps = state.frame_rate().round().max(1.0);
let at = (state.playhead * fps).round() + frames;
diff --git a/src/crates/concat/src/panes/glide.rs b/src/crates/concat/src/panes/glide.rs
new file mode 100644
index 00000000..92c55f33
--- /dev/null
+++ b/src/crates/concat/src/panes/glide.rs
@@ -0,0 +1,312 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+//! The phone's lanes keep moving after the finger lets go.
+//!
+//! On a phone the lanes slide under a playhead held at their middle, and a
+//! drag along them is a scrub. A scrub that stopped dead the instant the
+//! finger left the glass read as sluggish next to every other list on the
+//! phone, which carries on at the speed it was thrown and slows to a stop.
+//! This is that: how fast the finger was going when it let go, and how the
+//! lanes run down from there.
+//!
+//! Both halves are pure - time is a number of seconds from any origin the
+//! caller likes - so they are tested here; the studio holds the timer that
+//! drives a glide and the clock that stamps the samples.
+
+use std::collections::VecDeque;
+use std::time::Instant;
+
+/// How far back a release looks for the finger's speed. A tenth of a
+/// second is Android's and iOS's own window: long enough to smooth a
+/// jittery sample or two, short enough that a drag which slowed before
+/// letting go is not thrown at the speed it had earlier.
+const HORIZON: f64 = 0.1;
+/// A finger that has not moved for this long before it lifts was held
+/// still, and lets go without throwing anything - however fast it went
+/// before it stopped. Android's figure.
+const STOPPED: f64 = 0.04;
+/// The most samples kept; at a touchscreen's 120 Hz a tenth of a second
+/// is a dozen, and an old one falls out the moment a new one comes in.
+const KEPT: usize = 32;
+
+/// The run-down: the speed falls by `e` every `TAU` seconds - 0.95 a
+/// 16 ms frame, the friction of a phone's own lists - so a throw at
+/// 3000 px/s travels about a thousand pixels before it stops.
+pub const TAU: f64 = 0.312;
+/// Slower than this, in pixels a second, a release is a lift, not a throw.
+pub const MIN_THROW: f64 = 60.0;
+/// The fastest throw honoured: a flick across a small screen can measure
+/// absurd speeds from two samples a millisecond apart.
+pub const MAX_THROW: f64 = 8000.0;
+/// A glide slower than this has stopped: under a pixel every two frames.
+pub const MIN_SPEED: f64 = 20.0;
+
+/// The finger's recent positions, and its speed from them.
+#[derive(Default)]
+pub struct Tracker {
+ /// (when, where): seconds, and the position along the lanes in
+ /// whatever unit the caller tracks - the speed comes back in that
+ /// unit per second.
+ samples: VecDeque<(f64, f64)>,
+}
+
+impl Tracker {
+ /// A new gesture: the last one's samples say nothing about this one.
+ pub fn clear(&mut self) {
+ self.samples.clear();
+ }
+
+ /// The finger was at `position` at time `at`.
+ pub fn push(&mut self, at: f64, position: f64) {
+ if !(at.is_finite() && position.is_finite()) {
+ return;
+ }
+ // Out of order is a clock gone wrong; start again from here.
+ if self.samples.back().is_some_and(|&(last, _)| at < last) {
+ self.samples.clear();
+ }
+ if self.samples.len() == KEPT {
+ self.samples.pop_front();
+ }
+ self.samples.push_back((at, position));
+ }
+
+ /// The speed at time `now`, the moment of the release: the slope of
+ /// the least-squares line through the samples of the last `HORIZON`,
+ /// which a single late or early sample cannot swing the way the
+ /// difference of the last two can. Zero when the finger had stopped
+ /// before it lifted, or there is too little to tell by.
+ pub fn velocity(&self, now: f64) -> f64 {
+ let Some(&(newest, _)) = self.samples.back() else {
+ return 0.0;
+ };
+ if now - newest > STOPPED {
+ return 0.0;
+ }
+ let recent: Vec<(f64, f64)> = self
+ .samples
+ .iter()
+ .copied()
+ .filter(|&(at, _)| newest - at <= HORIZON)
+ .collect();
+ if recent.len() < 2 {
+ return 0.0;
+ }
+ let n = recent.len() as f64;
+ let mean_t = recent.iter().map(|&(at, _)| at).sum::<f64>() / n;
+ let mean_x = recent.iter().map(|&(_, x)| x).sum::<f64>() / n;
+ let (mut covariance, mut variance) = (0.0, 0.0);
+ for &(at, x) in &recent {
+ covariance += (at - mean_t) * (x - mean_x);
+ variance += (at - mean_t) * (at - mean_t);
+ }
+ // All the samples at one instant: a speed cannot be told.
+ if variance < 1e-9 {
+ return 0.0;
+ }
+ covariance / variance
+ }
+}
+
+/// One throw running down: where it has got to, by the clock.
+///
+/// Time-based rather than a fixed factor per tick, so a timer that fires
+/// late - a busy frame, a phone throttling itself - moves the lanes as far
+/// as they would have gone, and the glide takes the same time on a 60 Hz
+/// screen as on a 120 Hz one.
+#[derive(Clone, Copy, Debug)]
+pub struct Glide {
+ /// The speed it was thrown at, in pixels a second; the sign is the
+ /// direction.
+ speed: f64,
+ /// Pixels travelled as of the last step.
+ travelled: f64,
+}
+
+impl Glide {
+ /// A throw at `speed` pixels a second, or None when that is too slow
+ /// to be one. Clamped to `MAX_THROW`.
+ pub fn thrown(speed: f64) -> Option<Self> {
+ if !speed.is_finite() || speed.abs() < MIN_THROW {
+ return None;
+ }
+ Some(Self {
+ speed: speed.clamp(-MAX_THROW, MAX_THROW),
+ travelled: 0.0,
+ })
+ }
+
+ /// Pixels travelled `elapsed` seconds after the throw.
+ pub fn distance(speed: f64, elapsed: f64) -> f64 {
+ speed * TAU * (1.0 - (-elapsed.max(0.0) / TAU).exp())
+ }
+
+ /// The speed `elapsed` seconds after the throw.
+ pub fn speed_at(speed: f64, elapsed: f64) -> f64 {
+ speed * (-elapsed.max(0.0) / TAU).exp()
+ }
+
+ /// The pixels to move since the last step, `elapsed` seconds after the
+ /// throw, and whether the glide is still going after them.
+ pub fn step(&mut self, elapsed: f64) -> (f64, bool) {
+ let to = Self::distance(self.speed, elapsed);
+ let moved = to - self.travelled;
+ self.travelled = to;
+ (moved, Self::speed_at(self.speed, elapsed).abs() >= MIN_SPEED)
+ }
+}
+
+/// A throw as the studio keeps it: the samples of the drag in progress,
+/// and the glide running, if one is. The clock lives here so the samples
+/// and the glide read the same one.
+pub struct Coast {
+ pub tracker: Tracker,
+ /// A finger is on the lanes, and the scrubs it makes are its samples.
+ pub tracking: bool,
+ /// The glide, when it was thrown, and the furthest it may go: the end
+ /// of the cut, or where it started if that was already past it.
+ pub glide: Option<(Glide, Instant, f32)>,
+ epoch: Instant,
+}
+
+impl Default for Coast {
+ fn default() -> Self {
+ Self {
+ tracker: Tracker::default(),
+ tracking: false,
+ glide: None,
+ epoch: Instant::now(),
+ }
+ }
+}
+
+impl Coast {
+ /// Seconds since the studio began: the samples' clock.
+ pub fn clock(&self) -> f64 {
+ self.epoch.elapsed().as_secs_f64()
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn a_steady_drag_measures_its_speed() {
+ let mut tracker = Tracker::default();
+ // 1200 px/s, sampled every 8 ms for a fifth of a second.
+ for step in 0..25 {
+ let at = f64::from(step) * 0.008;
+ tracker.push(at, 1200.0 * at);
+ }
+ let speed = tracker.velocity(0.192 + 0.005);
+ assert!((speed - 1200.0).abs() < 1e-6, "{speed}");
+ }
+
+ #[test]
+ fn only_the_last_tenth_of_a_second_counts() {
+ let mut tracker = Tracker::default();
+ // Fast, then slow for the last 120 ms: the release is slow.
+ let mut x = 0.0;
+ for step in 0..30 {
+ let at = f64::from(step) * 0.01;
+ x += if at < 0.18 { 30.0 } else { 2.0 };
+ tracker.push(at, x);
+ }
+ let speed = tracker.velocity(0.29);
+ assert!((speed - 200.0).abs() < 1.0, "{speed}");
+ }
+
+ #[test]
+ fn a_finger_held_still_before_it_lifts_throws_nothing() {
+ let mut tracker = Tracker::default();
+ for step in 0..10 {
+ let at = f64::from(step) * 0.01;
+ tracker.push(at, 2000.0 * at);
+ }
+ assert!(tracker.velocity(0.09 + 0.01) > 1000.0);
+ // The same drag, lifted 60 ms after its last move.
+ assert_eq!(tracker.velocity(0.09 + 0.06), 0.0);
+ }
+
+ #[test]
+ fn a_jittery_sample_does_not_swing_the_speed() {
+ let mut tracker = Tracker::default();
+ for step in 0..12 {
+ let at = f64::from(step) * 0.008;
+ // Every third sample a frame late in its stamp: the position is
+ // right, the time is not.
+ let stamp = if step % 3 == 2 { at + 0.004 } else { at };
+ tracker.push(stamp, -900.0 * at);
+ }
+ let speed = tracker.velocity(0.09);
+ assert!((speed + 900.0).abs() < 150.0, "{speed}");
+ }
+
+ #[test]
+ fn too_little_to_tell_by_is_no_speed() {
+ let mut tracker = Tracker::default();
+ assert_eq!(tracker.velocity(0.0), 0.0);
+ tracker.push(1.0, 10.0);
+ assert_eq!(tracker.velocity(1.0), 0.0);
+ tracker.push(1.0, 50.0);
+ assert_eq!(tracker.velocity(1.0), 0.0, "two samples at one instant");
+ tracker.push(f64::NAN, 3.0);
+ tracker.clear();
+ assert_eq!(tracker.velocity(1.0), 0.0);
+ // A clock that runs backwards starts the samples again.
+ tracker.push(2.0, 0.0);
+ tracker.push(2.01, 10.0);
+ tracker.push(1.0, 0.0);
+ assert_eq!(tracker.velocity(1.0), 0.0);
+ }
+
+ #[test]
+ fn a_throw_runs_down_and_stops() {
+ let mut glide = Glide::thrown(3000.0).expect("a throw");
+ // 0.95 a 16 ms frame.
+ let ratio = Glide::speed_at(1.0, 0.016);
+ assert!((ratio - 0.95).abs() < 0.002, "{ratio}");
+ let mut total = 0.0;
+ let mut frames = 0;
+ loop {
+ frames += 1;
+ let (moved, going) = glide.step(f64::from(frames) * 0.016);
+ assert!(moved > 0.0, "always forward");
+ total += moved;
+ if !going {
+ break;
+ }
+ assert!(frames < 200, "a glide ends");
+ }
+ // It covers nearly all of speed × TAU, and in about a second and
+ // a half: ln(3000 / 20) × TAU.
+ assert!(total > 0.99 * 3000.0 * TAU && total <= 3000.0 * TAU, "{total}");
+ assert!((90..=100).contains(&frames), "{frames}");
+ }
+
+ #[test]
+ fn a_late_timer_moves_as_far_as_a_punctual_one() {
+ let mut punctual = Glide::thrown(-2000.0).expect("a throw");
+ let mut late = Glide::thrown(-2000.0).expect("a throw");
+ let mut on_time = 0.0;
+ for frame in 1..=30 {
+ on_time += punctual.step(f64::from(frame) * 0.016).0;
+ }
+ // The late one fires twice, the second time very late.
+ let lagging = late.step(0.1).0 + late.step(0.48).0;
+ assert!((on_time - lagging).abs() < 1e-9, "{on_time} {lagging}");
+ assert!(on_time < 0.0, "backwards stays backwards");
+ }
+
+ #[test]
+ fn a_slow_release_is_no_throw_and_a_wild_one_is_capped() {
+ assert!(Glide::thrown(MIN_THROW / 2.0).is_none());
+ assert!(Glide::thrown(-MIN_THROW / 2.0).is_none());
+ assert!(Glide::thrown(f64::NAN).is_none());
+ let mut wild = Glide::thrown(1e7).expect("a throw");
+ let (moved, _) = wild.step(10.0);
+ assert!(moved <= MAX_THROW * TAU + 1e-6, "{moved}");
+ }
+}
diff --git a/src/crates/concat/src/panes/mod.rs b/src/crates/concat/src/panes/mod.rs
index d9b9ded1..0511a79b 100644
--- a/src/crates/concat/src/panes/mod.rs
+++ b/src/crates/concat/src/panes/mod.rs
@@ -16,6 +16,7 @@
pub mod captions;
pub mod export;
+pub mod glide;
pub mod media_bin;
pub mod monitor;
pub mod pace;
diff --git a/src/crates/concat/src/panes/timeline.rs b/src/crates/concat/src/panes/timeline.rs
index 578fcf83..da8c1736 100644
--- a/src/crates/concat/src/panes/timeline.rs
+++ b/src/crates/concat/src/panes/timeline.rs
@@ -346,6 +346,42 @@ mod tests {
assert_eq!(view.scroll_left, 0.0);
}
+ /// What the lanes' pinch sends: Slint's scale since the fingers landed,
+ /// turned into the step since the last update.
+ fn pinch(view: &mut TimelinePane, scales: &[f32], anchor: f32) {
+ let mut last = 1.0;
+ for &scale in scales {
+ view.zoom(last / scale, anchor);
+ view.recentre(3.0);
+ last = scale;
+ }
+ }
+
+ #[test]
+ fn a_pinch_zooms_by_its_whole_scale_about_the_fingers() {
+ // On a desk: the instant between the fingers stays between them.
+ let mut view = pane(1000.0, 10.0, 0.1);
+ let before = (20.0 - view.scroll_left) / view.seconds_per_pixel;
+ pinch(&mut view, &[1.1, 1.3, 1.25, 2.0], 20.0);
+ assert!((view.seconds_per_pixel - 0.05).abs() < 1e-6, "{}", view.seconds_per_pixel);
+ let after = (20.0 - view.scroll_left) / view.seconds_per_pixel;
+ assert!((before - after).abs() < 1e-2, "{before} {after}");
+ // Spread past the closest zoom and back: held at the limit, and
+ // turning back zooms out at once rather than after a dead stretch.
+ pinch(&mut view, &[1e4, 5e3], 20.0);
+ assert!(view.seconds_per_pixel > ZOOM_IN_LIMIT);
+ assert!((view.seconds_per_pixel - 2.0 * ZOOM_IN_LIMIT).abs() < 1e-6);
+
+ // On a phone: whatever the fingers' middle, the playhead stays at
+ // the lanes' middle, as the zoom buttons keep it.
+ let mut phone = pane(400.0, 0.0, 0.05);
+ phone.centred = true;
+ phone.recentre(3.0);
+ pinch(&mut phone, &[0.8, 0.5], 9.0);
+ assert!((phone.seconds_per_pixel - 0.1).abs() < 1e-6);
+ assert!(((3.0 - phone.scroll_left) / phone.seconds_per_pixel - 200.0).abs() < 1e-3);
+ }
+
#[test]
fn zoom_keeps_the_anchor_under_the_pointer_and_stays_in_range() {
let mut view = pane(1000.0, 10.0, 0.1);
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index 8873c3ec..525cbd9d 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -818,6 +818,10 @@ pub struct Studio {
pub playhead: f32,
pub playing: bool,
transport: slint::Timer,
+ /// The phone's lanes carrying on after a finger throws them, and the
+ /// beat that moves them while they do; see `panes::glide`.
+ coast: crate::panes::glide::Coast,
+ glide_beat: slint::Timer,
/// The preview axis: the instant under the pointer while it crosses the
/// lanes, which the monitor shows instead of the playhead's. None when
/// the pointer is elsewhere, or the axis is off, or the cut is playing.
@@ -2170,6 +2174,8 @@ impl Studio {
// ~20px a second: a ten-second cut fits a pane at its default width.
playing: false,
transport: slint::Timer::default(),
+ coast: crate::panes::glide::Coast::default(),
+ glide_beat: slint::Timer::default(),
hover: None,
hover_hush: slint::Timer::default(),
clipboard: Vec::new(),
@@ -2864,6 +2870,7 @@ impl Studio {
// ── playback ──
pub fn play_toggle(&mut self) {
+ self.stop_glide();
// The monitor's play button and Space play what it shows.
if self.source.is_some() {
self.source_toggle();
@@ -2972,6 +2979,88 @@ impl Studio {
self.request_preview();
}
+ // ── the phone's throw ──
+
+ /// A finger landed on the phone's lanes, or two began a pinch: a glide
+ /// still running stops where it is, the way a list does under a
+ /// thumb, and the scrubs from here are the new gesture's samples.
+ pub fn finger_held(&mut self) {
+ self.stop_glide();
+ self.coast.tracker.clear();
+ self.coast.tracking = true;
+ }
+
+ /// A scrub: the playhead goes to `seconds`, and while a finger is on
+ /// the phone's lanes, where it went is a sample of how fast they move.
+ pub fn scrub(&mut self, seconds: f32) {
+ self.seek(seconds.max(0.0));
+ if self.coast.tracking {
+ let at = self.coast.clock();
+ self.coast.tracker.push(at, f64::from(self.playhead));
+ }
+ }
+
+ /// The finger that dragged the phone's lanes along the cut has let go:
+ /// they carry on at its speed and run down, scrubbing as they go.
+ /// Nothing while playing - the transport owns the playhead then - and
+ /// nothing for a finger that stopped before it lifted.
+ pub fn finger_lifted(&mut self) {
+ let tracking = std::mem::replace(&mut self.coast.tracking, false);
+ if !tracking || self.playing || !self.lanes.centred {
+ return;
+ }
+ // Thrown in pixels, so the friction and the thresholds mean the
+ // same at every zoom; each step goes back to seconds at the zoom
+ // of the moment.
+ let per_pixel = f64::from(self.lanes.seconds_per_pixel.max(1e-6));
+ let speed = self.coast.tracker.velocity(self.coast.clock()) / per_pixel;
+ let Some(glide) = crate::panes::glide::Glide::thrown(speed) else {
+ return;
+ };
+ let limit = self.duration().max(self.playhead);
+ self.coast.glide = Some((glide, std::time::Instant::now(), limit));
+ // A beat a frame, only while it moves: nothing is drawn for a glide
+ // that is not running.
+ self.glide_beat.start(
+ slint::TimerMode::Repeated,
+ std::time::Duration::from_millis(16),
+ || {
+ crate::host::Shell::with(|shell, app| {
+ shell.studio.borrow_mut().glide_step();
+ shell.studio.borrow_mut().refresh_art();
+ shell.studio.borrow().publish_lanes(&app, &shell.models);
+ });
+ },
+ );
+ }
+
+ /// One beat of a glide: as far as it has run since the last, never
+ /// before the start of the cut or past `limit`, and the end of it
+ /// when it has slowed to nothing or reached either.
+ fn glide_step(&mut self) {
+ let Some((mut glide, since, limit)) = self.coast.glide else {
+ self.glide_beat.stop();
+ return;
+ };
+ let (moved, going) = glide.step(since.elapsed().as_secs_f64());
+ let per_pixel = f64::from(self.lanes.seconds_per_pixel);
+ let wanted = f64::from(self.playhead) + moved * per_pixel;
+ let limit = f64::from(limit);
+ let reached = wanted <= 0.0 || wanted >= limit;
+ self.seek(wanted.clamp(0.0, limit) as f32);
+ if going && !reached {
+ self.coast.glide = Some((glide, since, limit as f32));
+ } else {
+ self.stop_glide();
+ }
+ }
+
+ /// Ends a glide, if one is running.
+ pub fn stop_glide(&mut self) {
+ self.coast.glide = None;
+ self.glide_beat.stop();
+ }
+
// ── the preview axis ──
/// The instant the monitor shows: the pointer's while it crosses the
diff --git a/src/crates/concat/ui/editor.slint b/src/crates/concat/ui/editor.slint
index 67f2a15e..ca017b0f 100644
--- a/src/crates/concat/ui/editor.slint
+++ b/src/crates/concat/ui/editor.slint
@@ -396,6 +396,12 @@ export global Editor {
/// decides which clips are worth publishing.
callback lanes-resized(width: float);
callback scrubbed(seconds: float);
+ /// A finger landed on a phone's lanes, or two began a pinch: a glide
+ /// still running stops.
+ callback finger-held();
+ /// The finger dragging a phone's lanes along the cut let go: they
+ /// carry on at its speed and run down.
+ callback finger-lifted();
/// A ruler diamond was dragged: every key at `from` moves to `to`.
callback key-mark-moved(from: float, to: float);
callback clip-pressed(id: string, additive: bool, edge: int);
diff --git a/src/crates/concat/ui/phone/editor.slint b/src/crates/concat/ui/phone/editor.slint
index 36ec063f..e2300cde 100644
--- a/src/crates/concat/ui/phone/editor.slint
+++ b/src/crates/concat/ui/phone/editor.slint
@@ -34,9 +34,11 @@ import { PhoneSheet } from "sheet.slint";
// - the monitor, which takes whatever height the rest leaves;
// - the transport: where the playhead is, Play, undo and redo;
// - the lanes, with the playhead held at their middle and the cut
-// sliding under it - a drag scrubs, a tap on a clip selects it, a
-// tap on empty lane lets go, a clip dragged moves (see `finger` in
-// lanes.slint, and `centred` in the timeline pane on the Rust side);
+// sliding under it - a drag scrubs and a throw glides on, two fingers
+// pinch the zoom, a tap on a clip selects it where it is, a tap on
+// empty lane lets go, a clip dragged moves (see `finger` in
+// lanes.slint, `centred` in the timeline pane on the Rust side, and
+// the glide beside it);
// - the bar of tools. With nothing selected it is the library's pages
// and the project's verbs; with a clip selected it is the clip's
// verbs, with a way back at its head.
@@ -164,8 +166,8 @@ component Fact inherits HorizontalLayout {
}
}
-/// A round chip over the lanes: the zoom, since a finger cannot pinch
-/// here - Slint sees one finger at a time.
+/// A round chip over the lanes: the zoom, for a thumb that has no second
+/// finger free to pinch with.
component LaneChip inherits Rectangle {
in property <Glyph> glyph;
in property <string> label;
@@ -560,6 +562,8 @@ export component PhoneEditor inherits Rectangle {
Editor.blur();
Editor.scrubbed(seconds);
}
+ finger-held => { Editor.finger-held(); }
+ finger-lifted => { Editor.finger-lifted(); }
key-mark-moved(from, to) => { Editor.key-mark-moved(from, to); }
hovered(seconds) => { Editor.hovered(seconds); }
hover-ended => { Editor.hover-ended(); }
diff --git a/src/crates/concat/ui/timeline/lanes.slint b/src/crates/concat/ui/timeline/lanes.slint
index d81a783b..7f2238dd 100644
--- a/src/crates/concat/ui/timeline/lanes.slint
+++ b/src/crates/concat/ui/timeline/lanes.slint
@@ -1148,6 +1148,12 @@ export component Lanes inherits Rectangle {
callback scrolled(seconds: float);
callback track-scrolled(pixels: length);
callback zoomed(factor: float, anchor-seconds: float);
+ /// A finger landed on the lanes, or two began a pinch: whatever was
+ /// still gliding stops. Only with `finger`.
+ callback finger-held();
+ /// The finger that dragged the lanes along the cut let go, moving:
+ /// they carry on at its speed. Only with `finger`.
+ callback finger-lifted();
/// A drag from the library is over the lanes at this moment and this
/// place. Asked on every move of it, because the answer — the ghost below
@@ -1179,8 +1185,12 @@ export component Lanes inherits Rectangle {
property <length> finger-x;
property <length> finger-y;
property <length> finger-last-y;
+ /// Which finger it is, as Slint numbers them; see `finger-up`.
+ property <int> finger-id;
- function finger-down(x: length, y: length) {
+ function finger-down(x: length, y: length, id: int) {
+ root.finger-held();
+ root.finger-id = id;
root.finger-axis = 0;
root.finger-playhead = root.playhead;
root.finger-x = x;
@@ -1207,6 +1217,23 @@ export component Lanes inherits Rectangle {
root.finger-last-y = y;
}
}
+ /// The surface the finger pressed has been let go of, by finger `id`;
+ /// true when that was a tap. A drag along the cut is thrown, and the
+ /// lanes glide on from where it let go.
+ ///
+ /// A second finger landing lets go of the first too: Slint releases
+ /// the first so a pinch can begin, and numbers that release with the
+ /// second finger's id - which is how it is told from a real lift, and
+ /// why it is neither a tap nor a throw.
+ function finger-up(id: int) -> bool {
+ if (id != root.finger-id) {
+ return false;
+ }
+ if (root.finger-axis == 1) {
+ root.finger-lifted();
+ }
+ return root.finger-axis == 0;
+ }
// ── scrolling at the edge ─────────────────────────────────────────
// A scrub or a clip drag that reaches the lanes' edge scrolls the view
@@ -1262,6 +1289,34 @@ export component Lanes inherits Rectangle {
background: Theme.lane;
clip: true;
+ // Two fingers pinched, or a trackpad's pinch: the zoom, through the
+ // same `zoomed` the wheel and the buttons use, so it has their limits.
+ // Slint numbers the gesture as one scale since it began; each update
+ // is turned into the step since the last one, so the zoom moves with
+ // the fingers whatever it was when they landed. About the fingers'
+ // middle on a desk; a phone's lanes hold the playhead at theirs, and
+ // zoom about that (see `TimelinePane::recentre`).
+ //
+ // Under the wheel, not around it: every surface there turns a pinch
+ // down, and a pinch turned down falls through to what is beneath. A
+ // clip or the floor still has the first finger until the second lands.
+ pinch := ScaleRotateGestureHandler {
+ property <float> last-scale: 1;
+
+ started => {
+ self.last-scale = 1;
+ if (root.finger) {
+ root.finger-held();
+ }
+ }
+ updated => {
+ if (self.scale > 0 && self.last-scale > 0) {
+ root.zoomed(self.last-scale / self.scale, root.seconds-at(self.center.x));
+ self.last-scale = self.scale;
+ }
+ }
+ }
+
// Ancestor of everything below, so a wheel the clips do not handle bubbles
// up to here. A sibling would not see it.
wheel := TouchArea {
@@ -1375,7 +1430,7 @@ export component Lanes inherits Rectangle {
self.to-x = self.mouse-x;
self.to-y = self.mouse-y;
if (root.finger) {
- root.finger-down(self.mouse-x, self.mouse-y);
+ root.finger-down(self.mouse-x, self.mouse-y, event.touch-finger-id);
} else {
self.drawing = true;
}
@@ -1398,8 +1453,8 @@ export component Lanes inherits Rectangle {
root.stack-y(Math.min(self.from-y, self.to-y)),
root.stack-y(Math.max(self.from-y, self.to-y)),
self.additive);
- } else if (root.finger && root.finger-axis == 0
- && event.kind == PointerEventKind.up) {
+ } else if (root.finger && event.kind == PointerEventKind.up
+ && root.finger-up(event.touch-finger-id)) {
// A tap on an empty lane: the playhead goes there,
// and the empty band a press that never moved would
// have closed clears the selection.
@@ -1456,6 +1511,9 @@ export component Lanes inherits Rectangle {
// clip by the last drag's distance.
// https://github.com/jub0t/Concat/issues/247
pressed(additive, edge) => {
+ if (root.finger) {
+ root.finger-held();
+ }
root.press-scroll = root.scroll-left;
root.drag-seconds = 0;
root.drag-pixels = 0;
@@ -1482,7 +1540,17 @@ export component Lanes inherits Rectangle {
}
// Click anywhere on the timeline and the playhead goes there,
// a clip included: it is selected and the playhead lands on it.
- clicked(x) => { root.scrubbed(Math.max(0, root.seconds-at(self.x + x))); }
+ // Not under a finger: the lanes are held at the playhead there,
+ // and a tap that moved it would slide the whole cut half a
+ // screen to bring the clip to the middle - the clip tapped
+ // would leap away from the thumb that tapped it. A tap selects;
+ // the lanes stay where they were, the way they do in every
+ // phone editor.
+ clicked(x) => {
+ if (!root.finger) {
+ root.scrubbed(Math.max(0, root.seconds-at(self.x + x)));
+ }
+ }
hovered(x) => { root.hover-at(self.x + x); }
hover-ended => { root.hover-off(); }
context-requested => {
@@ -1667,9 +1735,9 @@ export component Lanes inherits Rectangle {
// The ruler slides with the lanes under a finger;
// a tap on it goes to the instant tapped.
if (event.kind == PointerEventKind.down) {
- root.finger-down(self.mouse-x, self.mouse-y);
+ root.finger-down(self.mouse-x, self.mouse-y, event.touch-finger-id);
} else if (event.kind == PointerEventKind.up
- && root.finger-axis == 0) {
+ && root.finger-up(event.touch-finger-id)) {
root.scrubbed(Math.max(0, root.seconds-at(self.mouse-x)));
}
return;