summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Cory Forsstrom <cforsstrom18@gmail.com>2022-02-23 10:14:08 -0800
committerLibravatar Cory Forsstrom <cforsstrom18@gmail.com>2022-02-23 11:05:52 -0800
commit16b63031c15d3469c82a24936494e59c36d4d529 (patch)
treef28ae3f16611390bab23077b5862aa699cee29e9 /graphics
parent4aa943cbc63230dfcb995c469ceec9f74e6132e1 (diff)
downloadiced-16b63031c15d3469c82a24936494e59c36d4d529.tar.gz
iced-16b63031c15d3469c82a24936494e59c36d4d529.tar.bz2
iced-16b63031c15d3469c82a24936494e59c36d4d529.zip
Add with_clip for canvas
Diffstat (limited to '')
-rw-r--r--graphics/src/widget/canvas/frame.rs24
1 files changed, 24 insertions, 0 deletions
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) {