PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Guides: a guide let go over either ruler is removed, not only off the canvas (#6286)
Theo Wilenius9f8d4bc0acb5
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 391ad464f..2fea271cf 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -3631,7 +3631,17 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:if press_stroke {buttons.clicked = false;}- let p = response.interact_pointer_pos().map(|p| xf.to_doc(p)).or_else(|| app.drag.as_ref().and_then(|d| d.points.last().map(|q| [q[0], q[1]])));+ let at = response.interact_pointer_pos();+ // #6286: a guide let go over a ruler is removed, whichever ruler it is. Tested here in+ // screen space, where the rulers are: on the guide's own axis the release can still be+ // inside the document, which is what `finish_drag` sees.+ if app.guide_drag.is_some() {+ let on_ruler = at.is_some_and(|p| crate::rulers::dropped_on_a_ruler(app, full, p));+ if let Some(g) = app.guide_drag.as_mut() {+ g.over_ruler = on_ruler;+ }+ }+ let p = at.map(|p| xf.to_doc(p)).or_else(|| app.drag.as_ref().and_then(|d| d.points.last().map(|q| [q[0], q[1]])));if let Some(d) = p {tap_at_peak_pressure(app);tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, mods);diff --git a/crates/ui-egui/src/move_hover.rs b/crates/ui-egui/src/move_hover.rsindex c3d07f313..ff9d425f8 100644--- a/crates/ui-egui/src/move_hover.rs+++ b/crates/ui-egui/src/move_hover.rs@@ -185,7 +185,7 @@ mod tests {assert_eq!(active_outline(&mut app, None, false, false), Some(a));// When a drag or transform is in progress, no outline:- app.guide_drag = Some(crate::rulers::GuideDrag { vertical: false, index: None, pos: 10.0, press: 10.0 });+ app.guide_drag = Some(crate::rulers::GuideDrag { vertical: false, index: None, pos: 10.0, press: 10.0, over_ruler: false });assert_eq!(active_outline(&mut app, None, false, false), None);app.guide_drag = None;diff --git a/crates/ui-egui/src/rulers.rs b/crates/ui-egui/src/rulers.rsindex 61ea25d96..320a99bea 100644--- a/crates/ui-egui/src/rulers.rs+++ b/crates/ui-egui/src/rulers.rs@@ -1,6 +1,6 @@//! View extras: rulers (⌘R), grid (⌘'), guides (⌘;). Guides are dragged out of the rulers and-//! moved with the Move tool (drag one off the canvas to delete it), all through undoable engine-//! commands (`view.newGuide` / `view.moveGuide` / `view.deleteGuide`).+//! moved with the Move tool (drag one off the canvas or onto a ruler to delete it), all through+//! undoable engine commands (`view.newGuide` / `view.moveGuide` / `view.deleteGuide`).use egui::{Align2, Color32, Pos2, Rect, Sense, Stroke, pos2, vec2};use photocraft_doc::Document;@@ -96,13 +96,16 @@ pub struct GuideDrag {/// Where the pointer went down, on the guide's axis: released there, an existing guide is/// clicked (selected), not moved.pub press: f64,+ /// Whether the pointer was over a ruler when the guide was let go (#6286): a guide released+ /// there is removed, whatever its own axis reads.+ pub over_ruler: bool,}impl GuideDrag {/// An existing guide taken at document point `p`.pub fn existing(vertical: bool, index: usize, p: [f64; 2]) -> Self {let at = if vertical { p[0] } else { p[1] };- Self { vertical, index: Some(index), pos: at, press: at }+ Self { vertical, index: Some(index), pos: at, press: at, over_ruler: false }}}@@ -111,6 +114,20 @@ pub fn content_rect(app: &PhotocraftApp, rect: Rect) -> Rect {if app.ui.extras.rulers { Rect::from_min_max(rect.min + vec2(RULER, RULER), rect.max) } else { rect }}+/// Whether the screen point `p` is over a ruler, inside the full canvas rect `full`. A guide let go+/// there is removed, as in Photoshop, and either ruler removes it (#6286): the top ruler measures+/// document x and the left one y, so the ruler the guide was not dragged out of can lie over a+/// coordinate that is still inside the document on the guide's own axis.+pub(crate) fn dropped_on_a_ruler(app: &PhotocraftApp, full: Rect, p: Pos2) -> bool {+ if !app.ui.extras.rulers {+ return false;+ }+ let content = content_rect(app, full);+ let top = Rect::from_min_max(full.min, pos2(full.max.x, content.min.y));+ let left = Rect::from_min_max(full.min, pos2(content.min.x, full.max.y));+ top.contains(p) || left.contains(p)+}+/// Tick step (document px) so major ticks are at least ~60 screen px apart: 1, 2, 5, 10, 20, 50…#[cfg(test)]fn tick_step(zoom: f32) -> f64 {@@ -235,9 +252,9 @@ pub fn guide_at(app: &PhotocraftApp, x: f64, y: f64) -> Option<(bool, usize)> {None}-/// Finish a guide drag: create, move, or delete (dropped outside the canvas). An existing guide-/// released where it was pressed is a click: it's selected and stays put, as in Photoshop; a-/// moved one stays selected.+/// Finish a guide drag: create, move, or delete (dropped outside the canvas or on a ruler). An+/// existing guide released where it was pressed is a click: it's selected and stays put, as in+/// Photoshop; a moved one stays selected.pub fn finish_drag(app: &mut PhotocraftApp, d: GuideDrag) {let Some(size) = app.session.active().map(|s| s.doc.size) else { return };if let Some(i) = d.index@@ -248,7 +265,7 @@ pub fn finish_drag(app: &mut PhotocraftApp, d: GuideDrag) {}let extent = if d.vertical { size.width } else { size.height } as f64;let orientation = if d.vertical { "vertical" } else { "horizontal" };- let inside = d.pos >= 0.0 && d.pos <= extent;+ let inside = !d.over_ruler && d.pos >= 0.0 && d.pos <= extent;let pos = (d.pos * 1000.0).round() / 1000.0;let _ = match (d.index, inside) {(None, true) => app.run("view.newGuide", json!({"orientation": orientation, "position": pos})),@@ -437,11 +454,13 @@ pub fn draw_rulers(app: &mut PhotocraftApp, ui: &mut egui::Ui, full: Rect, xf: &let d = xf.to_doc(pos);let along = if vertical { d[0] } else { d[1] };let pos = if ui.input(|i| i.modifiers.shift) { snap_to_tick(app, xf, vertical, along) } else { crate::snap_ui::snap_guide(app, vertical, along) };- app.guide_drag = Some(GuideDrag { vertical, index: None, pos, press: pos });+ app.guide_drag = Some(GuideDrag { vertical, index: None, pos, press: pos, over_ruler: false });}if resp.drag_stopped()- && let Some(d) = app.guide_drag.take()+ && let Some(mut d) = app.guide_drag.take(){+ // Let go over a ruler (the other one, say) the drag is discarded, not placed (#6286).+ d.over_ruler = resp.interact_pointer_pos().is_some_and(|p| dropped_on_a_ruler(app, full, p));finish_drag(app, d);}resp.context_menu(|ui| {@@ -675,13 +694,13 @@ mod tests {let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());app.run("file.new", json!({"width": 200, "height": 100})).unwrap();app.hover_doc = None;- app.guide_drag = Some(GuideDrag { vertical: true, index: None, pos: 42.0, press: 42.0 });+ app.guide_drag = Some(GuideDrag { vertical: true, index: None, pos: 42.0, press: 42.0, over_ruler: false });let mut h = egui_kittest::Harness::builder().with_size(vec2(260.0, 240.0)).build_ui_state(|ui, app| crate::panels::dock_body(app, ui, crate::dock::Group::Navigator, 2), app);h.run_steps(2);assert!(h.query_by_label("42").is_some(), "vertical guide: X readout");- h.state_mut().guide_drag = Some(GuideDrag { vertical: false, index: None, pos: 17.0, press: 17.0 });+ h.state_mut().guide_drag = Some(GuideDrag { vertical: false, index: None, pos: 17.0, press: 17.0, over_ruler: false });h.run_steps(2);assert!(h.query_by_label("17").is_some(), "horizontal guide: Y readout");}@@ -810,14 +829,14 @@ mod tests {let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());app.session.execute("file.new", json!({"width": 200, "height": 100})).unwrap();app.sync_views();- finish_drag(&mut app, GuideDrag { vertical: true, index: None, pos: 50.0, press: 50.0 });- finish_drag(&mut app, GuideDrag { vertical: false, index: None, pos: 500.0, press: 500.0 }); // off canvas: ignored+ finish_drag(&mut app, GuideDrag { vertical: true, index: None, pos: 50.0, press: 50.0, over_ruler: false });+ finish_drag(&mut app, GuideDrag { vertical: false, index: None, pos: 500.0, press: 500.0, over_ruler: false }); // off canvas: ignoredassert_eq!(app.session.active().unwrap().doc.guides.vertical, vec![50.0]);assert!(app.session.active().unwrap().doc.guides.horizontal.is_empty());assert_eq!(guide_at(&app, 51.0, 10.0), Some((true, 0)));- finish_drag(&mut app, GuideDrag { vertical: true, index: Some(0), pos: 120.0, press: 50.0 });+ finish_drag(&mut app, GuideDrag { vertical: true, index: Some(0), pos: 120.0, press: 50.0, over_ruler: false });assert_eq!(app.session.active().unwrap().doc.guides.vertical, vec![120.0]);- finish_drag(&mut app, GuideDrag { vertical: true, index: Some(0), pos: -30.0, press: 120.0 });+ finish_drag(&mut app, GuideDrag { vertical: true, index: Some(0), pos: -30.0, press: 120.0, over_ruler: false });assert!(app.session.active().unwrap().doc.guides.vertical.is_empty());app.ui.extras.lock_guides = true;assert_eq!(guide_at(&app, 0.0, 0.0), None);@@ -1001,6 +1020,146 @@ mod tests {assert_eq!(drag(left, egui::Modifiers::ALT), (vec![], vec![90.0]), "Alt from the left ruler: horizontal");}+ /// #6286: a guide let go over a ruler is removed, whichever ruler it is. The top ruler measures+ /// document x and the left one y, so a horizontal guide released on the left ruler is still+ /// inside the document on its own axis, and used to be placed instead of discarded.+ #[test]+ fn a_guide_dropped_on_either_ruler_is_removed() {+ let new_app = || {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({"width": 256, "height": 128})).unwrap();+ app.ui.extras.rulers = true;+ // No snapping, so a guide that is kept lands exactly where it is let go.+ app.ui.extras.snap = false;+ app+ };+ let drag = |from: Pos2, to: Pos2| {+ let (mut h, _, _) = ruler_harness(new_app());+ h.event(egui::Event::PointerMoved(from));+ press(&mut h, from, true, egui::Modifiers::NONE);+ h.event(egui::Event::PointerMoved(to));+ h.run_steps(1);+ press(&mut h, to, false, egui::Modifiers::NONE);+ let g = &h.state().session.active().unwrap().doc.guides;+ (g.vertical.clone(), g.horizontal.clone())+ };+ // #5698: out of the top ruler is a horizontal guide, out of the left one a vertical guide.+ let (top, left) = (pos2(200.0, RULER / 2.0), pos2(RULER / 2.0, 150.0));+ assert_eq!(drag(top, left), (vec![], vec![]), "out of the top ruler, released on the left ruler");+ assert_eq!(drag(left, top), (vec![], vec![]), "out of the left ruler, released on the top ruler");+ // Released on the canvas the guide lands where it was let go, as before.+ assert_eq!(drag(top, pos2(200.0, 150.0)), (vec![], vec![56.0]), "released on the canvas");+ assert_eq!(drag(left, pos2(120.0, 150.0)), (vec![40.0], vec![]), "released on the canvas");+ }++ /// #6286: the guide is removed when it is let go over a ruler, and moved when it is not. The+ /// release can be inside the document on the guide's own axis and still be a ruler drop, so the+ /// two are told apart by where the pointer is, not by the position it reads.+ #[test]+ fn a_guide_let_go_on_a_ruler_is_removed_not_moved() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({"width": 200, "height": 100})).unwrap();+ app.sync_views();+ app.run("view.newGuide", json!({"orientation": "horizontal", "position": 50})).unwrap();+ finish_drag(&mut app, GuideDrag { vertical: false, index: Some(0), pos: 50.0, press: 10.0, over_ruler: true });+ assert!(app.session.active().unwrap().doc.guides.horizontal.is_empty(), "let go on a ruler: removed");+ app.run("view.newGuide", json!({"orientation": "horizontal", "position": 50})).unwrap();+ finish_drag(&mut app, GuideDrag { vertical: false, index: Some(0), pos: 80.0, press: 10.0, over_ruler: false });+ assert_eq!(app.session.active().unwrap().doc.guides.horizontal, vec![80.0], "let go on the canvas: moved");+ }++ /// Only the top and left ruler bands count as a ruler, and only while the rulers are shown: with+ /// them hidden the whole canvas rect is canvas, so a guide dropped in the corner is kept (#6286).+ #[test]+ fn only_the_ruler_bands_count_as_a_ruler() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ let full = Rect::from_min_size(pos2(16.0, 42.0), vec2(968.0, 642.0));+ app.ui.extras.rulers = true;+ assert!(dropped_on_a_ruler(&app, full, pos2(full.min.x + RULER / 2.0, 371.0)), "the left ruler");+ assert!(dropped_on_a_ruler(&app, full, pos2(508.0, full.min.y + RULER / 2.0)), "the top ruler");+ assert!(!dropped_on_a_ruler(&app, full, pos2(508.0, 371.0)), "the canvas");+ app.ui.extras.rulers = false;+ assert!(!dropped_on_a_ruler(&app, full, pos2(full.min.x + RULER / 2.0, 371.0)), "rulers hidden: no band");+ assert!(!dropped_on_a_ruler(&app, full, pos2(508.0, full.min.y + RULER / 2.0)), "rulers hidden: no band");+ }++ /// The canvas the guides live on, rulers on, at 100 %.+ fn canvas_harness(tool: crate::state::Tool) -> egui_kittest::Harness<'static, PhotocraftApp> {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({"width": 400, "height": 300})).unwrap();+ app.sync_views();+ app.ui.extras.rulers = true;+ app.ui.extras.snap = false;+ app.ui.tool = tool;+ let mut h = egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).build_ui_state(+ |ui, app: &mut PhotocraftApp| {+ let ctx = ui.ctx().clone();+ if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {+ return;+ }+ crate::shortcuts::handle(app, &ctx);+ egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));+ },+ app,+ );+ PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);+ h.run_steps(4);+ let v = &mut h.state_mut().ui.views[0];+ v.zoom = 1.0;+ v.center = [200.0, 150.0];+ v.fit_pending = false;+ h.run_steps(2);+ h+ }++ /// #6286: an existing guide dragged onto a ruler with the Move tool is deleted, though the+ /// release is inside the document on the guide's own axis: the left ruler measures y, so a+ /// horizontal guide let go there still reads a y inside the canvas and used to be moved.+ #[test]+ fn a_guide_dragged_onto_a_ruler_is_deleted_through_the_canvas() {+ let mut h = canvas_harness(crate::state::Tool::Move);+ h.state_mut().run("view.newGuide", json!({"orientation": "horizontal", "position": 150})).unwrap();+ h.run_steps(1);+ let at = |h: &egui_kittest::Harness<'static, PhotocraftApp>, x: f32, y: f32| {+ let app = h.state();+ let v = &app.ui.views[0];+ let xf = ViewXform {+ rect: content_rect(app, app.last_canvas_rect),+ zoom: v.zoom,+ center: v.center,+ flip: app.ui.view.flip_horizontal,+ rotation: v.rotation,+ aspect: app.ui.view.display_aspect(),+ };+ xf.to_screen(x, y)+ };+ let on_the_guide = at(&h, 200.0, 150.0);+ // 50 document px below the press, in the left ruler's band: still inside the canvas on the+ // guide's own axis, which is where the old code moved the guide instead of removing it.+ let canvas = h.state().last_canvas_rect;+ let onto_the_left_ruler = pos2(canvas.min.x + RULER / 2.0, on_the_guide.y + 50.0);+ h.event(egui::Event::PointerMoved(on_the_guide));+ h.run_steps(1);+ h.event(egui::Event::PointerButton { pos: on_the_guide, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE });+ h.run_steps(1);+ // Past egui's click distance, so the drag starts at the press, on the guide.+ h.event(egui::Event::PointerMoved(pos2(on_the_guide.x, on_the_guide.y + 12.0)));+ h.run_steps(2);+ assert!(h.state().guide_drag.is_some(), "the Move tool takes the guide");+ h.event(egui::Event::PointerMoved(onto_the_left_ruler));+ h.run_steps(1);+ h.event(egui::Event::PointerButton {+ pos: onto_the_left_ruler,+ button: egui::PointerButton::Primary,+ pressed: false,+ modifiers: egui::Modifiers::NONE,+ });+ h.run_steps(2);+ let g = &h.state().session.active().unwrap().doc.guides;+ assert!(g.horizontal.is_empty(), "released on the left ruler: the guide is gone, got {:?}", g.horizontal);+ assert!(h.state().guide_drag.is_none(), "the drag is over");+ }+/// #3770: a guide Shift-dragged out of a ruler lands on the nearest tick the ruler draws/// (tenths of the labelled step, in the ruler unit); without Shift it lands where it's dropped.#[test]diff --git a/docs/ui-parity.md b/docs/ui-parity.mdindex 793f09840..fbddcfd0c 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-15 · **Change:** minor (Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-15 · **Change:** minor (Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; a guide let go over either ruler is removed, #6286; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, thehandles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,@@ -194,7 +194,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme| Layer and selection keys: ⌘, toggles visibility, ⌘\ targets the mask, / locks transparency, ⌘⌥2 loads luminosity, ⌘⌥⌫ fills from history, Tab / ⇧Tab rename the next layer, ⌥-click a thumbnail fits the layer | done (2026-10-11) | || Tool keys: ← / → turn the brush tip (1°, ⇧ 15°), ⇧-click with Type starts new text over old, Space+F / ⇧Space+F cycle the pasteboard colour | done (2026-10-11) | || Type formatting keys while editing text | done: ⇧⌘K, U, B, I and / toggle All Caps, Underline, Faux Bold, Faux Italic, Strikethrough (off when every selected character has it, else on); ⌥↑/↓ leading ∓2 pt, ⇧⌥↑/↓ baseline shift ±2 pt (10 with ⌘); ⌥←/→ tracking ±20 over a selection (100 with ⌘; a collapsed caret still kerns); ⌥⇧⌘H toggles Hyphenate for the touched paragraphs. One `type.setStyle` step per press (new `leadingBy`/`baselineShiftBy`/`trackingBy`; auto leading starts from its laid-out value); the global ⇧⌘K/U/B/I never fire while typing. Differs: a collapsed caret in non-empty text changes nothing, since the model can't hold a pending style for the next characters typed (empty text takes it as its typing style) (`type_tool.rs`, `input_tests.rs` `type_tool_format_keys_*`) | |-| Guides: click selects, Delete deletes, right-click menu, ⌥-click turns a guide, double-click opens Guides, Grid & Slices | done (2026-10-12) | |+| Guides: click selects, Delete deletes, right-click menu, ⌥-click turns a guide, double-click opens Guides, Grid & Slices | done (2026-10-12) | a guide let go over either ruler is removed, not only off the canvas (#6286) |## Panels and workspace@@ -227,6 +227,7 @@ Paragraph; the rest open as in-app floating windows.| Date | Change | Summary ||---|---|---|+| 2026-10-15 | minor | A guide let go over either ruler is removed, not only off the canvas: the top ruler measures document x and the left one y, so the ruler a guide was not dragged out of can lie over a coordinate inside the document (#6286) || 2026-10-13 | minor | Menu bar from the keyboard: Alt / F10 focus, Alt+letter, underlined mnemonics (#4988) || 2026-10-13 | minor | Layers panel filter row: Kind is a real dropdown with Kind, Name and Mode filters, drivable by `ui.set {layerFilter}` (#5048); row added as partial || 2026-10-13 | minor | Stale "missing tool" rows corrected against main: Color Replacement (`paint.colorReplacement`), Red Eye (`paint.redEye`) and Add/Delete Anchor Point (the P flyout cycle) are live toolbar tools, so only Art History Brush is missing; no percentage or estimate changed |