diff options
author | 2024-03-27 19:47:48 +0900 | |
---|---|---|
committer | 2024-03-27 19:47:48 +0900 | |
commit | 19afc66cadfc7ea230d4d749b0d7b0197e29cf93 (patch) | |
tree | d012dff84003f2d7d18a1e6bc4bdac62df73b322 /core/src/renderer.rs | |
parent | 4334e63ba1dd88b367f3b7f2790b7869d11d12c0 (diff) | |
parent | 1df1cf82f4c9485533f2566c8490cfe188b4ae6a (diff) | |
download | iced-19afc66cadfc7ea230d4d749b0d7b0197e29cf93.tar.gz iced-19afc66cadfc7ea230d4d749b0d7b0197e29cf93.tar.bz2 iced-19afc66cadfc7ea230d4d749b0d7b0197e29cf93.zip |
Merge branch 'master' into viewer_content_fit
Diffstat (limited to 'core/src/renderer.rs')
-rw-r--r-- | core/src/renderer.rs | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/core/src/renderer.rs b/core/src/renderer.rs index 1139b41c..6712314e 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -2,26 +2,47 @@ #[cfg(debug_assertions)] mod null; -#[cfg(debug_assertions)] -pub use null::Null; - use crate::{ Background, Border, Color, Rectangle, Shadow, Size, Transformation, Vector, }; /// A component that can be used by widgets to draw themselves on a screen. -pub trait Renderer: Sized { +pub trait Renderer { + /// Starts recording a new layer. + fn start_layer(&mut self); + + /// Ends recording a new layer. + /// + /// The new layer will clip its contents to the provided `bounds`. + fn end_layer(&mut self, bounds: Rectangle); + /// Draws the primitives recorded in the given closure in a new layer. /// /// The layer will clip its contents to the provided `bounds`. - fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)); + fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) { + self.start_layer(); + f(self); + self.end_layer(bounds); + } + + /// Starts recording with a new [`Transformation`]. + fn start_transformation(&mut self); + + /// Ends recording a new layer. + /// + /// The new layer will clip its contents to the provided `bounds`. + fn end_transformation(&mut self, transformation: Transformation); /// Applies a [`Transformation`] to the primitives recorded in the given closure. fn with_transformation( &mut self, transformation: Transformation, f: impl FnOnce(&mut Self), - ); + ) { + self.start_transformation(); + f(self); + self.end_transformation(transformation); + } /// Applies a translation to the primitives recorded in the given closure. fn with_translation( |