Skip to main content

eframe/web/
web_painter.rs

1use egui::ScreenshotCallback;
2use wasm_bindgen::JsValue;
3
4/// Renderer for a browser canvas.
5/// As of writing we're not allowing to decide on the painter at runtime,
6/// therefore this trait is merely there for specifying and documenting the interface.
7pub(crate) trait WebPainter {
8    // Create a new web painter targeting a given canvas.
9    // fn new(canvas: HtmlCanvasElement, options: &WebOptions) -> Result<Self, String>
10    // where
11    //     Self: Sized;
12
13    /// Reference to the canvas in use.
14    fn canvas(&self) -> &web_sys::HtmlCanvasElement;
15
16    /// Maximum size of a texture in one direction.
17    fn max_texture_side(&self) -> usize;
18
19    /// Update all internal textures and paint gui.
20    /// When `capture` isn't empty, the rendered screen should be captured
21    /// and passed to the callbacks once it is ready.
22    fn paint_and_update_textures(
23        &mut self,
24        clear_color: [f32; 4],
25        clipped_primitives: &[egui::ClippedPrimitive],
26        pixels_per_point: f32,
27        textures_delta: &mut egui::TexturesDelta,
28        capture: Vec<ScreenshotCallback>,
29    ) -> Result<(), JsValue>;
30
31    /// Destroy all resources.
32    fn destroy(&mut self);
33}