diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs index 5acf13b487..4406f01e22 100644 --- a/crates/engine/src/prefs.rs +++ b/crates/engine/src/prefs.rs @@ -993,7 +993,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &[ "workspace.autoShowHiddenPanels", "workspace.enableFloatingDocumentWindowDocking", "workspace.enableNarrowOptionsBar", - "tools.enableFlickPanning", "fileHandling.imagePreviews", "fileHandling.saveInBackground", "fileHandling.ignoreExifProfileTag", diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index ee3e171c51..74a2612520 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -2823,6 +2823,20 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: // box is only drawn and driven on the primary canvas. let transform_owns_pointer = primary && app.ui.transform.is_some() && temporary.is_none() && !middle; let hand_pan = tool == Tool::Hand && !transform_owns_pointer; + // Preferences › Tools › Enable Flick Panning: a Hand drag let go while moving glides on. + let flick_id = egui::Id::new(("pc-flick-pan", idx, primary, ctx.viewport_id())); + let flick_on = app.session.prefs().tools.enable_flick_panning; + if let Some(d) = crate::flick_pan::frame(&ctx, flick_id, hand_pan && response.dragged(), response.drag_delta(), flick_on) { + let d = xf.unmap_vec(d) / (view.zoom / ppp); + if d.is_finite() { + view.center[0] -= d.x; + view.center[1] -= d.y; + } + // Overscroll off: the glide stops at the pan limit, as the scrollbars do. + if !app.session.prefs().tools.overscroll && crate::scrollbars::clamp_view(&mut view, rect.size() / vec2(aspect, 1.0), ppp) { + ctx.data_mut(|m| m.get_temp_mut_or_default::(flick_id).stop()); + } + } if hand_pan && response.dragged() { let d = xf.unmap_vec(response.drag_delta()) / (view.zoom / ppp); view.center[0] -= d.x; @@ -6146,6 +6160,63 @@ mod tests { assert!((step.x - 0.5).abs() < 1e-3, "{step:?}"); } + #[test] + fn a_flicked_hand_drag_glides_on_only_with_flick_panning() { + // #204: Preferences › Tools › Enable Flick Panning. A fast Hand drag let go while moving + // keeps the view gliding for a while; off, the view stops where the drag ended. + for flick in [true, false] { + let ctx = egui::Context::default(); + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 2000, "height": 1500})).unwrap(); + app.run("prefs.set", json!({"path": "tools.enableFlickPanning", "value": flick})).unwrap(); + app.ui.tool = Tool::Hand; + app.sync_views(); + let mut view = app.ui.views[0].clone(); + view.zoom = 1.0; + view.center = [1000.0, 750.0]; + view.fit_pending = false; + view.fill_pending = false; + let rect = Rect::from_min_size(Pos2::ZERO, vec2(400.0, 300.0)); + let mut frame = |app: &mut PhotocraftApp, events: Vec| -> View { + let input = egui::RawInput { screen_rect: Some(rect), events, ..Default::default() }; + let mut out = ctx.run_ui(input, |ui| { + view = canvas_view(app, ui, 0, rect, view.clone(), true); + }); + out.textures_delta.clear(); + view.clone() + }; + let start = Pos2::new(200.0, 150.0); + let press = + |pos: Pos2, pressed: bool| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + frame(&mut app, vec![egui::Event::PointerMoved(start)]); + frame(&mut app, vec![press(start, true)]); + let mut end = start; + for i in 1..=8 { + end = start + vec2(-20.0 * i as f32, 0.0); + frame(&mut app, vec![egui::Event::PointerMoved(end)]); + } + let released = frame(&mut app, vec![press(end, false)]).center; + let mut centers = vec![released]; + for _ in 0..5 { + centers.push(frame(&mut app, vec![]).center); + } + if flick { + // Dragged left: the image follows the pointer, the view keeps moving right. + for w in centers.windows(2) { + assert!(w[1][0] > w[0][0], "glides on: {centers:?}"); + } + // ...and comes to rest. + let mut last = *centers.last().unwrap(); + for _ in 0..120 { + last = frame(&mut app, vec![]).center; + } + assert_eq!(frame(&mut app, vec![]).center, last, "the glide stops"); + } else { + assert!(centers.iter().all(|c| *c == released), "no glide when off: {centers:?}"); + } + } + } + #[test] fn a_secondary_canvas_hand_pans_while_a_transform_is_open() { // #2302 review: `app.ui.transform` is global, but only the primary canvas draws and drives diff --git a/crates/ui-egui/src/flick_pan.rs b/crates/ui-egui/src/flick_pan.rs new file mode 100644 index 0000000000..4ce5a39fb6 --- /dev/null +++ b/crates/ui-egui/src/flick_pan.rs @@ -0,0 +1,211 @@ +//! Preferences › Tools › Enable Flick Panning (#204): letting go of a Hand-tool drag (the +//! selected Hand, the Space-held Hand or a middle-button drag) while the pointer is still moving +//! keeps the view gliding that way, slowing smoothly to a stop, as in Photoshop. Any click, new +//! drag or key press stops it. Off, the view stops where the drag ended. +//! +//! [`Flick`] is the pure state (velocity estimate and decay); [`frame`] drives it from one +//! canvas frame's input and returns the screen-space pan to apply. + +use egui::{Context, Id, Vec2}; + +/// Pointer movement this recent (seconds) sets the release velocity. +const WINDOW: f64 = 0.08; +/// Time constant of the exponential friction (seconds): a fast flick stops in under a second. +const TAU: f32 = 0.18; +/// A release slower than this (screen points per second) does not glide. +const MIN_START: f32 = 150.0; +/// The glide stops below this speed. +const MIN_SPEED: f32 = 15.0; +/// Fastest glide (screen points per second); a hostile or glitchy delta can't fling the view away. +const MAX_SPEED: f32 = 6000.0; +/// Longest frame step the glide integrates; a stalled frame doesn't jump the view. +const MAX_DT: f32 = 0.1; + +/// One canvas's flick state. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct Flick { + /// Recent drag steps: (time, frame interval, screen delta). + samples: Vec<(f64, f32, Vec2)>, + /// A Hand drag was in progress last frame. + dragging: bool, + /// The glide velocity in screen points per second, while gliding. + velocity: Option, + /// Time of the previous frame. + last: Option, +} + +impl Flick { + /// Frame interval since the previous call, clamped to `0..=MAX_DT`; records `now`. + fn tick(&mut self, now: f64) -> f32 { + let dt = self.last.map_or(0.0, |l| (now - l) as f32); + self.last = Some(now); + if dt.is_finite() { dt.clamp(0.0, MAX_DT) } else { 0.0 } + } + + /// A Hand drag moved the pointer by `delta` this frame (`dt` after the previous one). + pub fn track(&mut self, now: f64, dt: f32, delta: Vec2) { + self.velocity = None; + self.dragging = true; + if delta.is_finite() && dt.is_finite() { + self.samples.push((now, dt, delta)); + } + self.samples.retain(|s| now - s.0 <= WINDOW); + } + + /// Pointer velocity over the last [`WINDOW`] before `now`, in screen points per second. + pub fn release_velocity(&self, now: f64) -> Vec2 { + let (mut d, mut t) = (Vec2::ZERO, 0.0f32); + for &(at, dt, delta) in &self.samples { + if now - at <= WINDOW { + d += delta; + t += dt; + } + } + if t <= 1e-4 { + return Vec2::ZERO; + } + let v = d / t; + if !v.is_finite() { + return Vec2::ZERO; + } + let speed = v.length(); + if speed > MAX_SPEED { v * (MAX_SPEED / speed) } else { v } + } + + /// The drag ended at `now`: start gliding if `enabled` and the pointer was still moving fast + /// enough. Returns whether a glide started. + pub fn release(&mut self, now: f64, enabled: bool) -> bool { + self.dragging = false; + let v = self.release_velocity(now); + self.samples.clear(); + self.velocity = (enabled && v.length() >= MIN_START).then_some(v); + self.velocity.is_some() + } + + /// Advance the glide by `dt` seconds: the screen-space distance moved, or `None` when not + /// gliding (or it just came to rest). + pub fn step(&mut self, dt: f32) -> Option { + let v = self.velocity?; + let dt = if dt.is_finite() { dt.clamp(0.0, MAX_DT) } else { 0.0 }; + // Exact integral of v·e^(−t/τ) over the step, then the decayed velocity. + let decay = (-dt / TAU).exp(); + let moved = v * (TAU * (1.0 - decay)); + let next = v * decay; + self.velocity = (next.is_finite() && next.length() >= MIN_SPEED).then_some(next); + moved.is_finite().then_some(moved) + } + + /// Stop any glide (a click, new drag or key press). + pub fn stop(&mut self) { + self.velocity = None; + self.samples.clear(); + } + + pub fn gliding(&self) -> bool { + self.velocity.is_some() + } +} + +/// Drive canvas `id`'s flick for this frame. `hand_drag` is whether a Hand drag moved the view by +/// `delta` (screen points) this frame; `enabled` is the preference. Returns the screen-space +/// distance the glide moves the view this frame (the same sense as a drag delta). +pub fn frame(ctx: &Context, id: Id, hand_drag: bool, delta: Vec2, enabled: bool) -> Option { + let (now, interrupt) = ctx.input(|i| { + let key = i.events.iter().any(|e| matches!(e, egui::Event::Key { pressed: true, .. })); + (i.time, i.pointer.any_pressed() || key) + }); + let mut flick = ctx.data(|d| d.get_temp::(id)).unwrap_or_default(); + let dt = flick.tick(now); + let moved = if hand_drag { + flick.track(now, dt, delta); + None + } else { + if flick.dragging { + flick.release(now, enabled); + } + if interrupt || !enabled { + flick.stop(); + } + flick.step(dt) + }; + // A moving drag asks for one more frame, so its release is seen even if nothing else repaints. + if flick.gliding() || (hand_drag && delta != Vec2::ZERO) { + ctx.request_repaint(); + } + ctx.data_mut(|d| d.insert_temp(id, flick)); + moved +} + +#[cfg(test)] +mod tests { + use super::*; + use egui::vec2; + + const DT: f32 = 1.0 / 60.0; + + fn flung(speed_per_frame: f32) -> (Flick, f64) { + let mut f = Flick::default(); + let mut t = 0.0; + for _ in 0..10 { + t += f64::from(DT); + f.track(t, DT, vec2(speed_per_frame, 0.0)); + } + (f, t + f64::from(DT)) + } + + #[test] + fn velocity_comes_from_the_last_moments_of_the_drag() { + let (f, now) = flung(20.0); + let v = f.release_velocity(now); + assert!((v.x - 1200.0).abs() < 1.0, "{v:?}"); + assert_eq!(v.y, 0.0); + // Held still for a while before letting go: no velocity. + assert_eq!(f.release_velocity(now + 0.5), Vec2::ZERO); + } + + #[test] + fn a_fast_release_glides_and_decays_to_a_stop() { + let (mut f, now) = flung(20.0); + assert!(f.release(now, true)); + let mut total = 0.0; + let mut last = f32::INFINITY; + let mut frames = 0; + while let Some(d) = f.step(DT) { + assert!(d.x > 0.0 && d.x < last, "decelerates: {d:?}"); + last = d.x; + total += d.x; + frames += 1; + assert!(frames < 200, "stops"); + } + // About 1 s of glide at most, covering about v·τ. + assert!((20..=70).contains(&frames), "{frames} frames"); + assert!(total > 150.0 && total < 1200.0 * TAU + 1.0, "{total}"); + assert!(!f.gliding()); + } + + #[test] + fn disabled_or_slow_releases_do_not_glide() { + let (mut f, now) = flung(20.0); + assert!(!f.release(now, false)); + assert_eq!(f.step(DT), None); + let (mut f, now) = flung(1.0); + assert!(!f.release(now, true), "60 pt/s is a stop, not a flick"); + } + + #[test] + fn stop_and_hostile_numbers() { + let (mut f, now) = flung(20.0); + f.release(now, true); + f.stop(); + assert_eq!(f.step(DT), None); + // Huge deltas are clamped; NaN deltas and steps are ignored. + let (mut f, now) = flung(1.0e9); + f.track(now - 0.001, DT, vec2(f32::NAN, 0.0)); + assert!(f.release_velocity(now).length() <= MAX_SPEED + 1.0); + f.release(now, true); + let d = f.step(f32::NAN); + assert!(d.is_none_or(|d| d.is_finite())); + let d = f.step(f32::INFINITY).unwrap_or_default(); + assert!(d.is_finite() && d.length() <= MAX_SPEED * MAX_DT); + } +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 2b6e71e4df..cb200769d4 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -75,6 +75,7 @@ pub mod fill_ui; pub mod filter_dialog; #[cfg(not(target_arch = "wasm32"))] mod filter_preview_worker; +pub mod flick_pan; mod font_preview; pub mod frame_tool; pub mod gallery_ui; diff --git a/docs/scorecard.md b/docs/scorecard.md index 4f75449230..8a2a062c1d 100644 --- a/docs/scorecard.md +++ b/docs/scorecard.md @@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js | [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 17 not run, 5 not measurable yet (baseline 2026-10-05) | | [File compatibility](#file-compatibility) | 6 | 11 | 10 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 236/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 | | [Tools](#tools) | 25 | 16 | 2 | | -| [Workspace and UI](#workspace-and-ui) | 8 | 8 | 7 | settings that do nothing: 35 of 153 (target 0) | +| [Workspace and UI](#workspace-and-ui) | 8 | 8 | 7 | settings that do nothing: 34 of 153 (target 0) | | [Type](#type) | 1 | 4 | 4 | | | [Automation](#automation) | 3 | 2 | 6 | 630 of 630 menu items live (100.0%) | | [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 28 of 28 crates; panic_hunt present | @@ -176,9 +176,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t ## Workspace and UI -**Settings that do nothing: 35 of 153** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't. +**Settings that do nothing: 34 of 153** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't. -Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `file_handling.image_previews`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`. +Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `workspace.enable_narrow_options_bar`, `file_handling.image_previews`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`. | Id | Target | Status | Issue | Note | |---|---|---|---|---| diff --git a/docs/ui-parity.md b/docs/ui-parity.md index df23d9f61d..91afa00dcc 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity: tools, handles, modifiers and feel -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-10 · **Change:** minor (Crop resize stability, immediate ratio previews, and options-bar overflow regression coverage) · **Target:** Adobe Photoshop 2026 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-11 · **Change:** minor (Hand-tool flick panning) · **Target:** Adobe Photoshop 2026 How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation, @@ -161,7 +161,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme | Space = Hand, ⌘Space / ⌘⌥Space = zoom in/out, spring-loaded while held | done | `hold_keys.rs` | | Hold any tool letter for a temporary tool | missing | #2672 | | Scrubby zoom | done | `zoom_tool.rs` | -| Flick panning | missing | `tools.enable_flick_panning` unread | +| Flick panning | done | `flick_pan.rs` (Preferences › Tools › Enable Flick Panning) | | Animated zoom | missing | unread pref; #566 | | Double-click Zoom tool = 100%, double-click Hand = fit | partial | Zoom missing (#2508) | | ⌥-wheel zoom in gentle steps | missing | UI-217-18 | @@ -208,3 +208,4 @@ Paragraph; the rest open as in-app floating windows. |---|---|---| | 2026-10-10 | major | First version, from a source audit against Photoshop 2026 27.11.0's shortcuts file and the open issues | | 2026-10-10 | minor | Fixed Crop live resize snapping feedback and outdated-camera rendering, applied ratios immediately to centred inscribed previews, and removed two-point options-bar overflow; added pointer, rendering, dropdown/Enter, Swap/X and scrolling regressions | +| 2026-10-11 | minor | Flick panning done: releasing a moving Hand drag (tool, Space or middle button) glides and decays, gated by Enable Flick Panning |