mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Code cleanup: spliut out save_screeshot_and_exit helper function
This commit is contained in:
@@ -644,23 +644,7 @@ mod glow_integration {
|
|||||||
#[cfg(feature = "__screenshot")]
|
#[cfg(feature = "__screenshot")]
|
||||||
if integration.egui_ctx.frame_nr() == 2 {
|
if integration.egui_ctx.frame_nr() == 2 {
|
||||||
if let Ok(path) = std::env::var("EFRAME_SCREENSHOT_TO") {
|
if let Ok(path) = std::env::var("EFRAME_SCREENSHOT_TO") {
|
||||||
assert!(
|
save_screeshot_and_exit(&path, painter, screen_size_in_pixels);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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 {
|
struct Viewport {
|
||||||
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
|
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
|
||||||
window: Option<Rc<Window>>,
|
window: Option<Rc<Window>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user