Skip to content

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

Move: Show Transform Controls frames every selected layer (#5917)

baz38b96f273aa5
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index b3693f7d8..9227c2a0f 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -3842,8 +3842,10 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
// corner badge, as Photoshop's corner radius cursor.
ui.ctx().set_cursor_icon(egui::CursorIcon::Default);
crate::icons::cursor_badge(&ctx, "scan", p);
- } else if let Some((r, p, c)) =
- response.hover_pos().and_then(|p| transform_controls_rect(app, &xf).and_then(|r| transform_controls_cursor(r, p).map(|c| (r, p, c))))
+ } else if let Some((r, p, c)) = response
+ .hover_pos()
+ .filter(|_| !transform_controls_several(app))
+ .and_then(|p| transform_controls_rect(app, &xf).and_then(|r| transform_controls_cursor(r, p).map(|c| (r, p, c))))
{
// The Move tool draws handles without opening a Free Transform session.
// Give them their resize/rotate cursors before the first pointer press (#2871).
@@ -4677,23 +4679,36 @@ pub(crate) fn layer_edges_rect(app: &PhotocraftApp, idx: usize) -> Option<photoc
Some(b.translate(dx, dy))
}
-/// Move tool › Show Transform Controls: the box Free Transform would open on the active layer.
-fn transform_controls_rect(app: &PhotocraftApp, xf: &ViewXform) -> Option<Rect> {
- // A corner radius drag hides the box, as in Photoshop.
+/// The layers Move › Show Transform Controls frames: every selected layer but the Background.
+/// A corner radius drag hides the box, as in Photoshop.
+fn transform_controls_layers(app: &PhotocraftApp) -> Vec<&photocraft_doc::Layer> {
if app.ui.tool != Tool::Move
|| !app.ui.tool_options.move_show_transform
|| app.ui.transform.is_some()
|| app.drag.is_some()
|| app.ui.corner_radius.is_some()
{
- return None;
+ return Vec::new();
}
+ let Some(st) = app.session.active() else { return Vec::new() };
+ st.selected_layers().into_iter().filter_map(|id| st.doc.layer(id)).filter(|l| !crate::doc_props_ui::is_background(&st.doc, l)).collect()
+}
+
+/// Several layers are selected: Show Transform Controls frames them all, as Photoshop does, but
+/// Free Transform works on one layer, so the frame has no handles to scale or rotate them.
+fn transform_controls_several(app: &PhotocraftApp) -> bool {
+ transform_controls_layers(app).len() > 1
+}
+
+/// Move tool › Show Transform Controls: the boxes Free Transform would open on the selected
+/// layers, joined into one.
+fn transform_controls_rect(app: &PhotocraftApp, xf: &ViewXform) -> Option<Rect> {
let st = app.session.active()?;
- let l = st.active_layer.and_then(|id| st.doc.layer(id))?;
- if crate::doc_props_ui::is_background(&st.doc, l) {
- return None;
- }
- let b = photocraft_engine::transform_cmds::transform_frame(&st.doc, l);
+ let b = transform_controls_layers(app)
+ .into_iter()
+ .map(|l| photocraft_engine::transform_cmds::transform_frame(&st.doc, l))
+ .filter(|b| !b.is_empty())
+ .reduce(|a, b| a.union(&b))?;
let (dx, dy) = crate::move_ui::floating_offset(app).unwrap_or((0, 0));
let b = b.translate(dx, dy);
if b.is_empty() {
@@ -4750,6 +4765,9 @@ fn transform_controls_hit(r: Rect, p: Pos2) -> bool {
/// Enter the existing Free Transform session when a Move-tool transform control is pressed.
fn begin_transform_controls_at(app: &mut PhotocraftApp, ctx: &egui::Context, xf: &ViewXform, p: Pos2) -> bool {
+ if transform_controls_several(app) {
+ return false;
+ }
let Some(r) = transform_controls_rect(app, xf) else { return false };
if !transform_controls_hit(r, p) {
return false;
@@ -4763,11 +4781,21 @@ fn begin_transform_controls_at(app: &mut PhotocraftApp, ctx: &egui::Context, xf:
}
}
-/// Move tool › Show Transform Controls: the active layer's bounding box with its eight handles.
+/// Move tool › Show Transform Controls: the selected layers' bounding box, with its eight handles
+/// for one layer, and the outline of every selected shape layer, as in Photoshop.
fn draw_transform_controls(app: &mut PhotocraftApp, painter: &egui::Painter, xf: &ViewXform) {
let Some(r) = transform_controls_rect(app, xf) else { return };
let accent = crate::theme::Tokens::get(painter.ctx()).accent;
+ let to_scr = |q: [f64; 2]| xf.to_screen(q[0] as f32, q[1] as f32);
+ for l in transform_controls_layers(app) {
+ if let LayerContent::Shape(sh) = &l.content {
+ crate::vector_ui::draw_outline(painter, &sh.path, &to_scr, accent);
+ }
+ }
painter.rect_stroke(r, 0.0, Stroke::new(1.0, accent), egui::StrokeKind::Middle);
+ if transform_controls_several(app) {
+ return;
+ }
for p in [r.left_top(), r.center_top(), r.right_top(), r.right_center(), r.right_bottom(), r.center_bottom(), r.left_bottom(), r.left_center()] {
let h = Rect::from_center_size(p, vec2(7.0, 7.0));
painter.rect_filled(h, 0.0, Color32::WHITE);
@@ -8109,6 +8137,37 @@ mod transform_controls_tests {
use super::*;
use serde_json::json;
+ #[test]
+ fn several_selected_layers_share_one_frame_without_handles() {
+ // As in Photoshop: Show Transform Controls frames every selected layer. Free Transform
+ // works on one layer, so the shared frame doesn't start it.
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.session.execute("file.new", json!({"width": 200, "height": 200})).unwrap();
+ app.session.execute("shape.create", json!({"kind": "rect", "rect": [20, 30, 40, 40], "fill": "#ff0000"})).unwrap();
+ let a = app.session.active().unwrap().active_layer.unwrap();
+ app.session.execute("shape.create", json!({"kind": "rect", "rect": [100, 120, 50, 30], "fill": "#ff0000"})).unwrap();
+ app.sync_views();
+ app.ui.tool = Tool::Move;
+ app.ui.tool_options.move_show_transform = true;
+ let xf =
+ ViewXform { rect: Rect::from_min_size(Pos2::ZERO, vec2(200.0, 200.0)), zoom: 1.0, center: [100.0, 100.0], flip: false, rotation: 0.0, aspect: 1.0 };
+ let one = transform_controls_rect(&app, &xf).unwrap();
+ assert!(!transform_controls_several(&app));
+ app.session.execute("layer.select", json!({"layer": a.0, "mode": "add"})).unwrap();
+ assert!(transform_controls_several(&app));
+ let both = transform_controls_rect(&app, &xf).unwrap();
+ assert!(both.contains_rect(one) && both.width() > one.width() && both.height() > one.height(), "{both:?} frames both");
+ let (lt, rb) = (xf.to_doc(both.left_top()), xf.to_doc(both.right_bottom()));
+ assert!((lt[0] - 20.0).abs() < 1e-3 && (lt[1] - 30.0).abs() < 1e-3 && (rb[0] - 150.0).abs() < 1e-3 && (rb[1] - 150.0).abs() < 1e-3, "{lt:?} {rb:?}");
+ let ctx = egui::Context::default();
+ assert!(!begin_transform_controls_at(&mut app, &ctx, &xf, both.right_bottom()));
+ assert!(app.ui.transform.is_none());
+ // The Background never joins the frame.
+ let bg = app.session.active().unwrap().doc.layers[0].id;
+ app.session.execute("layer.select", json!({"layer": bg.0, "mode": "add"})).unwrap();
+ assert_eq!(transform_controls_layers(&app).len(), 2);
+ }
+
#[test]
fn move_transform_controls_start_free_transform_for_vector_shapes() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
diff --git a/crates/ui-egui/src/move_auto_select_tests.rs b/crates/ui-egui/src/move_auto_select_tests.rs
index 3d635922e..403ab28cd 100644
--- a/crates/ui-egui/src/move_auto_select_tests.rs
+++ b/crates/ui-egui/src/move_auto_select_tests.rs
@@ -236,3 +236,24 @@ fn every_theme_shows_the_gradient_options() {
assert!(combos.iter().any(|c| c.contains("Normal")), "{theme:?}: the blend mode picker shows; combo boxes: {combos:?}");
}
}
+
+#[test]
+fn shift_click_adds_shape_layers_one_after_another() {
+ // Shapes, as in Photoshop: a click selects one, each ⇧-click adds the one under it.
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.session.execute("file.new", json!({"width": 200, "height": 200})).unwrap();
+ for rect in [[10, 10, 40, 40], [80, 10, 40, 40], [10, 100, 40, 40]] {
+ app.session.execute("shape.create", json!({"kind": "rect", "rect": rect, "fill": "#ff0000"})).unwrap();
+ }
+ app.sync_views();
+ app.ui.tool = Tool::Move;
+ app.ui.extras.snap = false;
+ app.ui.view.show.smart_guides = false;
+ let ids: Vec<LayerId> = app.session.active().unwrap().doc.layers.iter().skip(1).map(|l| l.id).collect();
+ drag(&mut app, [30.0, 30.0], [0.0, 0.0], egui::Modifiers::NONE);
+ drag(&mut app, [100.0, 30.0], [0.0, 0.0], egui::Modifiers::SHIFT);
+ drag(&mut app, [30.0, 120.0], [0.0, 0.0], egui::Modifiers::SHIFT);
+ let mut selected = app.session.active().unwrap().selected_layers();
+ selected.sort_by_key(|l| l.0);
+ assert_eq!(selected, ids);
+}
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 7fbe8932c..d8d29122c 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-14 · **Change:** minor (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-14 · **Change:** minor (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
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,
@@ -96,6 +96,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
| ⌥-drag duplicates, ⇧ constrains to 45° | done | `move_mods.rs` |
| Auto-Select with hover outline, box-select layers, double-click fit | missing | TOOL-214-4 |
| Auto-Select bounding box and snapping follow the picked layer | partial | follow the previous layer (#2666) |
+| Several layers selected (⇧-click adds, box-select): Show Transform Controls frames them all, with every selected shape's outline | partial: the shared frame has no handles, since Free Transform works on one layer (`canvas.rs` `transform_controls_layers`, `several_selected_layers_share_one_frame_without_handles`; `move_auto_select_tests.rs`) | |
| ⌘-drag temporary Move shows the box and snaps | partial | #2681 |
| ⌘-right-click layer list under the pointer | done | `layer_pick_ui.rs` |
| Double-click type to edit it (caret at the pointer, Type tool) | done | #1132, `type_tool::edit_at` |
@@ -253,3 +254,4 @@ Paragraph; the rest open as in-app floating windows.
| 2026-10-11 | minor | Pen ⇧ 45° done: ⇧-click puts the next anchor on the nearest 45° ray, ⇧-drag turns its handles in 45° steps (TOOL-214-10 done, #3751) |
| 2026-10-14 | minor | Last selected tool restored across launches; temporary overrides excluded, explicit Eraser choices retained, and final selection flushed on normal exit |
| 2026-10-13 | minor | Free Transform with a selection: the box is the selection's rectangle, and the marching ants follow it while it is transformed (#5297) |
+| 2026-10-14 | minor | Move › Show Transform Controls frames every selected layer and outlines the selected shapes |