From 122619b197868be773feb63726526a013863df85 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 29 Oct 2025 09:54:51 +0100 Subject: [PATCH] :sparkles: Support for booleans dynamic transforms --- render-wasm/src/shapes/modifiers.rs | 13 ++++++++--- render-wasm/src/state/shapes_pool.rs | 33 +++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/render-wasm/src/shapes/modifiers.rs b/render-wasm/src/shapes/modifiers.rs index b43e2b98bf..df5839e888 100644 --- a/render-wasm/src/shapes/modifiers.rs +++ b/render-wasm/src/shapes/modifiers.rs @@ -109,6 +109,7 @@ fn calculate_bool_bounds( shape: &Shape, shapes: ShapesPoolRef, bounds: &HashMap, + modifiers: &HashMap ) -> Option { let shape_bounds = bounds.find(shape); let children_ids = shape.children_ids(true); @@ -117,9 +118,13 @@ fn calculate_bool_bounds( return Some(shape_bounds); }; - let path = bools::bool_from_shapes(bool_data.bool_type, &children_ids, shapes); + let mut subtree = shapes.subtree(&shape.id); + subtree.set_modifiers(modifiers.clone()); - Some(path.bounds()) + let path = bools::bool_from_shapes(bool_data.bool_type, &children_ids, &subtree); + let result = path.bounds(); + + Some(result) } fn set_pixel_precision(transform: &mut Matrix, bounds: &mut Bounds) { @@ -253,6 +258,7 @@ fn propagate_reflow( bounds: &mut HashMap, layout_reflows: &mut Vec, reflown: &mut HashSet, + modifiers: &HashMap ) { let Some(shape) = state.shapes.get(id) else { return; @@ -306,7 +312,7 @@ fn propagate_reflow( reflown.insert(*id); } Type::Bool(_) => { - if let Some(shape_bounds) = calculate_bool_bounds(shape, shapes, bounds) { + if let Some(shape_bounds) = calculate_bool_bounds(shape, shapes, bounds, modifiers) { bounds.insert(shape.id, shape_bounds); reflow_parent = true; } @@ -397,6 +403,7 @@ pub fn propagate_modifiers( &mut bounds, &mut layout_reflows, &mut reflown, + &mut modifiers, ), } } diff --git a/render-wasm/src/state/shapes_pool.rs b/render-wasm/src/state/shapes_pool.rs index d4ca32af9a..d286d6955c 100644 --- a/render-wasm/src/state/shapes_pool.rs +++ b/render-wasm/src/state/shapes_pool.rs @@ -316,6 +316,38 @@ impl<'a> ShapesPoolImpl<'a> { unsafe { Some(&*(&self.shapes[idx].id as *const Uuid)) } } + pub fn subtree(&self, id: &Uuid) -> ShapesPoolImpl<'a> { + let Some(shape) = self.get(id) else { panic!("Subtree not found"); }; + + // TODO: Maybe create all_children_iter + let all_children = shape.all_children(self, true, true); + + let mut shapes = vec![]; + let mut idx = 0; + let mut shapes_uuid_to_idx = HashMap::default(); + + for id in all_children.iter() { + let Some(shape) = self.get(id) else { panic!("Not found"); }; + shapes.push(shape.clone()); + + let id_ref: &'a Uuid = unsafe { &*(&self.shapes[idx].id as *const Uuid) }; + shapes_uuid_to_idx.insert(id_ref, idx); + idx += 1; + } + + let mut result = ShapesPoolImpl { + shapes, + counter: idx, + shapes_uuid_to_idx, + modified_shape_cache: HashMap::default(), + modifiers: HashMap::default(), + structure: HashMap::default(), + }; + result.rebuild_references(); + + result + } + fn to_update_bool(&self, shape: &Shape) -> bool { // TODO: Check if any of the children is in the modifiers with a // different matrix than the current one. @@ -344,4 +376,3 @@ impl<'a> ShapesPoolImpl<'a> { // ) // }) // } -