mirror of
https://github.com/penpot/penpot.git
synced 2026-04-29 21:28:20 +00:00
✨ Store bounds inside the shape
This commit is contained in:
parent
4b8f4d2d5b
commit
7459239639
@ -180,6 +180,7 @@ pub struct Shape {
|
|||||||
pub shadows: Vec<Shadow>,
|
pub shadows: Vec<Shadow>,
|
||||||
pub layout_item: Option<LayoutItem>,
|
pub layout_item: Option<LayoutItem>,
|
||||||
pub extrect: OnceCell<math::Rect>,
|
pub extrect: OnceCell<math::Rect>,
|
||||||
|
pub bounds: OnceCell<math::Bounds>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns all ancestor shapes of this shape, traversing up the parent hierarchy
|
// Returns all ancestor shapes of this shape, traversing up the parent hierarchy
|
||||||
@ -260,6 +261,7 @@ impl Shape {
|
|||||||
shadows: Vec::with_capacity(1),
|
shadows: Vec::with_capacity(1),
|
||||||
layout_item: None,
|
layout_item: None,
|
||||||
extrect: OnceCell::new(),
|
extrect: OnceCell::new(),
|
||||||
|
bounds: OnceCell::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,6 +292,10 @@ impl Shape {
|
|||||||
self.extrect = OnceCell::new();
|
self.extrect = OnceCell::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn invalidate_bounds(&mut self) {
|
||||||
|
self.bounds = OnceCell::new();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_parent(&mut self, id: Uuid) {
|
pub fn set_parent(&mut self, id: Uuid) {
|
||||||
self.parent_id = Some(id);
|
self.parent_id = Some(id);
|
||||||
}
|
}
|
||||||
@ -319,6 +325,7 @@ impl Shape {
|
|||||||
|
|
||||||
pub fn set_selrect(&mut self, left: f32, top: f32, right: f32, bottom: f32) {
|
pub fn set_selrect(&mut self, left: f32, top: f32, right: f32, bottom: f32) {
|
||||||
self.invalidate_extrect();
|
self.invalidate_extrect();
|
||||||
|
self.invalidate_bounds();
|
||||||
self.selrect.set_ltrb(left, top, right, bottom);
|
self.selrect.set_ltrb(left, top, right, bottom);
|
||||||
if let Type::Text(ref mut text) = self.shape_type {
|
if let Type::Text(ref mut text) = self.shape_type {
|
||||||
text.update_layout(self.selrect);
|
text.update_layout(self.selrect);
|
||||||
@ -685,8 +692,7 @@ impl Shape {
|
|||||||
|| self.selrect.height() * scale > ANTIALIAS_THRESHOLD
|
|| self.selrect.height() * scale > ANTIALIAS_THRESHOLD
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Maybe store this inside the shape
|
pub fn calculate_bounds(&self) -> Bounds {
|
||||||
pub fn bounds(&self) -> Bounds {
|
|
||||||
let mut bounds = Bounds::new(
|
let mut bounds = Bounds::new(
|
||||||
Point::new(self.selrect.x(), self.selrect.y()),
|
Point::new(self.selrect.x(), self.selrect.y()),
|
||||||
Point::new(self.selrect.x() + self.selrect.width(), self.selrect.y()),
|
Point::new(self.selrect.x() + self.selrect.width(), self.selrect.y()),
|
||||||
@ -712,6 +718,11 @@ impl Shape {
|
|||||||
bounds
|
bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bounds(&self) -> Bounds {
|
||||||
|
*self.bounds
|
||||||
|
.get_or_init(|| self.calculate_bounds())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn selrect(&self) -> math::Rect {
|
pub fn selrect(&self) -> math::Rect {
|
||||||
self.selrect
|
self.selrect
|
||||||
}
|
}
|
||||||
@ -1134,8 +1145,12 @@ impl Shape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_transform(&mut self, transform: &Matrix) {
|
pub fn apply_transform(&mut self, transform: &Matrix) {
|
||||||
self.invalidate_extrect();
|
|
||||||
self.transform_selrect(transform);
|
self.transform_selrect(transform);
|
||||||
|
|
||||||
|
// We don't need to invalidate this? we can just transform it
|
||||||
|
self.invalidate_extrect();
|
||||||
|
self.invalidate_bounds();
|
||||||
|
|
||||||
if let shape_type @ (Type::Path(_) | Type::Bool(_)) = &mut self.shape_type {
|
if let shape_type @ (Type::Path(_) | Type::Bool(_)) = &mut self.shape_type {
|
||||||
if let Some(path) = shape_type.path_mut() {
|
if let Some(path) = shape_type.path_mut() {
|
||||||
path.transform(transform);
|
path.transform(transform);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user