summaryrefslogtreecommitdiffstats
path: root/core/src/renderer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/renderer.rs')
-rw-r--r--core/src/renderer.rs33
1 files changed, 27 insertions, 6 deletions
diff --git a/core/src/renderer.rs b/core/src/renderer.rs
index 1139b41c..a2785ae8 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, bounds: Rectangle);
+
+ /// Ends recording a new layer.
+ ///
+ /// The new layer will clip its contents to the provided `bounds`.
+ fn end_layer(&mut self);
+
/// 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(bounds);
+ f(self);
+ self.end_layer();
+ }
+
+ /// Starts recording with a new [`Transformation`].
+ fn start_transformation(&mut self, transformation: Transformation);
+
+ /// Ends recording a new layer.
+ ///
+ /// The new layer will clip its contents to the provided `bounds`.
+ fn end_transformation(&mut self);
/// 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(transformation);
+ f(self);
+ self.end_transformation();
+ }
/// Applies a translation to the primitives recorded in the given closure.
fn with_translation(