mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
✨ Improve performance of group bounds
This commit is contained in:
@@ -719,8 +719,7 @@ impl Shape {
|
||||
}
|
||||
|
||||
pub fn bounds(&self) -> Bounds {
|
||||
*self.bounds
|
||||
.get_or_init(|| self.calculate_bounds())
|
||||
*self.bounds.get_or_init(|| self.calculate_bounds())
|
||||
}
|
||||
|
||||
pub fn selrect(&self) -> math::Rect {
|
||||
@@ -947,6 +946,24 @@ impl Shape {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn children_ids_iter(&self, include_hidden: bool) -> Box<dyn Iterator<Item = &Uuid> + '_> {
|
||||
if include_hidden {
|
||||
return Box::new(self.children.iter().rev());
|
||||
}
|
||||
|
||||
if let Type::Bool(_) = self.shape_type {
|
||||
Box::new([].iter())
|
||||
} else if let Type::Group(group) = self.shape_type {
|
||||
if group.masked {
|
||||
Box::new(self.children.iter().rev().take(self.children.len() - 1))
|
||||
} else {
|
||||
Box::new(self.children.iter().rev())
|
||||
}
|
||||
} else {
|
||||
Box::new(self.children.iter().rev())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn all_children(
|
||||
&self,
|
||||
shapes: &ShapesPool,
|
||||
@@ -1259,6 +1276,36 @@ impl Shape {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modified_children_ids_iter<'a>(
|
||||
&'a self,
|
||||
structure: Option<&'a Vec<StructureEntry>>,
|
||||
include_hidden: bool,
|
||||
) -> Box<dyn Iterator<Item = Cow<'a, Uuid>> + 'a> {
|
||||
if let Some(structure) = structure {
|
||||
let mut result: Vec<Cow<'a, Uuid>> = self
|
||||
.children_ids_iter(include_hidden)
|
||||
.map(Cow::Borrowed)
|
||||
.collect();
|
||||
let mut to_remove = HashSet::<Cow<'a, Uuid>>::new();
|
||||
|
||||
for st in structure {
|
||||
match st.entry_type {
|
||||
StructureEntryType::AddChild => {
|
||||
result.insert(result.len() - st.index as usize, Cow::Owned(st.id));
|
||||
}
|
||||
StructureEntryType::RemoveChild => {
|
||||
to_remove.insert(Cow::Owned(st.id));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Box::new(result.into_iter().filter(move |id| !to_remove.contains(id)))
|
||||
} else {
|
||||
Box::new(self.children_ids_iter(include_hidden).map(Cow::Borrowed))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drop_shadow_paints(&self) -> Vec<skia_safe::Paint> {
|
||||
let drop_shadows: Vec<&Shadow> = self.drop_shadows_visible().collect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user