summaryrefslogtreecommitdiffstats
path: root/tiny_skia
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-12-14 03:49:24 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-12-14 03:49:24 +0100
commit2cf4abf25bb5702635c19a22353399db8cef7be3 (patch)
tree3859d0fede59e92864c66c2ace89bc1d401769d6 /tiny_skia
parent6572909ab5b004176f6d261b67b4caa99f1f54bb (diff)
downloadiced-2cf4abf25bb5702635c19a22353399db8cef7be3.tar.gz
iced-2cf4abf25bb5702635c19a22353399db8cef7be3.tar.bz2
iced-2cf4abf25bb5702635c19a22353399db8cef7be3.zip
Support custom renderers in `iced_test` through `renderer::Headless` trait
Diffstat (limited to 'tiny_skia')
-rw-r--r--tiny_skia/src/lib.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs
index 758921d4..a42f1de4 100644
--- a/tiny_skia/src/lib.rs
+++ b/tiny_skia/src/lib.rs
@@ -29,7 +29,7 @@ pub use geometry::Geometry;
use crate::core::renderer;
use crate::core::{
- Background, Color, Font, Pixels, Point, Rectangle, Transformation,
+ Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
};
use crate::engine::Engine;
use crate::graphics::compositor;
@@ -405,3 +405,26 @@ impl core::svg::Renderer for Renderer {
impl compositor::Default for Renderer {
type Compositor = window::Compositor;
}
+
+impl renderer::Headless for Renderer {
+ fn new(default_font: Font, default_text_size: Pixels) -> Self {
+ Self::new(default_font, default_text_size)
+ }
+
+ fn screenshot(
+ &mut self,
+ size: Size<u32>,
+ scale_factor: f32,
+ background_color: Color,
+ ) -> Vec<u8> {
+ let viewport =
+ Viewport::with_physical_size(size, f64::from(scale_factor));
+
+ window::compositor::screenshot::<&str>(
+ self,
+ &viewport,
+ background_color,
+ &[],
+ )
+ }
+}