Skip to content

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

Merge origin/main into fix/6550-selected-path-outline

David Mannbac554b181b3
diff --cc crates/ui-egui/src/vector_ui.rs
index 9878e10b8,205e47aaf..d5388001b
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@@ -978,15 -978,15 +978,23 @@@ pub(crate) fn draw_handle(painter: &egu
painter.circle_filled(handle, 3.0, accent);
}
+ /// Does `tool` draw the anchor squares of the paths it can edit? Path Selection does, and so do
+ /// the Pen tools: as in Photoshop, a path finished with Enter or by closing it keeps its anchors
+ /// on screen, so it can still be edited (⌘/Ctrl-drag, Auto Add/Delete) (#6884, #4716).
+ pub(crate) fn shows_anchors(tool: Tool) -> bool {
+ // Add/Delete Anchor Point and Convert Point draw Direct Selection's overlay instead.
+ matches!(tool, Tool::PathSelection | Tool::Pen | Tool::FreeformPen | Tool::CurvaturePen)
+ }
+
-/// Work path / active shape path outlines, anchors, and the pen path in progress.
+/// The saved path selected in the Paths panel: Photoshop's target path, drawn on the canvas with
+/// any tool (#6550). `None` when the panel selects the work path, a layer's path or nothing.
+pub(crate) fn selected_saved_path(app: &PhotocraftApp) -> Option<&Path> {
+ let sel = app.ui.selected_path.as_deref().filter(|s| !matches!(*s, "work" | "layer"))?;
+ app.session.active()?.doc.paths.iter().find(|p| p.name == sel).map(|p| &p.path)
+}
+
+/// Work path / active shape path / selected saved path outlines, anchors, and the pen path in
+/// progress.
pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform, doc: &Document) {
let tool = app.ui.tool;
let accent = Tokens::get(painter.ctx()).accent;
@@@ -1013,15 -1009,12 +1021,16 @@@
crate::anchor_tools::draw_hover(app, painter, &to_scr, accent, painter.ctx().input(|i| i.modifiers));
}
} else if paths {
- // Paths remain visible as outlines with any tool. Path Selection adds anchor squares; Direct
- // Selection has its own overlay above.
+ // Paths remain visible as outlines with any tool. Path Selection and the Pen tools add
+ // anchor squares; Direct Selection has its own overlay above.
+ let anchors = shows_anchors(tool);
if let Some(wp) = &doc.work_path {
- draw_path(wp, tool == Tool::PathSelection);
+ draw_path(wp, anchors);
}
+ // The saved path selected in the Paths panel is the target path (#6550).
+ if let Some(p) = selected_saved_path(app) {
- draw_path(p, tool == Tool::PathSelection);
++ draw_path(p, anchors);
+ }
let st = app.session.active();
if let Some(l) = st.and_then(|s| s.active_layer.and_then(|id| s.doc.layer(id)))
&& let LayerContent::Shape(sh) = &l.content
@@@ -2088,44 -2105,6 +2121,46 @@@ mod tests
assert!(overlay_shapes(&app, &ctx) > 0, "the pen path in progress is still drawn");
}
+ #[test]
+ fn the_saved_path_selected_in_the_paths_panel_is_drawn() {
+ // #6550: selecting a saved path in the Paths panel drew nothing on the canvas.
+ let ctx = egui::Context::default();
+ let mut app = app();
+ let tri = |o: f64| {
+ json!({"subpaths": [{"closed": true, "knots": [
+ {"anchor": [20.0 + o, 20], "in": [20.0 + o, 20], "out": [20.0 + o, 20]},
+ {"anchor": [90.0 + o, 20], "in": [90.0 + o, 20], "out": [90.0 + o, 20]},
+ {"anchor": [90.0 + o, 90], "in": [90.0 + o, 90], "out": [90.0 + o, 90]}
+ ]}]})
+ };
+ app.run("path.set", json!({"name": "Path 1", "path": tri(0.0)})).unwrap();
+ app.run("path.set", json!({"name": "Path 2", "path": tri(10.0)})).unwrap();
+ assert!(app.session.active().unwrap().doc.work_path.is_none());
+ for tool in [Tool::Move, Tool::Brush, Tool::Pen, Tool::PathSelection, Tool::DirectSelection] {
+ app.ui.tool = tool;
+ app.ui.selected_path = None;
+ assert_eq!(overlay_shapes(&app, &ctx), 0, "{tool:?}: nothing selected, nothing drawn");
+ app.ui.selected_path = Some("Path 1".into());
+ assert_eq!(selected_saved_path(&app).map(|p| p.subpaths[0].knots[0].anchor.x), Some(20.0));
+ assert!(overlay_shapes(&app, &ctx) > 0, "{tool:?}: the selected saved path is drawn");
+ app.ui.selected_path = Some("Path 2".into());
+ assert_eq!(selected_saved_path(&app).map(|p| p.subpaths[0].knots[0].anchor.x), Some(30.0));
+ app.ui.selected_path = Some("Gone".into());
+ assert_eq!(overlay_shapes(&app, &ctx), 0, "{tool:?}: a missing path draws nothing");
+ app.ui.selected_path = Some("Path 1".into());
+ app.ui.view.show.target_path = false;
+ assert_eq!(overlay_shapes(&app, &ctx), 0, "{tool:?}: View > Show > Target Path off");
+ app.ui.view.show.target_path = true;
+ }
- // Path Selection adds its anchor squares (the outline plus three anchors, two shapes each).
++ // Path Selection (and the Pen tools, as for the work path) add anchor squares.
+ app.ui.tool = Tool::Move;
+ let plain = overlay_shapes(&app, &ctx);
+ app.ui.tool = Tool::PathSelection;
+ assert!(overlay_shapes(&app, &ctx) > plain);
++ app.ui.tool = Tool::Pen;
++ assert!(overlay_shapes(&app, &ctx) > plain);
+ }
+
#[test]
fn shape_drag_creates_layers_with_modifiers() {
let mut app = app();