From ea5e7effede2cbd8df8af0a1e0eb82e5f34ed27a Mon Sep 17 00:00:00 2001 From: SiFuMax09 Date: Thu, 29 Oct 2026 02:13:44 +0100 Subject: [PATCH] Move: estimate exactly what moved_target shifts (a group's contents, a mask-only drag leaves them); tighten the sparse test --- crates/ui-egui/src/canvas/move_ui.rs | 27 +++++++++++++------- crates/ui-egui/src/canvas/move_ui/tests.rs | 29 +++++++++++++++++++++- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/canvas/move_ui.rs b/crates/ui-egui/src/canvas/move_ui.rs index 172616cb14..5c4d537815 100644 --- a/crates/ui-egui/src/canvas/move_ui.rs +++ b/crates/ui-egui/src/canvas/move_ui.rs @@ -72,16 +72,25 @@ fn shift_bytes(s: &photocraft_raster::Surface) -> u64 { tiles.saturating_mul(t * t).saturating_mul(s.format().bytes_per_pixel() as u64) } -/// Whether the pixel memory a live drag frame writes for the layers `ids` of `doc` exceeds `limit`: -/// what `moved_target` shifts, that is a layer's content and linked mask, or only its mask when -/// `mask_target` drags an unlinked mask alone. +/// Whether the pixel memory a live drag frame writes for the move targets `ids` of `doc` exceeds +/// `limit`, counting what `moved_target` shifts: a target whose unlinked mask is dragged alone +/// (`mask_target`) copies that mask only and its descendants stay put; any other target shifts its +/// content and linked mask, and every layer inside it likewise (a group's contents move whole). fn exceeds(doc: &Document, ids: &[LayerId], limit: u64, mask_target: bool) -> bool { let mut total = 0u64; - for l in ids.iter().filter_map(|id| doc.layer(*id)) { - let mask_alone = mask_target && photocraft_engine::layer_multi_cmds::moves_mask_alone(l); - let content = if mask_alone { 0 } else { l.surface().map_or(0, shift_bytes) }; - let mask = l.mask.as_ref().filter(|m| mask_alone || m.linked).map_or(0, |m| shift_bytes(&m.surface)); - total = total.saturating_add(content).saturating_add(mask); + for id in ids { + let Some(root) = doc.layer(*id) else { continue }; + let moving = if mask_target && photocraft_engine::layer_multi_cmds::moves_mask_alone(root) { + total = total.saturating_add(root.mask.as_ref().map_or(0, |m| shift_bytes(&m.surface))); + Vec::new() + } else { + with_descendants(doc, &[*id]) + }; + for l in moving.iter().filter_map(|d| doc.layer(*d)) { + let content = l.surface().map_or(0, shift_bytes); + let mask = l.mask.as_ref().filter(|m| m.linked).map_or(0, |m| shift_bytes(&m.surface)); + total = total.saturating_add(content).saturating_add(mask); + } if total > limit { return true; } @@ -180,7 +189,7 @@ pub(crate) fn display_doc(app: &mut PhotocraftApp, idx: usize) -> Option<(Arc