1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 15:13:12 -04:00
Files
egui/crates/eframe/src/web/web_painter.rs
lucasmerlin 6c1d695fc6 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
2024-12-12 19:17:42 +01:00

36 lines
1.3 KiB
Rust

use egui::{Event, UserData};
use wasm_bindgen::JsValue;
/// Renderer for a browser canvas.
/// As of writing we're not allowing to decide on the painter at runtime,
/// therefore this trait is merely there for specifying and documenting the interface.
pub(crate) trait WebPainter {
// Create a new web painter targeting a given canvas.
// fn new(canvas: HtmlCanvasElement, options: &WebOptions) -> Result<Self, String>
// where
// Self: Sized;
/// Reference to the canvas in use.
fn canvas(&self) -> &web_sys::HtmlCanvasElement;
/// Maximum size of a texture in one direction.
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);
}