diff options
author | 2022-03-07 15:36:09 +0700 | |
---|---|---|
committer | 2022-03-07 15:36:09 +0700 | |
commit | fbbb864aaa7d4163ffea9ccd39d8097568253c3e (patch) | |
tree | 0b000c1091b6f6b8fe060b0c9fbf542a4654f68d /graphics/src/widget/canvas/frame.rs | |
parent | c35496d80fc542c9beeea39dec98eb5cdef07aaa (diff) | |
parent | 4411da25cfcfddab138dadd05e92f9bd4db1b763 (diff) | |
download | iced-fbbb864aaa7d4163ffea9ccd39d8097568253c3e.tar.gz iced-fbbb864aaa7d4163ffea9ccd39d8097568253c3e.tar.bz2 iced-fbbb864aaa7d4163ffea9ccd39d8097568253c3e.zip |
Merge branch 'master' into virtual-widgets
Diffstat (limited to 'graphics/src/widget/canvas/frame.rs')
-rw-r--r-- | graphics/src/widget/canvas/frame.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs index 357dfa62..a3449605 100644 --- a/graphics/src/widget/canvas/frame.rs +++ b/graphics/src/widget/canvas/frame.rs @@ -253,6 +253,27 @@ impl Frame { self.transforms.current = self.transforms.previous.pop().unwrap(); } + /// 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 useful to perform drawing operations that need to be + /// clipped. + #[inline] + 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: region, + content: Box::new(Primitive::Translate { + translation: Vector::new(region.x, region.y), + content: Box::new(frame.into_geometry().into_primitive()), + }), + }); + } + /// Applies a translation to the current transform of the [`Frame`]. #[inline] pub fn translate(&mut self, translation: Vector) { |