summaryrefslogtreecommitdiffstats
path: root/graphics/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-03-02 20:54:24 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-03-02 21:03:46 +0700
commit27e859e1537d62fd7a5f1f4fc4d760a7a39bc804 (patch)
treed29cf04ad168da29a750eca84cf2848264a068a9 /graphics/src
parentf40da376ce1e7a508d8dde85697326b8a0eed373 (diff)
downloadiced-27e859e1537d62fd7a5f1f4fc4d760a7a39bc804.tar.gz
iced-27e859e1537d62fd7a5f1f4fc4d760a7a39bc804.tar.bz2
iced-27e859e1537d62fd7a5f1f4fc4d760a7a39bc804.zip
Use `Rectangle` directly in `Frame::with_clip`
Diffstat (limited to 'graphics/src')
-rw-r--r--graphics/src/widget/canvas/frame.rs32
1 files changed, 11 insertions, 21 deletions
diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs
index 23db843d..08518f40 100644
--- a/graphics/src/widget/canvas/frame.rs
+++ b/graphics/src/widget/canvas/frame.rs
@@ -244,34 +244,24 @@ impl Frame {
self.transforms.current = self.transforms.previous.pop().unwrap();
}
- /// Stores the current transform of the [`Frame`] and executes the given
- /// drawing operations within a clipped [`Rectange`] at translation / size,
- /// restoring the transform afterwards.
+ /// Executes the given drawing operations within a [`Rectangle`] region,
+ /// clipping any geometry that overflows its bounds. Any transformations
+ /// 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.
- ///
- /// [`Rectange`]: crate::Rectangle
#[inline]
- pub fn with_clip(
- &mut self,
- translation: Vector,
- size: Size,
- f: impl FnOnce(&mut Frame),
- ) {
- let mut frame = Frame::new(self.size());
- frame.translate(translation);
+ pub fn with_clip(&mut self, region: Rectangle, f: impl FnOnce(&mut Frame)) {
+ let mut frame = Frame::new(region.size());
f(&mut frame);
self.primitives.push(Primitive::Clip {
- bounds: Rectangle {
- x: translation.x,
- y: translation.y,
- width: size.width,
- height: size.height,
- },
- content: Box::new(frame.into_geometry().into_primitive()),
+ bounds: region,
+ content: Box::new(Primitive::Translate {
+ translation: Vector::new(region.x, region.y),
+ content: Box::new(frame.into_geometry().into_primitive()),
+ }),
});
}