From ba9065fcfce0e96b6202ea9559584a43f013e7fd Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 27 Nov 2026 21:41:50 +0100 Subject: [PATCH 1/2] Free Transform: grey Warp for a group box (#16731) A box over a group now opens with warp off, as the box over several layers does: Warp is greyed in its right-click menu and Edit > Transform > Warp (with the split-warp rows) is greyed while it is open. Warp asked through automation, or from the menu with no box open, refuses on a group instead of opening a plain box. Pixel, type and smart object layers keep Warp. --- .../ui-egui/src/tools/transform_tool/begin.rs | 28 +++++++-- .../src/tools/transform_tool/commit.rs | 6 +- .../transform_tool/group_warp_greyed_tests.rs | 58 +++++++++++++++++++ .../ui-egui/src/tools/transform_tool/tests.rs | 3 + 4 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 crates/ui-egui/src/tools/transform_tool/group_warp_greyed_tests.rs diff --git a/crates/ui-egui/src/tools/transform_tool/begin.rs b/crates/ui-egui/src/tools/transform_tool/begin.rs index c90ea547e70..0756c0cfff6 100644 --- a/crates/ui-egui/src/tools/transform_tool/begin.rs +++ b/crates/ui-egui/src/tools/transform_tool/begin.rs @@ -24,7 +24,7 @@ fn type_allow(typed: bool) -> BoxAllow { } /// The session over the source frame `rect`: the stored settings, the interpolation default and the nudge pause. -/// `warp_ok` is false where the content cannot warp (a lone mask or channel, several layers, Content-Aware Scale). +/// `warp_ok` is false where the content cannot warp (a lone mask or channel, several layers, a group, Content-Aware Scale). fn open_session(app: &PhotocraftApp, rect: [f64; 4], allow: BoxAllow, warp_ok: bool) -> TransformSession { TransformSession::new(frame_of(rect)) .allow(allow.with_warp(warp_ok)) @@ -130,6 +130,8 @@ pub fn begin(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String> let opacity = layer.opacity * layer.fill_opacity; let whole = lifted.is_none(); let allow = type_allow(matches!(layer.content, LayerContent::Text(_))); + // A group doesn't warp, as several layers don't (#16731). + let warp_ok = !frame_only && !matches!(layer.content, LayerContent::Group(_)); // Reading the moving pixels and compositing the layers over them is the heavy part: hundreds // of megapixels on a large canvas. Done on the UI thread, the window stopped answering for // long enough that a Wayland compositor dropped it, so a large layer prepares as a job @@ -161,7 +163,7 @@ pub fn begin(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String> ..OpenPreview::new(session, shown, textures, app.ui.tool) }); app.ui.transform = Some(FreeTransform { - session: open_session(app, rect, allow, !frame_only), + session: open_session(app, rect, allow, warp_ok), id: session, layer: id.0, layers: Vec::new(), @@ -373,9 +375,23 @@ pub(super) fn moves_kind(app: &PhotocraftApp, t: &FreeTransform, kind: fn(&Layer app.session.active().is_some_and(|st| moving_layers(t).iter().any(|id| st.doc.layer(*id).is_some_and(|l| kind(&l.content)))) } +/// Does the box move a group as one layer (not its mask, a path or a selection outline)? +pub(super) fn moves_group(app: &PhotocraftApp, t: &FreeTransform) -> bool { + t.layers.is_empty() && !t.selection && t.target.is_none() && t.path.is_none() && moves_kind(app, t, |c| matches!(c, LayerContent::Group(_))) +} + /// Why Warp refuses with several layers selected. pub const WARP_ONE_LAYER: &str = "Warp works on one layer at a time: select a single layer"; +/// Why Warp refuses on a group (#16731). +pub const WARP_GROUP: &str = "Warp doesn't work on a group"; + +/// Why the open box can't warp: several layers (#6501) or a group (#16731). +fn warp_refusal(app: &PhotocraftApp) -> Option<&'static str> { + let t = app.ui.transform.as_ref()?; + if !t.layers.is_empty() { Some(WARP_ONE_LAYER) } else { moves_group(app, t).then_some(WARP_GROUP) } +} + /// 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> { @@ -688,14 +704,14 @@ pub fn begin_warp(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), St if app.ui.transform.as_ref().is_some_and(|t| t.content_aware.is_some()) { return Err(CAS_ONLY_SCALES.into()); } - if app.ui.transform.as_ref().is_some_and(|t| !t.layers.is_empty()) { - return Err(WARP_ONE_LAYER.into()); + if let Some(why) = warp_refusal(app) { + return Err(why.into()); } if app.ui.transform.is_none() { begin(app, ctx)?; - if app.ui.transform.as_ref().is_some_and(|t| !t.layers.is_empty()) { + if let Some(why) = warp_refusal(app) { cancel(app); - return Err(WARP_ONE_LAYER.into()); + return Err(why.into()); } } enter_warp(app, ctx); diff --git a/crates/ui-egui/src/tools/transform_tool/commit.rs b/crates/ui-egui/src/tools/transform_tool/commit.rs index 8dc1166dcb7..7829c4c3af3 100644 --- a/crates/ui-egui/src/tools/transform_tool/commit.rs +++ b/crates/ui-egui/src/tools/transform_tool/commit.rs @@ -2,7 +2,7 @@ use craft::behavior::EditEvent; use craft::behavior::kurbo::Point; use craft::draw::ui::transform::{TransformEdit, TransformRequest}; -use super::begin::{fold_made, moves_kind, moving_layers, rect_to_quad_affine, take_back_made}; +use super::begin::{fold_made, moves_group, moves_kind, moving_layers, rect_to_quad_affine, take_back_made}; use super::{ Arc, DocId, FreeTransform, JobEvent, JobId, JobOutcome, LayerContent, LayerId, MadeLayer, OpenPreview, PhotocraftApp, SessionWarp, Several, json, preset_for_command, swap_mode_texels, @@ -414,14 +414,14 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> Option { SAVE_FOR_WEB | COPY_CSS => Some(false), // Rotate and Flip turn the box (not while warping, where the mesh is the box). _ if preset_for_command(id).is_some() => Some(t.session.warp().is_none()), - // One box over several layers doesn't warp (#6501). + // One box over several layers doesn't warp (#6501), nor one over a group (#16731). "edit.transform.warp" | "layer.smartObjects.warp" | "edit.transform.splitWarpCrosswise" | "edit.transform.splitWarpHorizontally" | "edit.transform.splitWarpVertically" | "edit.transform.removeWarpSplit" - if !t.layers.is_empty() => + if !t.layers.is_empty() || moves_group(app, t) => { Some(false) } diff --git a/crates/ui-egui/src/tools/transform_tool/group_warp_greyed_tests.rs b/crates/ui-egui/src/tools/transform_tool/group_warp_greyed_tests.rs new file mode 100644 index 00000000000..70cc70293fe --- /dev/null +++ b/crates/ui-egui/src/tools/transform_tool/group_warp_greyed_tests.rs @@ -0,0 +1,58 @@ +//! #16731: a box over a group doesn't warp, as one over several layers doesn't; a box over one +//! layer of any other kind still does. + +use super::*; +use crate::transform_tool::begin::WARP_GROUP; + +/// The Edit › Transform rows of the Warp block. +const WARP_BLOCK: [&str; 5] = [ + "edit.transform.warp", + "edit.transform.splitWarpCrosswise", + "edit.transform.splitWarpHorizontally", + "edit.transform.splitWarpVertically", + "edit.transform.removeWarpSplit", +]; + +/// Is the Warp row of the open box's right-click menu enabled? +fn warp_row(app: &PhotocraftApp) -> bool { + let words = TransformMenuWords::english(); + open(app).session.menu(&words).iter().find(|e| matches!(e.value(), Some(TransformChoice::Warp))).map(|e| e.is_enabled()).expect("the menu has a Warp row") +} + +#[test] +fn a_group_box_greys_warp_in_its_menu_and_in_edit_transform() { + let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + let ctx = app.ctx().clone(); + app.session.execute("layer.new.groupFromLayers", json!({})).unwrap(); + let st = app.session.active().unwrap(); + assert!(st.active_layer.and_then(|id| st.doc.layer(id)).is_some_and(|l| matches!(l.content, LayerContent::Group(_))), "the group is active"); + begin(&mut app, &ctx).unwrap(); + assert!(open(&app).layers.is_empty(), "a box over the group as one layer"); + assert!(!warp_row(&app), "Warp is greyed in the box's menu"); + for id in WARP_BLOCK { + assert!(!crate::menus::is_enabled(&app, id), "{id} is greyed while the group box is open"); + } + // Asked anyway (automation), Warp refuses and leaves the box as it was. + assert_eq!(begin_warp(&mut app, &ctx), Err(WARP_GROUP.into())); + assert!(open(&app).session.warp().is_none(), "the box doesn't switch to Warp"); + cancel(&mut app); + // With no box open, Warp refuses without leaving one behind. + assert_eq!(begin_warp(&mut app, &ctx), Err(WARP_GROUP.into())); + assert!(app.ui.transform.is_none(), "no box is left open"); +} + +#[test] +fn single_pixel_type_and_smart_object_layers_keep_warp() { + let ctx = egui::Context::default(); + let pixel = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + let mut typed = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + typed.run("type.create", json!({"x": 10, "y": 40, "text": "Hi"})).unwrap(); + let mut smart = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24)); + smart.session.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + for (name, mut app) in [("pixel", pixel), ("type", typed), ("smart object", smart)] { + begin(&mut app, &ctx).unwrap(); + assert!(warp_row(&app), "a {name} layer's box offers Warp"); + assert!(crate::menus::is_enabled(&app, "edit.transform.warp"), "Edit › Transform › Warp is live over a {name} layer"); + cancel(&mut app); + } +} diff --git a/crates/ui-egui/src/tools/transform_tool/tests.rs b/crates/ui-egui/src/tools/transform_tool/tests.rs index 1a6a44c965a..a445c57098e 100644 --- a/crates/ui-egui/src/tools/transform_tool/tests.rs +++ b/crates/ui-egui/src/tools/transform_tool/tests.rs @@ -2219,3 +2219,6 @@ fn an_unskewed_box_shows_its_horizontal_skew_as_zero() { #[path = "warp_remove_split_tests.rs"] mod warp_remove_split_tests; + +#[path = "group_warp_greyed_tests.rs"] +mod group_warp_greyed_tests; From 17252c46254519ac3181713678d668086b4c0357 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 27 Nov 2026 22:28:57 +0100 Subject: [PATCH 2/2] Free Transform: refuse group Warp before a background prepare, grey it during a commit (#16731) A large group's box opens only when its preparing job lands, so Warp now checks for a group before Free Transform starts. The open-box rule that greys the Warp block for several layers or a group now runs before the pending-commit branch too. --- .../ui-egui/src/tools/transform_tool/begin.rs | 18 +++++++++++++ .../src/tools/transform_tool/commit.rs | 25 +++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/tools/transform_tool/begin.rs b/crates/ui-egui/src/tools/transform_tool/begin.rs index 0756c0cfff6..53ad4b623d7 100644 --- a/crates/ui-egui/src/tools/transform_tool/begin.rs +++ b/crates/ui-egui/src/tools/transform_tool/begin.rs @@ -392,6 +392,21 @@ fn warp_refusal(app: &PhotocraftApp) -> Option<&'static str> { if !t.layers.is_empty() { Some(WARP_ONE_LAYER) } else { moves_group(app, t).then_some(WARP_GROUP) } } +/// Would [`begin`] box the active group as one layer? Asked before it runs: a large layer's box +/// opens only when its preparing job lands, too late for [`warp_refusal`]. +fn opens_group_box(app: &PhotocraftApp) -> bool { + if crate::vector_ui::free_transform_path(app).is_some() { + return false; + } + let target = crate::canvas::paint_target(app); + let Some(st) = app.session.active() else { return false }; + let Some(id) = st.active_layer else { return false }; + let targets = photocraft_engine::transform_cmds::box_targets(&st.doc, &photocraft_engine::transform_cmds::selection_targets(st)); + targets == [id] + && photocraft_engine::transform_cmds::lone_target(&st.doc, Some(id), &json!({ "target": target })).is_ok_and(|t| t.is_none()) + && st.doc.layer(id).is_some_and(|l| matches!(l.content, LayerContent::Group(_))) +} + /// 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> { @@ -708,6 +723,9 @@ pub fn begin_warp(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), St return Err(why.into()); } if app.ui.transform.is_none() { + if opens_group_box(app) { + return Err(WARP_GROUP.into()); + } begin(app, ctx)?; if let Some(why) = warp_refusal(app) { cancel(app); diff --git a/crates/ui-egui/src/tools/transform_tool/commit.rs b/crates/ui-egui/src/tools/transform_tool/commit.rs index 7829c4c3af3..29276a32069 100644 --- a/crates/ui-egui/src/tools/transform_tool/commit.rs +++ b/crates/ui-egui/src/tools/transform_tool/commit.rs @@ -398,6 +398,20 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> Option { return Some(false); } let t = app.ui.transform.as_ref()?; + // One box over several layers doesn't warp (#6501), nor one over a group (#16731), and not + // while its commit runs either. + if matches!( + id, + "edit.transform.warp" + | "layer.smartObjects.warp" + | "edit.transform.splitWarpCrosswise" + | "edit.transform.splitWarpHorizontally" + | "edit.transform.splitWarpVertically" + | "edit.transform.removeWarpSplit" + ) && (!t.layers.is_empty() || moves_group(app, t)) + { + return Some(false); + } if committing(app).is_some() { return box_command(id).then_some(false); } @@ -414,17 +428,6 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> Option { SAVE_FOR_WEB | COPY_CSS => Some(false), // Rotate and Flip turn the box (not while warping, where the mesh is the box). _ if preset_for_command(id).is_some() => Some(t.session.warp().is_none()), - // One box over several layers doesn't warp (#6501), nor one over a group (#16731). - "edit.transform.warp" - | "layer.smartObjects.warp" - | "edit.transform.splitWarpCrosswise" - | "edit.transform.splitWarpHorizontally" - | "edit.transform.splitWarpVertically" - | "edit.transform.removeWarpSplit" - if !t.layers.is_empty() || moves_group(app, t) => - { - Some(false) - } // Editable type can't be distorted (#2630, as #2701 rules for the menus outside a box). "edit.transform.distort" | "edit.transform.perspective" if moves_type(app, t) => Some(false), _ => None,