Merge pull request #1994 from MichalLebeda/frame-fn-returns
Add return values to ```Frame::with_clip()``` and ```Frame::with_save()```
This commit is contained in:
commit
8ed3490280
3 changed files with 26 additions and 8 deletions
|
|
@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Use workspace dependencies and package inheritance. [#2069](https://github.com/iced-rs/iced/pull/2069)
|
- Use workspace dependencies and package inheritance. [#2069](https://github.com/iced-rs/iced/pull/2069)
|
||||||
- Update `wgpu` to `0.17`. [#2065](https://github.com/iced-rs/iced/pull/2065)
|
- Update `wgpu` to `0.17`. [#2065](https://github.com/iced-rs/iced/pull/2065)
|
||||||
- Support automatic style type casting for `Button`. [#2046](https://github.com/iced-rs/iced/pull/2046)
|
- Support automatic style type casting for `Button`. [#2046](https://github.com/iced-rs/iced/pull/2046)
|
||||||
|
- `with_clip` and `with_save` in `Frame` can now return the data of the provided closure. [#1994](https://github.com/iced-rs/iced/pull/1994)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Clipping of `TextInput` selection. [#2199](https://github.com/iced-rs/iced/pull/2199)
|
- Clipping of `TextInput` selection. [#2199](https://github.com/iced-rs/iced/pull/2199)
|
||||||
|
|
@ -99,6 +100,7 @@ Many thanks to...
|
||||||
- @joshuamegnauth54
|
- @joshuamegnauth54
|
||||||
- @lufte
|
- @lufte
|
||||||
- @matze
|
- @matze
|
||||||
|
- @MichalLebeda
|
||||||
- @MrAntix
|
- @MrAntix
|
||||||
- @nicksenger
|
- @nicksenger
|
||||||
- @Nisatru
|
- @Nisatru
|
||||||
|
|
|
||||||
|
|
@ -111,12 +111,14 @@ impl Frame {
|
||||||
/// This method is useful to compose transforms and perform drawing
|
/// This method is useful to compose transforms and perform drawing
|
||||||
/// operations in different coordinate systems.
|
/// operations in different coordinate systems.
|
||||||
#[inline]
|
#[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());
|
delegate!(self, frame, frame.push_transform());
|
||||||
|
|
||||||
f(self);
|
let result = f(self);
|
||||||
|
|
||||||
delegate!(self, frame, frame.pop_transform());
|
delegate!(self, frame, frame.pop_transform());
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes the given drawing operations within a [`Rectangle`] region,
|
/// 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
|
/// This method is useful to perform drawing operations that need to be
|
||||||
/// clipped.
|
/// clipped.
|
||||||
#[inline]
|
#[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 {
|
let mut frame = match self {
|
||||||
Self::TinySkia(_) => Self::TinySkia(
|
Self::TinySkia(_) => Self::TinySkia(
|
||||||
iced_tiny_skia::geometry::Frame::new(region.size()),
|
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);
|
let origin = Point::new(region.x, region.y);
|
||||||
|
|
||||||
|
|
@ -152,6 +158,8 @@ impl Frame {
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a translation to the current transform of the [`Frame`].
|
/// Applies a translation to the current transform of the [`Frame`].
|
||||||
|
|
|
||||||
|
|
@ -388,12 +388,14 @@ impl Frame {
|
||||||
/// This method is useful to compose transforms and perform drawing
|
/// This method is useful to compose transforms and perform drawing
|
||||||
/// operations in different coordinate systems.
|
/// operations in different coordinate systems.
|
||||||
#[inline]
|
#[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();
|
self.push_transform();
|
||||||
|
|
||||||
f(self);
|
let result = f(self);
|
||||||
|
|
||||||
self.pop_transform();
|
self.pop_transform();
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pushes the current transform in the transform stack.
|
/// 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
|
/// This method is useful to perform drawing operations that need to be
|
||||||
/// clipped.
|
/// clipped.
|
||||||
#[inline]
|
#[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());
|
let mut frame = Frame::new(region.size());
|
||||||
|
|
||||||
f(&mut frame);
|
let result = f(&mut frame);
|
||||||
|
|
||||||
let origin = Point::new(region.x, region.y);
|
let origin = Point::new(region.x, region.y);
|
||||||
|
|
||||||
self.clip(frame, origin);
|
self.clip(frame, origin);
|
||||||
|
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws the clipped contents of the given [`Frame`] with origin at the given [`Point`].
|
/// Draws the clipped contents of the given [`Frame`] with origin at the given [`Point`].
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue