Support custom renderers in iced_test through renderer::Headless trait

This commit is contained in:
Héctor Ramón Jiménez 2024-12-14 03:49:24 +01:00
parent 6572909ab5
commit 2cf4abf25b
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
12 changed files with 191 additions and 80 deletions

View file

@ -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>;
}