Skip to content

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

fix(transform): keep artboard paper below child previews

chiharumurabayashi-stack6b5b64bfca97
diff --git a/crates/ui-egui/src/transform_tool.rs b/crates/ui-egui/src/transform_tool.rs
index 7ae223029..2c515d6e3 100644
--- a/crates/ui-egui/src/transform_tool.rs
+++ b/crates/ui-egui/src/transform_tool.rs
@@ -983,7 +983,14 @@ fn show_only(layers: &mut [photocraft_doc::Layer], keep: &[LayerId]) {
continue;
}
match &mut l.content {
- LayerContent::Group(g) if g.children.iter().any(|c| keep.iter().any(|k| contains(c, *k))) => show_only(&mut g.children, keep),
+ LayerContent::Group(g) if g.children.iter().any(|c| keep.iter().any(|k| contains(c, *k))) => {
+ // This ancestor only clips the covering children. Its background is already
+ // on the base canvas; drawing it again would cover the moving layer in white.
+ if let Some(board) = &mut g.artboard {
+ board.background = photocraft_doc::ArtboardBackground::Transparent;
+ }
+ show_only(&mut g.children, keep);
+ }
_ => l.visible = false,
}
}
@@ -1002,6 +1009,10 @@ pub(crate) fn solo_layer(layers: &mut [photocraft_doc::Layer], id: LayerId) {
match &mut l.content {
LayerContent::Group(g) if g.children.iter().any(|c| contains(c, id)) => {
l.clipped = false;
+ // Isolate the child, not the artboard's paper. Keep the board for clipping.
+ if let Some(board) = &mut g.artboard {
+ board.background = photocraft_doc::ArtboardBackground::Transparent;
+ }
solo_layer(&mut g.children, id);
}
_ => l.visible = false,
@@ -4954,6 +4965,80 @@ mod tests {
);
}
+ fn artboard_preview_app(background: photocraft_doc::ArtboardBackground) -> (PhotocraftApp, LayerId, LayerId) {
+ use photocraft_doc::{Artboard, Layer};
+ let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24));
+ let st = app.session.active_mut().unwrap();
+ let doc = Arc::make_mut(&mut st.doc);
+ let red = doc.layers.pop().unwrap();
+ let red_id = red.id;
+ let mut blue = Layer::raster("covering blue", photocraft_color::PixelFormat::RGBA8);
+ blue.surface_mut().unwrap().fill_rect(photocraft_geom::Rect::new(16, 16, 40, 40), &[0.0, 0.0, 1.0, 1.0]);
+ let mut board = Layer::group("board", vec![red, blue]);
+ let board_id = board.id;
+ if let LayerContent::Group(g) = &mut board.content {
+ let mut ab = Artboard::new(photocraft_geom::Rect::new(0, 0, 64, 64));
+ ab.background = background;
+ g.artboard = Some(ab);
+ }
+ doc.layers = vec![board];
+ (app, board_id, red_id)
+ }
+
+ #[test]
+ fn artboard_transform_overlay_does_not_cover_moving_pixels_with_the_board_background() {
+ use photocraft_doc::ArtboardBackground;
+ for background in [ArtboardBackground::White, ArtboardBackground::Black] {
+ let (mut app, board_id, red_id) = artboard_preview_app(background);
+ let original = app.session.active().unwrap().doc.clone();
+ begin(&mut app, &gpu_ctx()).unwrap();
+ let pv = app.transform_preview.as_ref().unwrap();
+ let (texture, rect) = pv.above.as_ref().unwrap().shown.as_ref().unwrap();
+ let (image, _) = texture.level_image(0).unwrap();
+ let at = |x: i32, y: i32| image.pixels[(y - rect.y0) as usize * image.size[0] + (x - rect.x0) as usize];
+ assert_eq!(at(12, 12), Color32::TRANSPARENT, "the board background belongs under the moving layer");
+ assert_eq!(at(20, 20), Color32::BLUE, "covering siblings must still cover the moving layer");
+ let under = photocraft_compose::render(&pv.doc, photocraft_geom::Rect::new(0, 0, 64, 64));
+ assert_eq!(under.px[12 * 64 + 12], background.rgba().unwrap(), "the board background remains on the base canvas");
+ assert!(!pv.doc.layer(red_id).unwrap().visible);
+ cancel(&mut app);
+ let LayerContent::Group(g) = &app.session.active().unwrap().doc.layer(board_id).unwrap().content else { panic!("board") };
+ assert_eq!(g.artboard.as_ref().unwrap().background, background);
+ assert!(Arc::ptr_eq(&app.session.active().unwrap().doc, &original), "preview and cancellation do not edit the document");
+ }
+ }
+
+ #[test]
+ fn artboard_solo_preview_keeps_holes_transparent_and_the_board_clip() {
+ use photocraft_doc::ArtboardBackground;
+ let (app, board_id, red_id) = artboard_preview_app(ArtboardBackground::White);
+ let original = &app.session.active().unwrap().doc;
+ let mut solo = (**original).clone();
+ solo.layer_mut(red_id).unwrap().surface_mut().unwrap().fill_rect(photocraft_geom::Rect::new(-2, -2, 1, 1), &[1.0, 0.0, 0.0, 1.0]);
+ solo_layer(&mut solo.layers, red_id);
+ let b = photocraft_geom::Rect::new(-2, -2, 66, 66);
+ let rendered = photocraft_compose::render(&solo, b);
+ let at = |x: i32, y: i32| rendered.px[(y + 2) as usize * 68 + (x + 2) as usize];
+ assert_eq!(at(12, 12), [1.0, 0.0, 0.0, 1.0]);
+ assert_eq!(at(30, 30), [0.0; 4], "neither the board's white nor another child enters the moving texture");
+ assert_eq!(at(-1, -1), [0.0; 4], "the artboard still clips its children");
+ let LayerContent::Group(g) = &solo.layer(board_id).unwrap().content else { panic!("board") };
+ assert!(g.artboard.is_some(), "keep the board boundary while omitting its background");
+ }
+
+ #[test]
+ fn artboard_moved_as_a_whole_keeps_its_background() {
+ use photocraft_doc::ArtboardBackground;
+ let (app, board_id, _) = artboard_preview_app(ArtboardBackground::Black);
+ let mut doc = (*app.session.active().unwrap().doc).clone();
+ solo_layer(&mut doc.layers, board_id);
+ let rendered = photocraft_compose::render(&doc, photocraft_geom::Rect::new(0, 0, 64, 64));
+ assert_eq!(rendered.px[50 * 64 + 50], [0.0, 0.0, 0.0, 1.0]);
+ show_only(&mut doc.layers, &[board_id]);
+ let rendered = photocraft_compose::render(&doc, photocraft_geom::Rect::new(0, 0, 64, 64));
+ assert_eq!(rendered.px[50 * 64 + 50], [0.0, 0.0, 0.0, 1.0], "a whole covering artboard keeps its own background");
+ }
+
#[test]
fn nested_group_preview_detaches_every_clipped_ancestor() {
use photocraft_color::PixelFormat;
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 793f09840..c025474ee 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-20 · **Change:** minor (artboard backgrounds remain below child Free Transform previews; 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
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,
@@ -257,3 +257,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-20 | minor | Free Transform of an artboard child omits ancestor paper from the covering and isolated composites while retaining board clipping. The base canvas and whole-artboard backgrounds are preserved; synthetic regressions in `transform_tool.rs`. No parity percentage changed. |