fix(ui): address multi-layer transform review

This commit is contained in:
eiketre committed 2026-10-22 17:59:54 +02:00
1 parent 0ef00d2b89
commit 205b332029
3 files changed
+68 -3

No files matched your search

+37 -1
View File
@@ -4971,7 +4971,12 @@ fn transform_controls_layers(app: &PhotocraftApp) -> Vec<&photocraft_doc::Layer>
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()
let layers: Vec<_> =
st.selected_layers().into_iter().filter_map(|id| st.doc.layer(id)).filter(|l| !crate::doc_props_ui::is_background(&st.doc, l)).collect();
if layers.len() > 1 && layers.iter().any(|l| photocraft_engine::transform_cmds::locked_for_transform(&st.doc, l.id)) {
return Vec::new();
}
layers
}
/// Several layers are selected: Show Transform Controls frames and transforms them together.
@@ -8632,6 +8637,37 @@ mod transform_controls_tests {
assert_eq!(photocraft_engine::transform_cmds::whole_layer_bounds(&st.doc, st.doc.layer(b).unwrap()), photocraft_geom::Rect::new(110, 125, 160, 155));
}
#[test]
fn shared_transform_controls_hide_if_any_selected_layer_is_locked() {
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();
let b = app.session.active().unwrap().active_layer.unwrap();
app.session.execute("layer.select", json!({"layer": a.0, "mode": "add"})).unwrap();
app.session
.edit("lock", |doc, _| {
doc.layer_mut(b).unwrap().locks.position = true;
Ok(())
})
.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 };
assert!(transform_controls_layers(&app).is_empty(), "a shared box that cannot start must not be shown");
assert!(transform_controls_rect(&app, &xf).is_none());
// Preserve the existing single-layer behaviour: a locked layer still shows its controls;
// pressing one reports the lock rather than silently removing the frame.
app.session.execute("layer.select", json!({"layer": b.0})).unwrap();
assert_eq!(transform_controls_layers(&app).len(), 1);
assert!(transform_controls_rect(&app, &xf).is_some());
}
#[test]
fn move_transform_controls_start_free_transform_for_vector_shapes() {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+30
View File
@@ -206,6 +206,9 @@ fn corners(r: [f64; 4]) -> [[f64; 2]; 4] {
/// Start Free Transform on the active layer (or its selected pixels), or on the targeted unlinked
/// layer mask, alpha channel or Quick Mask.
pub fn begin(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String> {
if app.multi_transform.is_some() {
return Err("Commit or cancel the transform first".into());
}
if let Some((params, path)) = crate::vector_ui::free_transform_path(app) {
return begin_path(app, ctx, params, path);
}
@@ -367,6 +370,9 @@ pub(crate) fn begin_layers(app: &mut PhotocraftApp, layers: Vec<LayerId>, rect:
/// Free Transform on a copy (⌥⌘T, no menu item): duplicates the active layer (with a selection,
/// its selected pixels, as Layer via Copy) and transforms the copy (#352).
pub fn begin_copy(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String> {
if app.multi_transform.is_some() {
return Err("Commit or cancel the transform first".into());
}
let selection = app.session.active().is_some_and(|d| d.doc.selection.is_some());
let params = if selection { json!({}) } else { json!({"inPlace": true}) };
app.run(if selection { "layer.new.layerViaCopy" } else { "layer.duplicate" }, params)?;
@@ -4412,6 +4418,30 @@ mod tests {
assert_eq!(app.session.active().unwrap().doc.layers.len(), layers);
}
#[test]
fn free_transform_copy_rejects_an_open_multi_transform_without_making_a_layer() {
let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24));
let first = app.session.active().unwrap().active_layer.unwrap();
app.session.execute("layer.new.layer", json!({})).unwrap();
let second = app.session.active().unwrap().active_layer.unwrap();
app.session
.edit("paint second", |doc, _| {
doc.layer_mut(second).unwrap().surface_mut().unwrap().fill_rect(photocraft_geom::Rect::new(32, 8, 48, 24), &[0.0, 1.0, 0.0, 1.0]);
Ok(())
})
.unwrap();
begin_layers(&mut app, vec![first, second], [8.0, 8.0, 48.0, 24.0]).unwrap();
let before = {
let st = app.session.active().unwrap();
(st.doc.layers.len(), st.revision, st.history.past_len())
};
assert_eq!(begin_copy(&mut app, &egui::Context::default()), Err("Commit or cancel the transform first".into()));
let st = app.session.active().unwrap();
assert_eq!((st.doc.layers.len(), st.revision, st.history.past_len()), before, "a rejected start is mutation-free");
assert!(app.multi_transform.is_some() && app.ui.transform.is_some(), "the existing transform stays open");
}
/// #1099: cancel, frame cleanup and a commit before the next frame all belong to the
/// original document, including after tab reordering and with shared layer IDs.
#[test]
+1 -2
View File
@@ -96,7 +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 | done: the shared frame has eight transform handles and opens one multi-layer Free Transform; scale/rotate/skew are previewed and committed to all selected top-level layers in one history step (`canvas.rs` `transform_controls_layers`, `several_selected_layers_share_one_frame_with_handles_and_transform_session`; `transform_tool.rs`; `transform_cmds.rs`) | |
| Several layers selected (⇧-click adds, box-select): Show Transform Controls frames them all, with every selected shape's outline | done | The shared frame has eight transform handles and opens one multi-layer Free Transform; scale/rotate/skew are previewed and committed to all selected top-level layers in one history step (`canvas.rs` `transform_controls_layers`, `several_selected_layers_share_one_frame_with_handles_and_transform_session`; `transform_tool.rs`; `transform_cmds.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` |
@@ -262,5 +262,4 @@ Paragraph; the rest open as in-app floating windows.
| 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 |
| 2026-10-22 | minor | Move › Show Transform Controls: multi-layer selections now show all eight handles and transform the selected top-level layers together in one Free Transform/history step |