Use Rectangle directly in Frame::with_clip
This commit is contained in:
parent
f40da376ce
commit
27e859e153
1 changed files with 11 additions and 21 deletions
|
|
@ -244,34 +244,24 @@ impl Frame {
|
||||||
self.transforms.current = self.transforms.previous.pop().unwrap();
|
self.transforms.current = self.transforms.previous.pop().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores the current transform of the [`Frame`] and executes the given
|
/// Executes the given drawing operations within a [`Rectangle`] region,
|
||||||
/// drawing operations within a clipped [`Rectange`] at translation / size,
|
/// clipping any geometry that overflows its bounds. Any transformations
|
||||||
/// restoring the transform afterwards.
|
/// performed are local to the provided closure.
|
||||||
///
|
///
|
||||||
/// This method is userful to perform drawing operations that need to be
|
/// This method is useful to perform drawing operations that need to be
|
||||||
/// clipped.
|
/// clipped.
|
||||||
///
|
|
||||||
/// [`Rectange`]: crate::Rectangle
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_clip(
|
pub fn with_clip(&mut self, region: Rectangle, f: impl FnOnce(&mut Frame)) {
|
||||||
&mut self,
|
let mut frame = Frame::new(region.size());
|
||||||
translation: Vector,
|
|
||||||
size: Size,
|
|
||||||
f: impl FnOnce(&mut Frame),
|
|
||||||
) {
|
|
||||||
let mut frame = Frame::new(self.size());
|
|
||||||
frame.translate(translation);
|
|
||||||
|
|
||||||
f(&mut frame);
|
f(&mut frame);
|
||||||
|
|
||||||
self.primitives.push(Primitive::Clip {
|
self.primitives.push(Primitive::Clip {
|
||||||
bounds: Rectangle {
|
bounds: region,
|
||||||
x: translation.x,
|
content: Box::new(Primitive::Translate {
|
||||||
y: translation.y,
|
translation: Vector::new(region.x, region.y),
|
||||||
width: size.width,
|
content: Box::new(frame.into_geometry().into_primitive()),
|
||||||
height: size.height,
|
}),
|
||||||
},
|
|
||||||
content: Box::new(frame.into_geometry().into_primitive()),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue