1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Simplify backends by adding fn paint_and_update_textures helper

This commit is contained in:
Emil Ernerfeldt
2022-02-21 21:49:52 +01:00
parent 8f887e2ebd
commit 0a46634c13
7 changed files with 73 additions and 42 deletions

View File

@@ -294,17 +294,14 @@ impl AppRunner {
/// Paint the results of the last call to [`Self::logic`].
pub fn paint(&mut self, clipped_meshes: Vec<egui::ClippedMesh>) -> Result<(), JsValue> {
let textures_delta = std::mem::take(&mut self.textures_delta);
for (id, image_delta) in textures_delta.set {
self.painter.set_texture(id, &image_delta);
}
self.painter.clear(self.app.clear_color());
self.painter
.paint_meshes(clipped_meshes, self.egui_ctx.pixels_per_point())?;
for id in textures_delta.free {
self.painter.free_texture(id);
}
self.painter.paint_and_update_textures(
clipped_meshes,
self.egui_ctx.pixels_per_point(),
&textures_delta,
)?;
Ok(())
}

View File

@@ -22,4 +22,23 @@ pub trait Painter {
) -> Result<(), JsValue>;
fn name(&self) -> &'static str;
fn paint_and_update_textures(
&mut self,
clipped_meshes: Vec<egui::ClippedMesh>,
pixels_per_point: f32,
textures_delta: &egui::TexturesDelta,
) -> Result<(), JsValue> {
for (id, image_delta) in &textures_delta.set {
self.set_texture(*id, image_delta);
}
self.paint_meshes(clipped_meshes, pixels_per_point)?;
for &id in &textures_delta.free {
self.free_texture(id);
}
Ok(())
}
}