From 16b63031c15d3469c82a24936494e59c36d4d529 Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Wed, 23 Feb 2022 10:14:08 -0800 Subject: Add with_clip for canvas --- graphics/src/widget/canvas/frame.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'graphics') diff --git a/graphics/src/widget/canvas/frame.rs b/graphics/src/widget/canvas/frame.rs index 4873e7fb..01b27451 100644 --- a/graphics/src/widget/canvas/frame.rs +++ b/graphics/src/widget/canvas/frame.rs @@ -244,6 +244,30 @@ impl Frame { self.transforms.current = self.transforms.previous.pop().unwrap(); } + /// TODO... + #[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); + + 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()), + }); + } + /// Applies a translation to the current transform of the [`Frame`]. #[inline] pub fn translate(&mut self, translation: Vector) { -- cgit