1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 23:13:13 -04:00

Code cleanup: spliut out save_screeshot_and_exit helper function

This commit is contained in:
Emil Ernerfeldt
2023-11-13 20:02:42 +01:00
parent 6e7a735b40
commit 7682a7aea6

View File

@@ -644,23 +644,7 @@ mod glow_integration {
#[cfg(feature = "__screenshot")]
if integration.egui_ctx.frame_nr() == 2 {
if let Ok(path) = std::env::var("EFRAME_SCREENSHOT_TO") {
assert!(
path.ends_with(".png"),
"Expected EFRAME_SCREENSHOT_TO to end with '.png', got {path:?}"
);
let screenshot = painter.borrow().read_screen_rgba(screen_size_in_pixels);
image::save_buffer(
&path,
screenshot.as_raw(),
screenshot.width() as u32,
screenshot.height() as u32,
image::ColorType::Rgba8,
)
.unwrap_or_else(|err| {
panic!("Failed to save screenshot to {path:?}: {err}");
});
eprintln!("Screenshot saved to {path:?}.");
std::process::exit(0);
save_screeshot_and_exit(&path, painter, screen_size_in_pixels);
}
}
@@ -696,6 +680,32 @@ mod glow_integration {
}
}
fn save_screeshot_and_exit(
path: &str,
painter: &mut Rc<RefCell<egui_glow::Painter>>,
screen_size_in_pixels: [u32; 2],
) {
assert!(
path.ends_with(".png"),
"Expected EFRAME_SCREENSHOT_TO to end with '.png', got {path:?}"
);
let screenshot = painter.borrow().read_screen_rgba(screen_size_in_pixels);
image::save_buffer(
path,
screenshot.as_raw(),
screenshot.width() as u32,
screenshot.height() as u32,
image::ColorType::Rgba8,
)
.unwrap_or_else(|err| {
panic!("Failed to save screenshot to {path:?}: {err}");
});
eprintln!("Screenshot saved to {path:?}.");
#[allow(clippy::exit)]
std::process::exit(0);
}
struct Viewport {
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
window: Option<Rc<Window>>,