summaryrefslogtreecommitdiffstats
path: root/wgpu/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-01-31 19:15:24 +0100
committerLibravatar GitHub <noreply@github.com>2024-01-31 19:15:24 +0100
commit8ed3490280a4dd8a1d4e3cd421b1785725f65865 (patch)
treea96da5c4400aaa56e5dcc6bfb3708c51731a9b7a /wgpu/src
parentf3145212319fe1376b5ec8d4d439c0b0e6f37bbf (diff)
parentf0a8064fb59e44934f797cef556779b475da6bff (diff)
downloadiced-8ed3490280a4dd8a1d4e3cd421b1785725f65865.tar.gz
iced-8ed3490280a4dd8a1d4e3cd421b1785725f65865.tar.bz2
iced-8ed3490280a4dd8a1d4e3cd421b1785725f65865.zip
Merge pull request #1994 from MichalLebeda/frame-fn-returns
Add return values to ```Frame::with_clip()``` and ```Frame::with_save()```
Diffstat (limited to '')
-rw-r--r--wgpu/src/geometry.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs
index 4d7f443e..a4d4fb1f 100644
--- a/wgpu/src/geometry.rs
+++ b/wgpu/src/geometry.rs
@@ -388,12 +388,14 @@ impl Frame {
/// This method is useful to compose transforms and perform drawing
/// operations in different coordinate systems.
#[inline]
- pub fn with_save(&mut self, f: impl FnOnce(&mut Frame)) {
+ pub fn with_save<R>(&mut self, f: impl FnOnce(&mut Frame) -> R) -> R {
self.push_transform();
- f(self);
+ let result = f(self);
self.pop_transform();
+
+ result
}
/// Pushes the current transform in the transform stack.
@@ -413,14 +415,20 @@ impl Frame {
/// 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)) {
+ pub fn with_clip<R>(
+ &mut self,
+ region: Rectangle,
+ f: impl FnOnce(&mut Frame) -> R,
+ ) -> R {
let mut frame = Frame::new(region.size());
- f(&mut frame);
+ let result = f(&mut frame);
let origin = Point::new(region.x, region.y);
self.clip(frame, origin);
+
+ result
}
/// Draws the clipped contents of the given [`Frame`] with origin at the given [`Point`].