1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Add screenshot support for eframe web (#5438)

This implements web support for taking screenshots in an eframe app (and
adds a nice demo).
It also updates the native screenshot implementation to work with the
wgpu gl backend.

The wgpu implementation is quite different than the native one because
we can't block to wait for the screenshot result, so instead I use a
channel to pass the result to a future frame asynchronously.

* Closes <https://github.com/emilk/egui/issues/5425>
* [x] I have followed the instructions in the PR template


https://github.com/user-attachments/assets/67cad40b-0384-431d-96a3-075cc3cb98fb
This commit is contained in:
lucasmerlin
2024-12-12 19:17:42 +01:00
committed by GitHub
parent de8ac88c0e
commit 6c1d695fc6
13 changed files with 613 additions and 272 deletions

View File

@@ -1,3 +1,4 @@
use egui::{Event, UserData};
use wasm_bindgen::JsValue;
/// Renderer for a browser canvas.
@@ -16,14 +17,19 @@ pub(crate) trait WebPainter {
fn max_texture_side(&self) -> usize;
/// Update all internal textures and paint gui.
/// When `capture` isn't empty, the rendered screen should be captured.
/// Once the screenshot is ready, the screenshot should be returned via [`Self::handle_screenshots`].
fn paint_and_update_textures(
&mut self,
clear_color: [f32; 4],
clipped_primitives: &[egui::ClippedPrimitive],
pixels_per_point: f32,
textures_delta: &egui::TexturesDelta,
capture: Vec<UserData>,
) -> Result<(), JsValue>;
fn handle_screenshots(&mut self, events: &mut Vec<Event>);
/// Destroy all resources.
fn destroy(&mut self);
}