1- use crate :: painter:: Painter ;
1+ use std:: time:: Duration ;
2+
23use egui:: { Context , Pos2 } ;
34use skia_safe:: { Canvas , Surface } ;
4- use std:: time:: Duration ;
5+
6+ use crate :: painter:: Painter ;
57
68pub struct RasterizeOptions {
79 pub pixels_per_point : f32 ,
10+ /// The number of frames to render before a screenshot is taken.
11+ /// Default is 2, so egui will be able to display windows
12+ pub frames_before_screenshot : usize ,
813}
914
1015impl Default for RasterizeOptions {
1116 fn default ( ) -> Self {
1217 Self {
1318 pixels_per_point : 1.0 ,
19+ frames_before_screenshot : 2 ,
1420 }
1521 }
1622}
@@ -27,10 +33,13 @@ pub fn rasterize(
2733
2834pub fn draw_onto_surface (
2935 surface : & mut Surface ,
30- ui : impl FnMut ( & Context ) ,
36+ mut ui : impl FnMut ( & Context ) ,
3137 options : Option < RasterizeOptions > ,
3238) {
33- let RasterizeOptions { pixels_per_point } = options. unwrap_or_default ( ) ;
39+ let RasterizeOptions {
40+ pixels_per_point,
41+ frames_before_screenshot,
42+ } = options. unwrap_or_default ( ) ;
3443 let mut backend = EguiSkia :: new ( ) ;
3544
3645 let input = egui:: RawInput {
@@ -45,8 +54,9 @@ pub fn draw_onto_surface(
4554 ..Default :: default ( )
4655 } ;
4756
48- backend. run ( input, ui) ;
49-
57+ for _ in 0 ..frames_before_screenshot {
58+ backend. run ( input. clone ( ) , & mut ui) ;
59+ }
5060 backend. paint ( surface. canvas ( ) ) ;
5161}
5262
0 commit comments