summaryrefslogtreecommitdiffstats
path: root/core/src/renderer.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-21 22:27:17 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-21 22:27:17 +0100
commit3645d34d6a1ba1247238e830e9eefd52d9e5b986 (patch)
tree2d38961161df0a85c1667474b2b696aab86b7160 /core/src/renderer.rs
parent7e4ae8450e1f28c15717ca5ca9748981af9c9541 (diff)
downloadiced-3645d34d6a1ba1247238e830e9eefd52d9e5b986.tar.gz
iced-3645d34d6a1ba1247238e830e9eefd52d9e5b986.tar.bz2
iced-3645d34d6a1ba1247238e830e9eefd52d9e5b986.zip
Implement composable, type-safe renderer fallback
Diffstat (limited to 'core/src/renderer.rs')
-rw-r--r--core/src/renderer.rs28
1 files changed, 26 insertions, 2 deletions
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(