Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Enhanced Controls: wire Zoom with Trackpad Pinch (#204) (#2577)

Reynold Hu334ae5779cee
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index 7c7d3b808..5c3448bc1 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -1015,7 +1015,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &[
"type.recentFonts",
"enhancedControls.scrubbySliderAcceleration",
"enhancedControls.touchGestures",
- "enhancedControls.zoomWithTrackpadPinch",
"rawDefaults.colorSpace",
"rawDefaults.bitDepth",
"rawDefaults.resolution",
diff --git a/crates/ui-egui/src/camera_raw_preview_ui.rs b/crates/ui-egui/src/camera_raw_preview_ui.rs
index a0a1d0cdb..e0f493811 100644
--- a/crates/ui-egui/src/camera_raw_preview_ui.rs
+++ b/crates/ui-egui/src/camera_raw_preview_ui.rs
@@ -110,7 +110,7 @@ pub(crate) fn interact(ui: &mut Ui, state: &mut CameraRawPreviewState, viewport:
let rect = state.image_rect(viewport, size);
// Reuse the canvas wheel policy: retain the modifiers of the wheel event while egui
// smooths it, even if Alt is released before the final part of the notch arrives.
- let wheel = crate::wheel_nav::read(ui.ctx(), false);
+ let wheel = crate::wheel_nav::read(ui.ctx(), false, true);
if response.hovered() {
ui.input_mut(|i| i.smooth_scroll_delta = Vec2::ZERO);
match wheel {
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index a1fcda0ad..06d52ff88 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -2675,7 +2675,8 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
let under_dialog = !app.ui.dialogs.is_empty();
let free_hover = under_dialog && crate::dialogs::free_pointer_over(&ctx, rect).is_some();
// Navigation (wheel_nav.rs): scroll pans (⇧ or ⌘/Ctrl sideways); pinch and ⌥-scroll zoom around the pointer.
- let wheel = crate::wheel_nav::read(&ctx, app.session.prefs().general.zoom_with_scroll_wheel);
+ let wheel =
+ crate::wheel_nav::read(&ctx, app.session.prefs().general.zoom_with_scroll_wheel, app.session.prefs().enhanced_controls.zoom_with_trackpad_pinch);
// The wheel also scrolls over the scrollbars drawn on top of the canvas (last frame's hover).
let bars_id = egui::Id::new(("pc-canvas-bars-hover", idx));
let over_bars = ctx.data(|d| d.get_temp::<bool>(bars_id)).unwrap_or(false);
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index c30796a5d..06c810e17 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1459,8 +1459,9 @@ impl eframe::App for PhotocraftApp {
menu.raw_input(raw_input);
}
shortcuts::clipboard_keys(ctx, ctx.text_edit_focused() || self.ui.text_edit.is_some(), raw_input);
- // Windows sends a touchpad pinch as Ctrl + wheel; make it a pinch again (wheel_nav.rs).
- if cfg!(target_os = "windows") {
+ // Windows sends a touchpad pinch as Ctrl + wheel; make it a pinch again (wheel_nav.rs) —
+ // unless the pinch preference is off, leaving those fractions to scroll sideways.
+ if cfg!(target_os = "windows") && self.session.prefs().enhanced_controls.zoom_with_trackpad_pinch {
wheel_nav::fold_legacy_pinch(ctx, raw_input);
}
raw_input.events.extend(self.take_synthetic_step());
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index 7ebf7736c..ae1b57b31 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -1720,8 +1720,9 @@ fn navigator(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
// should zoom even when the document canvas is configured to scroll on wheel.
// Use the canvas wheel classifier to honour one ×1.1 step per notch without
// applying egui's smoothed wheel tail a second time.
+ let pinch_zooms = app.session.prefs().enhanced_controls.zoom_with_trackpad_pinch;
if resp.hovered()
- && let Some(crate::wheel_nav::Wheel::Zoom(factor)) = crate::wheel_nav::read(&ctx, true)
+ && let Some(crate::wheel_nav::Wheel::Zoom(factor)) = crate::wheel_nav::read(&ctx, true, pinch_zooms)
{
let view = &mut app.ui.views[idx];
let next = crate::zoom_levels::clamp(view.zoom * factor, view.doc_size);
diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rs
index c2def4db7..9f99c6e20 100644
--- a/crates/ui-egui/src/prefs_ui.rs
+++ b/crates/ui-egui/src/prefs_ui.rs
@@ -2569,10 +2569,11 @@ mod tests {
assert!(!prefs::is_hidden("type.fillNewTypeLayersWithPlaceholder"));
assert!(!prefs::is_hidden("type.useEscToCommit"));
assert!(!prefs::is_hidden("type.smartQuotes"));
- // Rotate View with Trackpad is live; the other Enhanced Controls rows stay hidden.
+ // Rotate View with Trackpad and the pinch zoom are live; the other Enhanced Controls rows
+ // stay hidden.
assert!(has_visible_fields(&values, "enhancedControls"));
assert!(!prefs::is_hidden("enhancedControls.rotateViewWithTrackpad"));
- assert!(prefs::is_hidden("enhancedControls.zoomWithTrackpadPinch"));
+ assert!(!prefs::is_hidden("enhancedControls.zoomWithTrackpadPinch"));
// Camera Raw Defaults shows only "Open in Camera Raw" so far.
assert!(has_visible_fields(&values, "rawDefaults"));
assert!(!prefs::is_hidden("rawDefaults.openInCameraRaw"));
diff --git a/crates/ui-egui/src/wheel_nav.rs b/crates/ui-egui/src/wheel_nav.rs
index 1d94b5384..4d07537df 100644
--- a/crates/ui-egui/src/wheel_nav.rs
+++ b/crates/ui-egui/src/wheel_nav.rs
@@ -4,7 +4,9 @@
//! - ⌥/Alt + wheel zooms around the pointer, 10% per wheel notch, applied the frame it arrives.
//! - Preferences › General › Zoom with Scroll Wheel swaps the two: the wheel zooms and
//! ⌥/Alt + wheel scrolls.
-//! - A trackpad pinch zooms around the pointer.
+//! - A trackpad pinch zooms around the pointer, unless Preferences › Enhanced Controls ›
+//! Zoom with Trackpad Pinch is off (then a pinch does nothing, and Windows' Ctrl + wheel
+//! fractions scroll sideways like the wheel, because the fold below is skipped).
//!
//! [`configure`] makes egui fold ⌘/Ctrl + wheel into a sideways scroll as it does ⇧ + wheel, so
//! only a real pinch (egui's `Event::Zoom`, or a touch screen) reaches `zoom_delta`. macOS and
@@ -51,13 +53,15 @@ pub struct Input {
pub alt: bool,
/// Preferences › General › Zoom with Scroll Wheel.
pub zoom_with_wheel: bool,
+ /// Preferences › Enhanced Controls › Zoom with Trackpad Pinch.
+ pub pinch_zooms: bool,
/// Points per wheel notch (egui's `line_scroll_speed`).
pub notch: f32,
}
/// The view change for one frame of wheel input, if any.
pub fn classify(i: Input) -> Option<Wheel> {
- if i.zoom_delta.is_finite() && i.zoom_delta > 0.0 && i.zoom_delta != 1.0 {
+ if i.pinch_zooms && i.zoom_delta.is_finite() && i.zoom_delta > 0.0 && i.zoom_delta != 1.0 {
return Some(Wheel::Zoom(i.zoom_delta));
}
// One notch (`notch` points) is one ×1.1 step.
@@ -134,7 +138,7 @@ fn alt_id() -> Id {
/// Read this frame's wheel input. Call it every frame (hovered or not) so the Alt state of the
/// gesture follows the latest wheel event.
-pub fn read(ctx: &Context, zoom_with_wheel: bool) -> Option<Wheel> {
+pub fn read(ctx: &Context, zoom_with_wheel: bool, pinch_zooms: bool) -> Option<Wheel> {
let notch = ctx.options(|o| o.input_options.line_scroll_speed);
let (scroll, zoom_delta, latest, wheel, page) = ctx.input(|i| {
let latest = i.events.iter().rev().find_map(|e| match e {
@@ -171,7 +175,7 @@ pub fn read(ctx: &Context, zoom_with_wheel: bool) -> Option<Wheel> {
}
},
);
- classify(Input { scroll, raw, zoom_delta, alt, zoom_with_wheel, notch })
+ classify(Input { scroll, raw, zoom_delta, alt, zoom_with_wheel, pinch_zooms, notch })
}
#[cfg(test)]
@@ -181,7 +185,7 @@ mod tests {
use super::*;
fn input(scroll: Vec2, alt: bool) -> Input {
- Input { scroll, raw: scroll, zoom_delta: 1.0, alt, zoom_with_wheel: false, notch: 40.0 }
+ Input { scroll, raw: scroll, zoom_delta: 1.0, alt, zoom_with_wheel: false, pinch_zooms: true, notch: 40.0 }
}
fn wheel(delta: Vec2, modifiers: Modifiers) -> Event {
@@ -204,7 +208,7 @@ mod tests {
if legacy {
fold_legacy_pinch(&ctx, &mut raw);
}
- let mut out = ctx.run_ui(raw, |ui| match read(ui.ctx(), zoom_with_wheel) {
+ let mut out = ctx.run_ui(raw, |ui| match read(ui.ctx(), zoom_with_wheel, true) {
Some(Wheel::Pan(d)) => pan += d,
Some(Wheel::Zoom(f)) => zoom *= f,
None => {}
@@ -257,6 +261,44 @@ mod tests {
assert_eq!(classify(i), Some(Wheel::Zoom(0.8)));
}
+ /// Preferences › Enhanced Controls › Zoom with Trackpad Pinch off: the pinch is ignored, and
+ /// a scroll in the same frame pans as it would without a pinch.
+ #[test]
+ fn the_pinch_preference_switches_pinch_zooming() {
+ let i = Input { zoom_delta: 1.2, pinch_zooms: false, ..input(Vec2::ZERO, false) };
+ assert_eq!(classify(i), None);
+ let i = Input { zoom_delta: 1.2, pinch_zooms: false, ..input(Vec2::new(0.0, 12.0), false) };
+ assert_eq!(classify(i), Some(Wheel::Pan(Vec2::new(0.0, 12.0))));
+ // On (the default) the pinch still zooms.
+ let i = Input { zoom_delta: 1.2, pinch_zooms: true, ..input(Vec2::ZERO, false) };
+ assert_eq!(classify(i), Some(Wheel::Zoom(1.2)));
+ }
+
+ /// The Windows pinch fold follows the preference too: off, the Ctrl + wheel fractions stay
+ /// wheel events (which egui folds into a sideways scroll).
+ #[test]
+ fn the_windows_pinch_fold_follows_the_preference() {
+ use eframe::App as _;
+ if !cfg!(target_os = "windows") {
+ return;
+ }
+ let mut app = crate::PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ let ctx = Context::default();
+ let event = || Event::MouseWheel {
+ unit: MouseWheelUnit::Line,
+ delta: egui::vec2(0.0, 0.25),
+ phase: egui::TouchPhase::Move,
+ modifiers: Modifiers { ctrl: true, command: true, ..Modifiers::NONE },
+ };
+ let mut raw = RawInput { time: Some(1.0), events: vec![event()], ..Default::default() };
+ app.raw_input_hook(&ctx, &mut raw);
+ assert!(matches!(raw.events[0], Event::Zoom(_)), "the fraction is a pinch: {:?}", raw.events[0]);
+ app.run("prefs.set", serde_json::json!({"path": "enhancedControls.zoomWithTrackpadPinch", "value": false})).unwrap();
+ let mut raw = RawInput { time: Some(2.0), events: vec![event()], ..Default::default() };
+ app.raw_input_hook(&ctx, &mut raw);
+ assert!(matches!(raw.events[0], Event::MouseWheel { .. }), "off: it stays a wheel event: {:?}", raw.events[0]);
+ }
+
#[test]
fn zoom_with_scroll_wheel_preference_swaps_wheel_and_alt_wheel() {
let pref = |scroll, alt| Input { zoom_with_wheel: true, ..input(scroll, alt) };
@@ -326,7 +368,8 @@ mod tests {
for alt in [false, true] {
for notch in [0.0, -1.0, f32::NAN, 40.0] {
for zd in [f32::NAN, 0.0, -1.0, f32::INFINITY, 1.0] {
- let i = Input { scroll: Vec2::new(0.0, s), raw: Vec2::new(0.0, s), zoom_delta: zd, alt, zoom_with_wheel: !alt, notch };
+ let i =
+ Input { scroll: Vec2::new(0.0, s), raw: Vec2::new(0.0, s), zoom_delta: zd, alt, zoom_with_wheel: !alt, pinch_zooms: true, notch };
if let Some(Wheel::Zoom(f)) = classify(i) {
assert!(f.is_finite() && f > 0.0, "{f} from {i:?}");
}
diff --git a/docs/scorecard.md b/docs/scorecard.md
index 9e09010f8..8581358a8 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, 16 not run, 6 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 5 | 11 | 11 | 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) | 21 | 17 | 4 | |
-| [Workspace and UI](#workspace-and-ui) | 6 | 7 | 10 | settings that do nothing: 43 of 152 (target 0) |
+| [Workspace and UI](#workspace-and-ui) | 6 | 7 | 10 | settings that do nothing: 42 of 152 (target 0) |
| [Type](#type) | 0 | 3 | 6 | |
| [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 |
@@ -175,9 +175,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
## Workspace and UI
-**Settings that do nothing: 43 of 152** (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: 42 of 152** (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.beep_when_done`, `general.always_create_smart_objects_when_placing`, `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`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `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`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `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_.font_preview`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `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.beep_when_done`, `general.always_create_smart_objects_when_placing`, `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`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `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`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `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_.font_preview`, `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 |
|---|---|---|---|---|