mirror of
https://github.com/penpot/penpot.git
synced 2026-11-27 05:10:32 +00:00
♻️ Return mask_id by value and only for masked groups (#13273)
Splitting off some refactoring from other renderer work that I thought would be useful. Callers of mask_id should check is_masked_group first, so this rolls the two into one. Whilst we're here, it also removes the reference from the Uuid type (`Option<Uuid?> -> Option<Uuid>`). It's cheap to copy and a few call sites will need to copy it to satisfy the borrow checker anyway.
This commit is contained in:
parent
df3445cfb3
commit
a7726b279d
@ -2238,8 +2238,8 @@ impl RenderState {
|
||||
}
|
||||
}
|
||||
pending.extend(shape.children_ids_iter(false).copied());
|
||||
if shape.is_masked_group() {
|
||||
pending.extend(shape.mask_id().copied());
|
||||
if let Some(mask_id) = shape.mask_id() {
|
||||
pending.push(mask_id);
|
||||
}
|
||||
}
|
||||
reach
|
||||
@ -3137,7 +3137,7 @@ impl RenderState {
|
||||
mask: false,
|
||||
flattened: false,
|
||||
});
|
||||
if let Some(&mask_id) = element.mask_id() {
|
||||
if let Some(mask_id) = element.mask_id() {
|
||||
self.pending_nodes.push(NodeRenderState {
|
||||
id: mask_id,
|
||||
visited_children: false,
|
||||
@ -3434,7 +3434,7 @@ impl RenderState {
|
||||
clip_bounds: Option<ClipStack>,
|
||||
pass: SilhouettePass,
|
||||
) -> Result<()> {
|
||||
let Some(mask_shape) = shape.mask_id().and_then(|id| pass.tree.get(id)) else {
|
||||
let Some(mask_shape) = shape.mask_id().and_then(|id| pass.tree.get(&id)) else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::error::Result;
|
||||
use crate::shapes::{Shadow, Shape, Type};
|
||||
use crate::shapes::{Shadow, Shape};
|
||||
use crate::state::ShapesPoolRef;
|
||||
use crate::uuid::Uuid;
|
||||
|
||||
@ -75,12 +75,7 @@ fn render_group_content(
|
||||
tree: ShapesPoolRef,
|
||||
scale: f32,
|
||||
) -> Result<()> {
|
||||
let masked = matches!(element.shape_type, Type::Group(g) if g.masked);
|
||||
if !masked {
|
||||
return render_group_content_children(builder, shared, element, tree, scale);
|
||||
}
|
||||
|
||||
let Some(mask_id) = element.mask_id().copied() else {
|
||||
let Some(mask_id) = element.mask_id() else {
|
||||
return render_group_content_children(builder, shared, element, tree, scale);
|
||||
};
|
||||
|
||||
|
||||
@ -910,7 +910,7 @@ fn render_masked_children(
|
||||
.bounds(&subtree_bounds)
|
||||
.paint(&mask_paint),
|
||||
);
|
||||
render_tree_inner(shared, canvas, mask_id, tree, scale, child_opts)?;
|
||||
render_tree_inner(shared, canvas, &mask_id, tree, scale, child_opts)?;
|
||||
canvas.restore(); // mask layer
|
||||
}
|
||||
|
||||
|
||||
@ -1292,8 +1292,10 @@ impl Shape {
|
||||
self.cap_bounds_margin() > 0.0
|
||||
}
|
||||
|
||||
pub fn mask_id(&self) -> Option<&Uuid> {
|
||||
self.children.first()
|
||||
pub fn mask_id(&self) -> Option<Uuid> {
|
||||
self.is_masked_group()
|
||||
.then(|| self.children.first().copied())
|
||||
.flatten()
|
||||
}
|
||||
|
||||
pub fn children_count(&self) -> usize {
|
||||
@ -2652,7 +2654,7 @@ mod tests {
|
||||
let content_b = Uuid::new_v4();
|
||||
group.children = vec![mask_id, content_a, content_b];
|
||||
|
||||
assert_eq!(group.mask_id(), Some(&mask_id));
|
||||
assert_eq!(group.mask_id(), Some(mask_id));
|
||||
|
||||
let content: Vec<Uuid> = group.children_ids_iter(false).copied().collect();
|
||||
assert_eq!(content.len(), 2);
|
||||
|
||||
@ -114,7 +114,7 @@ fn calculate_masked_group_bounds(
|
||||
shapes: ShapesPoolRef,
|
||||
bounds: &HashMap<Uuid, Bounds>,
|
||||
) -> Option<Bounds> {
|
||||
let mask = shape.mask_id().and_then(|id| shapes.get(id))?;
|
||||
let mask = shape.mask_id().and_then(|id| shapes.get(&id))?;
|
||||
Some(bounds.find(mask))
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user