summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2022-03-05 13:31:39 +0700
committerLibravatar GitHub <noreply@github.com>2022-03-05 13:31:39 +0700
commit4411da25cfcfddab138dadd05e92f9bd4db1b763 (patch)
treed1516d54d4b877b0effd0151f084a423a5345879 /graphics
parentee6f4cb2ac7f322ef708fe0655835638bac841ea (diff)
parent27e859e1537d62fd7a5f1f4fc4d760a7a39bc804 (diff)
downloadiced-4411da25cfcfddab138dadd05e92f9bd4db1b763.tar.gz
iced-4411da25cfcfddab138dadd05e92f9bd4db1b763.tar.bz2
iced-4411da25cfcfddab138dadd05e92f9bd4db1b763.zip
Merge pull request #1264 from tarkah/canvas/clip
Add clip to canvas
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/widget/canvas/frame.rs21
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) {