mirror of https://github.com/penpot/penpot.git
✨ Support for booleans dynamic transforms
This commit is contained in:
parent
dbf9bdceb5
commit
122619b197
|
|
@ -109,6 +109,7 @@ fn calculate_bool_bounds(
|
|||
shape: &Shape,
|
||||
shapes: ShapesPoolRef,
|
||||
bounds: &HashMap<Uuid, Bounds>,
|
||||
modifiers: &HashMap<Uuid, Matrix>
|
||||
) -> Option<Bounds> {
|
||||
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<Uuid, Bounds>,
|
||||
layout_reflows: &mut Vec<Uuid>,
|
||||
reflown: &mut HashSet<Uuid>,
|
||||
modifiers: &HashMap<Uuid, Matrix>
|
||||
) {
|
||||
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,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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> {
|
|||
// )
|
||||
// })
|
||||
// }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue