PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Zoom: the Zoom tool's click honours Zoom Clicked Point to Center (#204) (#1241)
Reynold Hud57fdf0116a4
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 814c958c5..0b37946b1 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -1933,7 +1933,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:match (wheel, pointer) {(Some(crate::wheel_nav::Wheel::Zoom(f)), Some(p)) => {let nz = (view.zoom * f).clamp(0.01, 64.0);- zoom_about(&mut view, &xf, p, nz);+ zoom_about(&mut view, &xf, p, nz, false);}(Some(crate::wheel_nav::Wheel::Pan(scroll)), _) => {view.center[0] -= scroll.x / view.zoom * if flip { -1.0 } else { 1.0 };@@ -2128,7 +2128,8 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:match tool {Tool::Zoom => {let nz = zoom_step(view.zoom, if zoom_out(click_mods.alt) { -1 } else { 1 });- zoom_about(&mut view, &xf, p, nz);+ let center = app.session.prefs().tools.zoom_clicked_point_to_center;+ zoom_about(&mut view, &xf, p, nz, center);}// A click with the (temporary) Hand does nothing, never the tool underneath.Tool::Hand => {}@@ -2330,9 +2331,16 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:view}-fn zoom_about(view: &mut View, xf: &ViewXform, p: Pos2, new_zoom: f32) {+/// Zoom to `new_zoom` about the pointer `p`. By default the document point under it stays under+/// it; with Preferences › Tools › Zoom Clicked Point to Center (`center_on_point`) it moves to the+/// centre of the view instead (#204).+fn zoom_about(view: &mut View, xf: &ViewXform, p: Pos2, new_zoom: f32, center_on_point: bool) {let before = xf.to_doc(p);view.zoom = new_zoom;+ if center_on_point {+ view.center = [before[0] as f32, before[1] as f32];+ return;+ }let d = (p - xf.rect.center()) / new_zoom;let dx = if xf.flip { -d.x } else { d.x };view.center = [before[0] as f32 - dx, before[1] as f32 - d.y];@@ -3774,6 +3782,25 @@ mod tests {assert!(!view.fill_pending);}+ #[test]+ fn zoom_about_centres_the_clicked_point_with_the_preference() {+ let rect = Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));+ let xf = ViewXform { rect, zoom: 1.0, center: [400.0, 300.0], flip: false };+ let p = pos2(600.0, 200.0);+ let doc = xf.to_doc(p);+ // Off: the document point under the pointer stays under it.+ let mut view = View { zoom: 1.0, center: [400.0, 300.0], ..Default::default() };+ zoom_about(&mut view, &xf, p, 2.0, false);+ let after = ViewXform { rect, zoom: 2.0, center: view.center, flip: false };+ let s = after.to_screen(doc[0] as f32, doc[1] as f32);+ assert!((s - p).length() < 0.5, "{s:?} vs {p:?}");+ // On: the clicked point is the view centre.+ let mut view = View { zoom: 1.0, center: [400.0, 300.0], ..Default::default() };+ zoom_about(&mut view, &xf, p, 2.0, true);+ assert!((view.center[0] - doc[0] as f32).abs() < 0.5, "{:?}", view.center);+ assert!((view.center[1] - doc[1] as f32).abs() < 0.5, "{:?}", view.center);+ }+#[test]fn damage_grows_by_nested_effect_reach() {use photocraft_doc::{Effect, Layer};diff --git a/docs/scorecard.md b/docs/scorecard.mdindex d40b4f3b2..746cd2a71 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 | 13 | 47 scenarios: 3 within budget, 22 over budget or failing, 15 tracked only, 6 not run, 7 not measurable yet (baseline 2026-10-05) || [File compatibility](#file-compatibility) | 4 | 10 | 13 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 229/309, round trip ≥ 307/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 || [Tools](#tools) | 7 | 14 | 9 | |-| [Workspace and UI](#workspace-and-ui) | 0 | 5 | 18 | settings that do nothing: 57 of 139 (target 0) |+| [Workspace and UI](#workspace-and-ui) | 0 | 5 | 18 | settings that do nothing: 56 of 139 (target 0) || [Type](#type) | 0 | 3 | 6 | || [Automation](#automation) | 3 | 2 | 6 | 627 of 627 menu items live (100.0%) || [Reliability](#reliability) | 4 | 1 | 2 | never-crash lints on 27 of 27 crates; panic_hunt present |@@ -154,9 +154,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t## Workspace and UI-**Settings that do nothing: 57 of 139** (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: 56 of 139** (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.export_clipboard`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `interface.show_channels_in_color`, `interface.dynamic_color_sliders`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.open_documents_as_tabs`, `workspace.enable_floating_document_window_docking`, `workspace.large_tabs`, `workspace.enable_narrow_options_bar`, `tools.zoom_clicked_point_to_center`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `tools.double_click_layer_mask_launches_select_and_mask`, `file_handling.image_previews`, `file_handling.lowercase_extension`, `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`, `units_and_rulers.screen_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.smart_quotes`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.use_esc_to_commit`, `type_.text_engine`, `type_.font_preview`, `type_.fill_new_type_layers_with_placeholder`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `enhanced_controls.rotate_view_with_trackpad`, `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.export_clipboard`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `interface.show_channels_in_color`, `interface.dynamic_color_sliders`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.open_documents_as_tabs`, `workspace.enable_floating_document_window_docking`, `workspace.large_tabs`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `tools.double_click_layer_mask_launches_select_and_mask`, `file_handling.image_previews`, `file_handling.lowercase_extension`, `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`, `units_and_rulers.screen_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.smart_quotes`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.use_esc_to_commit`, `type_.text_engine`, `type_.font_preview`, `type_.fill_new_type_layers_with_placeholder`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `enhanced_controls.rotate_view_with_trackpad`, `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 ||---|---|---|---|---|