From 188db4da48954b95a3fe79bcd22689ffc3a661e0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 Mar 2024 05:52:48 +0100 Subject: Draft support for dynamic custom renderer injection --- core/src/renderer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src/renderer.rs') diff --git a/core/src/renderer.rs b/core/src/renderer.rs index 1139b41c..47b09d32 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -10,7 +10,7 @@ use crate::{ }; /// A component that can be used by widgets to draw themselves on a screen. -pub trait Renderer: Sized { +pub trait Renderer { /// Draws the primitives recorded in the given closure in a new layer. /// /// The layer will clip its contents to the provided `bounds`. -- cgit From 3645d34d6a1ba1247238e830e9eefd52d9e5b986 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 Mar 2024 22:27:17 +0100 Subject: Implement composable, type-safe renderer fallback --- core/src/renderer.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'core/src/renderer.rs') diff --git a/core/src/renderer.rs b/core/src/renderer.rs index 47b09d32..406b33f3 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -11,17 +11,41 @@ use crate::{ /// A component that can be used by widgets to draw themselves on a screen. 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( -- cgit From 1f13a91361258a1607c71f4840a26a6437f88612 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Mar 2024 05:27:31 +0100 Subject: Make `iced_tiny_skia` optional with a `tiny-skia` feature --- core/src/renderer.rs | 4 ---- 1 file changed, 4 deletions(-) (limited to 'core/src/renderer.rs') diff --git a/core/src/renderer.rs b/core/src/renderer.rs index 406b33f3..dfedcd45 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -1,10 +1,6 @@ //! Write your own renderer. -#[cfg(debug_assertions)] mod null; -#[cfg(debug_assertions)] -pub use null::Null; - use crate::{ Background, Border, Color, Rectangle, Shadow, Size, Transformation, Vector, }; -- cgit From 4f2f40c68b4647f281d34034beb159a41422aa06 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 Mar 2024 05:41:15 +0100 Subject: Fix standalone compilation of `iced_widget` crate --- core/src/renderer.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'core/src/renderer.rs') diff --git a/core/src/renderer.rs b/core/src/renderer.rs index dfedcd45..6712314e 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -1,4 +1,5 @@ //! Write your own renderer. +#[cfg(debug_assertions)] mod null; use crate::{ -- cgit From b05e61f5c8ae61c9f3c7cc08cded53901ebbccfd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 3 Apr 2024 21:07:54 +0200 Subject: Redesign `iced_wgpu` layering architecture --- core/src/renderer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core/src/renderer.rs') diff --git a/core/src/renderer.rs b/core/src/renderer.rs index 6712314e..f5ef8f68 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -9,7 +9,7 @@ use crate::{ /// A component that can be used by widgets to draw themselves on a screen. pub trait Renderer { /// Starts recording a new layer. - fn start_layer(&mut self); + fn start_layer(&mut self, bounds: Rectangle); /// Ends recording a new layer. /// @@ -20,13 +20,13 @@ pub trait Renderer { /// /// The layer will clip its contents to the provided `bounds`. fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) { - self.start_layer(); + self.start_layer(bounds); f(self); self.end_layer(bounds); } /// Starts recording with a new [`Transformation`]. - fn start_transformation(&mut self); + fn start_transformation(&mut self, transformation: Transformation); /// Ends recording a new layer. /// @@ -39,7 +39,7 @@ pub trait Renderer { transformation: Transformation, f: impl FnOnce(&mut Self), ) { - self.start_transformation(); + self.start_transformation(transformation); f(self); self.end_transformation(transformation); } -- cgit From 6ad5bb3597f640ac329801adf735d633bf0a512f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 9 Apr 2024 22:25:16 +0200 Subject: Port `iced_tiny_skia` to new layering architecture --- core/src/renderer.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core/src/renderer.rs') diff --git a/core/src/renderer.rs b/core/src/renderer.rs index f5ef8f68..a2785ae8 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -14,7 +14,7 @@ pub trait Renderer { /// Ends recording a new layer. /// /// The new layer will clip its contents to the provided `bounds`. - fn end_layer(&mut self, bounds: Rectangle); + fn end_layer(&mut self); /// Draws the primitives recorded in the given closure in a new layer. /// @@ -22,7 +22,7 @@ pub trait Renderer { fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) { self.start_layer(bounds); f(self); - self.end_layer(bounds); + self.end_layer(); } /// Starts recording with a new [`Transformation`]. @@ -31,7 +31,7 @@ pub trait Renderer { /// Ends recording a new layer. /// /// The new layer will clip its contents to the provided `bounds`. - fn end_transformation(&mut self, transformation: Transformation); + fn end_transformation(&mut self); /// Applies a [`Transformation`] to the primitives recorded in the given closure. fn with_transformation( @@ -41,7 +41,7 @@ pub trait Renderer { ) { self.start_transformation(transformation); f(self); - self.end_transformation(transformation); + self.end_transformation(); } /// Applies a translation to the primitives recorded in the given closure. -- cgit