diff options
author | 2024-12-14 03:49:24 +0100 | |
---|---|---|
committer | 2024-12-14 03:49:24 +0100 | |
commit | 2cf4abf25bb5702635c19a22353399db8cef7be3 (patch) | |
tree | 3859d0fede59e92864c66c2ace89bc1d401769d6 /core/src/renderer.rs | |
parent | 6572909ab5b004176f6d261b67b4caa99f1f54bb (diff) | |
download | iced-2cf4abf25bb5702635c19a22353399db8cef7be3.tar.gz iced-2cf4abf25bb5702635c19a22353399db8cef7be3.tar.bz2 iced-2cf4abf25bb5702635c19a22353399db8cef7be3.zip |
Support custom renderers in `iced_test` through `renderer::Headless` trait
Diffstat (limited to 'core/src/renderer.rs')
-rw-r--r-- | core/src/renderer.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/core/src/renderer.rs b/core/src/renderer.rs index 6684517f..68e070e8 100644 --- a/core/src/renderer.rs +++ b/core/src/renderer.rs @@ -3,7 +3,8 @@ mod null; use crate::{ - Background, Border, Color, Rectangle, Shadow, Size, Transformation, Vector, + Background, Border, Color, Font, Pixels, Rectangle, Shadow, Size, + Transformation, Vector, }; /// A component that can be used by widgets to draw themselves on a screen. @@ -100,3 +101,19 @@ impl Default for Style { } } } + +/// A headless renderer is a renderer that can render offscreen without +/// a window nor a compositor. +pub trait Headless { + /// Creates a new [`Headless`] renderer; + fn new(default_font: Font, default_text_size: Pixels) -> Self; + + /// Draws offscreen into a screenshot, returning a collection of + /// bytes representing the rendered pixels in RGBA order. + fn screenshot( + &mut self, + size: Size<u32>, + scale_factor: f32, + background_color: Color, + ) -> Vec<u8>; +} |