diff options
| author | 2023-08-02 14:35:53 +0200 | |
|---|---|---|
| committer | 2024-01-31 19:00:02 +0100 | |
| commit | f1c63398b35d651de54d36fbd2091f07ccf44cc6 (patch) | |
| tree | 413f931e04ff54c63f5d0233941b1d94da23dd81 /renderer/src/geometry | |
| parent | 5540ac07e4695cc4e268979eca4efeb604b7c77f (diff) | |
| download | iced-f1c63398b35d651de54d36fbd2091f07ccf44cc6.tar.gz iced-f1c63398b35d651de54d36fbd2091f07ccf44cc6.tar.bz2 iced-f1c63398b35d651de54d36fbd2091f07ccf44cc6.zip | |
Add return values to Frame::with_clip() and Frame::with_save()
Diffstat (limited to '')
| -rw-r--r-- | renderer/src/geometry.rs | 16 | 
1 files changed, 12 insertions, 4 deletions
| diff --git a/renderer/src/geometry.rs b/renderer/src/geometry.rs index 19ac87da..cd2140dc 100644 --- a/renderer/src/geometry.rs +++ b/renderer/src/geometry.rs @@ -111,12 +111,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 {          delegate!(self, frame, frame.push_transform()); -        f(self); +        let result = f(self);          delegate!(self, frame, frame.pop_transform()); + +        result      }      /// Executes the given drawing operations within a [`Rectangle`] region, @@ -126,7 +128,11 @@ 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 = match self {              Self::TinySkia(_) => Self::TinySkia(                  iced_tiny_skia::geometry::Frame::new(region.size()), @@ -137,7 +143,7 @@ impl Frame {              }          }; -        f(&mut frame); +        let result = f(&mut frame);          let origin = Point::new(region.x, region.y); @@ -152,6 +158,8 @@ impl Frame {              #[allow(unreachable_patterns)]              _ => unreachable!(),          }; + +        result      }      /// Applies a translation to the current transform of the [`Frame`]. | 
