diff --git a/examples/rasterize.rs b/examples/rasterize.rs index 3b7eaa5..0eaa6e1 100644 --- a/examples/rasterize.rs +++ b/examples/rasterize.rs @@ -1,4 +1,4 @@ -use egui_skia::rasterize; +use egui_skia::{rasterize, RasterizeOptions}; use skia_safe::{EncodedImageFormat, Paint, Point}; use std::fs::File; use std::io::Write; @@ -30,7 +30,10 @@ pub fn main() { }); }); }, - None, + Some(RasterizeOptions { + pixels_per_point: 1.0, + frames_before_screenshot: 2 + }), ); let data = surface diff --git a/src/egui_skia.rs b/src/egui_skia.rs index 42a3d7c..a44f389 100644 --- a/src/egui_skia.rs +++ b/src/egui_skia.rs @@ -1,16 +1,22 @@ -use crate::painter::Painter; +use std::time::Duration; + use egui::{Context, Pos2}; use skia_safe::{Canvas, Surface}; -use std::time::Duration; + +use crate::painter::Painter; pub struct RasterizeOptions { pub pixels_per_point: f32, + /// The number of frames to render before a screenshot is taken. + /// Default is 2, so egui will be able to display windows + pub frames_before_screenshot: usize, } impl Default for RasterizeOptions { fn default() -> Self { Self { pixels_per_point: 1.0, + frames_before_screenshot: 2, } } } @@ -27,10 +33,13 @@ pub fn rasterize( pub fn draw_onto_surface( surface: &mut Surface, - ui: impl FnMut(&Context), + mut ui: impl FnMut(&Context), options: Option, ) { - let RasterizeOptions { pixels_per_point } = options.unwrap_or_default(); + let RasterizeOptions { + pixels_per_point, + frames_before_screenshot, + } = options.unwrap_or_default(); let mut backend = EguiSkia::new(); let input = egui::RawInput { @@ -45,8 +54,9 @@ pub fn draw_onto_surface( ..Default::default() }; - backend.run(input, ui); - + for _ in 0..frames_before_screenshot { + backend.run(input.clone(), &mut ui); + } backend.paint(surface.canvas()); }