Skip to content

Commit 7ed8c66

Browse files
committed
Fix rasterize function not rendering egui windows
1 parent 33c24a8 commit 7ed8c66

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

examples/rasterize.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use egui_skia::rasterize;
1+
use egui_skia::{rasterize, RasterizeOptions};
22
use skia_safe::{EncodedImageFormat, Paint, Point};
33
use std::fs::File;
44
use std::io::Write;
@@ -30,7 +30,10 @@ pub fn main() {
3030
});
3131
});
3232
},
33-
None,
33+
Some(RasterizeOptions {
34+
pixels_per_point: 1.0,
35+
frames_before_screenshot: 2
36+
}),
3437
);
3538

3639
let data = surface

src/egui_skia.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
use crate::painter::Painter;
1+
use std::time::Duration;
2+
23
use egui::{Context, Pos2};
34
use skia_safe::{Canvas, Surface};
4-
use std::time::Duration;
5+
6+
use crate::painter::Painter;
57

68
pub 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

1015
impl 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

2834
pub 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

Comments
 (0)