mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Add Shape::Callback to do custom rendering inside of an egui UI (#1351)
* Add Shape::Callback to do custom rendering inside of an egui UI * Use Rc<glow::Context> everywhere * Remove trait WebPainter * Add glow::Context to epi::App::setup
This commit is contained in:
@@ -122,7 +122,7 @@ impl ContextImpl {
|
||||
///
|
||||
/// ``` no_run
|
||||
/// # fn handle_platform_output(_: egui::PlatformOutput) {}
|
||||
/// # fn paint(textures_detla: egui::TexturesDelta, _: Vec<egui::ClippedMesh>) {}
|
||||
/// # fn paint(textures_detla: egui::TexturesDelta, _: Vec<egui::ClippedPrimitive>) {}
|
||||
/// let mut ctx = egui::Context::default();
|
||||
///
|
||||
/// // Game loop:
|
||||
@@ -137,8 +137,8 @@ impl ContextImpl {
|
||||
/// });
|
||||
/// });
|
||||
/// handle_platform_output(full_output.platform_output);
|
||||
/// let clipped_meshes = ctx.tessellate(full_output.shapes); // create triangles to paint
|
||||
/// paint(full_output.textures_delta, clipped_meshes);
|
||||
/// let clipped_primitives = ctx.tessellate(full_output.shapes); // create triangles to paint
|
||||
/// paint(full_output.textures_delta, clipped_primitives);
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Clone)]
|
||||
@@ -773,7 +773,7 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Tessellate the given shapes into triangle meshes.
|
||||
pub fn tessellate(&self, shapes: Vec<ClippedShape>) -> Vec<ClippedMesh> {
|
||||
pub fn tessellate(&self, shapes: Vec<ClippedShape>) -> Vec<ClippedPrimitive> {
|
||||
// A tempting optimization is to reuse the tessellation from last frame if the
|
||||
// shapes are the same, but just comparing the shapes takes about 50% of the time
|
||||
// it takes to tessellate them, so it is not a worth optimization.
|
||||
@@ -782,13 +782,13 @@ impl Context {
|
||||
tessellation_options.pixels_per_point = self.pixels_per_point();
|
||||
tessellation_options.aa_size = 1.0 / self.pixels_per_point();
|
||||
let paint_stats = PaintStats::from_shapes(&shapes);
|
||||
let clipped_meshes = tessellator::tessellate_shapes(
|
||||
let clipped_primitives = tessellator::tessellate_shapes(
|
||||
shapes,
|
||||
tessellation_options,
|
||||
self.fonts().font_image_size(),
|
||||
);
|
||||
self.write().paint_stats = paint_stats.with_clipped_meshes(&clipped_meshes);
|
||||
clipped_meshes
|
||||
self.write().paint_stats = paint_stats.with_clipped_primitives(&clipped_primitives);
|
||||
clipped_primitives
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -1246,3 +1246,10 @@ impl Context {
|
||||
self.set_style(style);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn context_impl_send_sync() {
|
||||
fn assert_send_sync<T: Send + Sync>() {}
|
||||
assert_send_sync::<Context>();
|
||||
}
|
||||
|
||||
@@ -91,9 +91,10 @@ impl Widget for &epaint::stats::PaintStats {
|
||||
shape_path,
|
||||
shape_mesh,
|
||||
shape_vec,
|
||||
num_callbacks,
|
||||
text_shape_vertices,
|
||||
text_shape_indices,
|
||||
clipped_meshes,
|
||||
clipped_primitives,
|
||||
vertices,
|
||||
indices,
|
||||
} = self;
|
||||
@@ -104,6 +105,7 @@ impl Widget for &epaint::stats::PaintStats {
|
||||
label(ui, shape_path, "paths");
|
||||
label(ui, shape_mesh, "nested meshes");
|
||||
label(ui, shape_vec, "nested shapes");
|
||||
ui.label(format!("{} callbacks", num_callbacks));
|
||||
ui.add_space(10.0);
|
||||
|
||||
ui.label("Text shapes:");
|
||||
@@ -113,7 +115,7 @@ impl Widget for &epaint::stats::PaintStats {
|
||||
ui.add_space(10.0);
|
||||
|
||||
ui.label("Tessellated (and culled):");
|
||||
label(ui, clipped_meshes, "clipped_meshes")
|
||||
label(ui, clipped_primitives, "clipped_primitives")
|
||||
.on_hover_text("Number of separate clip rectangles");
|
||||
label(ui, vertices, "vertices");
|
||||
label(ui, indices, "indices").on_hover_text("Three 32-bit indices per triangles");
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
//! ``` no_run
|
||||
//! # fn handle_platform_output(_: egui::PlatformOutput) {}
|
||||
//! # fn gather_input() -> egui::RawInput { egui::RawInput::default() }
|
||||
//! # fn paint(textures_detla: egui::TexturesDelta, _: Vec<egui::ClippedMesh>) {}
|
||||
//! # fn paint(textures_detla: egui::TexturesDelta, _: Vec<egui::ClippedPrimitive>) {}
|
||||
//! let mut ctx = egui::Context::default();
|
||||
//!
|
||||
//! // Game loop:
|
||||
@@ -128,8 +128,8 @@
|
||||
//! });
|
||||
//! });
|
||||
//! handle_platform_output(full_output.platform_output);
|
||||
//! let clipped_meshes = ctx.tessellate(full_output.shapes); // create triangles to paint
|
||||
//! paint(full_output.textures_delta, clipped_meshes);
|
||||
//! let clipped_primitives = ctx.tessellate(full_output.shapes); // create triangles to paint
|
||||
//! paint(full_output.textures_delta, clipped_primitives);
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
@@ -386,8 +386,8 @@ pub use epaint::{
|
||||
color, mutex,
|
||||
text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
|
||||
textures::TexturesDelta,
|
||||
AlphaImage, ClippedMesh, Color32, ColorImage, ImageData, Mesh, Rgba, Rounding, Shape, Stroke,
|
||||
TextureHandle, TextureId,
|
||||
AlphaImage, ClippedPrimitive, Color32, ColorImage, ImageData, Mesh, Rgba, Rounding, Shape,
|
||||
Stroke, TextureHandle, TextureId,
|
||||
};
|
||||
|
||||
pub mod text {
|
||||
|
||||
Reference in New Issue
Block a user