Clean up egui_web code a bit
This commit is contained in:
parent
d7f9e2246c
commit
1068750bbc
3 changed files with 19 additions and 18 deletions
|
@ -198,18 +198,21 @@ impl AppRunner {
|
||||||
resize_canvas_to_screen_size(self.web_backend.canvas_id(), self.app.max_size_points());
|
resize_canvas_to_screen_size(self.web_backend.canvas_id(), self.app.max_size_points());
|
||||||
let canvas_size = canvas_size_in_points(self.web_backend.canvas_id());
|
let canvas_size = canvas_size_in_points(self.web_backend.canvas_id());
|
||||||
let raw_input = self.input.new_frame(canvas_size);
|
let raw_input = self.input.new_frame(canvas_size);
|
||||||
|
|
||||||
|
let info = epi::IntegrationInfo {
|
||||||
|
web_info: Some(epi::WebInfo {
|
||||||
|
web_location_hash: location_hash().unwrap_or_default(),
|
||||||
|
}),
|
||||||
|
cpu_usage: self.web_backend.previous_frame_time,
|
||||||
|
seconds_since_midnight: Some(seconds_since_midnight()),
|
||||||
|
native_pixels_per_point: Some(native_pixels_per_point()),
|
||||||
|
};
|
||||||
|
|
||||||
self.web_backend.begin_frame(raw_input);
|
self.web_backend.begin_frame(raw_input);
|
||||||
|
|
||||||
let mut app_output = epi::backend::AppOutput::default();
|
let mut app_output = epi::backend::AppOutput::default();
|
||||||
let mut frame = epi::backend::FrameBuilder {
|
let mut frame = epi::backend::FrameBuilder {
|
||||||
info: epi::IntegrationInfo {
|
info,
|
||||||
web_info: Some(epi::WebInfo {
|
|
||||||
web_location_hash: location_hash().unwrap_or_default(),
|
|
||||||
}),
|
|
||||||
cpu_usage: self.web_backend.previous_frame_time,
|
|
||||||
seconds_since_midnight: Some(seconds_since_midnight()),
|
|
||||||
native_pixels_per_point: Some(native_pixels_per_point()),
|
|
||||||
},
|
|
||||||
tex_allocator: self.web_backend.painter.as_tex_allocator(),
|
tex_allocator: self.web_backend.painter.as_tex_allocator(),
|
||||||
#[cfg(feature = "http")]
|
#[cfg(feature = "http")]
|
||||||
http: self.http.clone(),
|
http: self.http.clone(),
|
||||||
|
@ -218,9 +221,9 @@ impl AppRunner {
|
||||||
}
|
}
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let egui_ctx = &self.web_backend.ctx;
|
self.app.update(&self.web_backend.ctx, &mut frame);
|
||||||
self.app.update(egui_ctx, &mut frame);
|
|
||||||
let (egui_output, clipped_meshes) = self.web_backend.end_frame()?;
|
let (egui_output, clipped_meshes) = self.web_backend.end_frame()?;
|
||||||
|
|
||||||
if self.web_backend.ctx.memory().options.screen_reader {
|
if self.web_backend.ctx.memory().options.screen_reader {
|
||||||
self.screen_reader.speak(&egui_output.events_description());
|
self.screen_reader.speak(&egui_output.events_description());
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,6 +189,7 @@ impl WebGlPainter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_webgl_texture(&mut self, texture: WebGlTexture) -> egui::TextureId {
|
pub fn register_webgl_texture(&mut self, texture: WebGlTexture) -> egui::TextureId {
|
||||||
let id = self.alloc_user_texture_index();
|
let id = self.alloc_user_texture_index();
|
||||||
if let Some(Some(user_texture)) = self.user_textures.get_mut(id) {
|
if let Some(Some(user_texture)) = self.user_textures.get_mut(id) {
|
||||||
|
@ -200,20 +201,18 @@ impl WebGlPainter {
|
||||||
}
|
}
|
||||||
egui::TextureId::User(id as u64)
|
egui::TextureId::User(id as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_mesh(&self, mesh: &egui::epaint::Mesh16) -> Result<(), JsValue> {
|
fn paint_mesh(&self, mesh: &egui::epaint::Mesh16) -> Result<(), JsValue> {
|
||||||
debug_assert!(mesh.is_valid());
|
debug_assert!(mesh.is_valid());
|
||||||
|
|
||||||
let mut positions: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
let mut positions: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
||||||
let mut tex_coords: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
let mut tex_coords: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
||||||
|
let mut colors: Vec<u8> = Vec::with_capacity(4 * mesh.vertices.len());
|
||||||
for v in &mesh.vertices {
|
for v in &mesh.vertices {
|
||||||
positions.push(v.pos.x);
|
positions.push(v.pos.x);
|
||||||
positions.push(v.pos.y);
|
positions.push(v.pos.y);
|
||||||
tex_coords.push(v.uv.x);
|
tex_coords.push(v.uv.x);
|
||||||
tex_coords.push(v.uv.y);
|
tex_coords.push(v.uv.y);
|
||||||
}
|
|
||||||
|
|
||||||
let mut colors: Vec<u8> = Vec::with_capacity(4 * mesh.vertices.len());
|
|
||||||
for v in &mesh.vertices {
|
|
||||||
colors.push(v.color[0]);
|
colors.push(v.color[0]);
|
||||||
colors.push(v.color[1]);
|
colors.push(v.color[1]);
|
||||||
colors.push(v.color[2]);
|
colors.push(v.color[2]);
|
||||||
|
|
|
@ -192,6 +192,7 @@ impl WebGl2Painter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_webgl_texture(&mut self, texture: WebGlTexture) -> egui::TextureId {
|
pub fn register_webgl_texture(&mut self, texture: WebGlTexture) -> egui::TextureId {
|
||||||
let id = self.alloc_user_texture_index();
|
let id = self.alloc_user_texture_index();
|
||||||
if let Some(Some(user_texture)) = self.user_textures.get_mut(id) {
|
if let Some(Some(user_texture)) = self.user_textures.get_mut(id) {
|
||||||
|
@ -203,20 +204,18 @@ impl WebGl2Painter {
|
||||||
}
|
}
|
||||||
egui::TextureId::User(id as u64)
|
egui::TextureId::User(id as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_mesh(&self, mesh: &egui::epaint::Mesh16) -> Result<(), JsValue> {
|
fn paint_mesh(&self, mesh: &egui::epaint::Mesh16) -> Result<(), JsValue> {
|
||||||
debug_assert!(mesh.is_valid());
|
debug_assert!(mesh.is_valid());
|
||||||
|
|
||||||
let mut positions: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
let mut positions: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
||||||
let mut tex_coords: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
let mut tex_coords: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
||||||
|
let mut colors: Vec<u8> = Vec::with_capacity(4 * mesh.vertices.len());
|
||||||
for v in &mesh.vertices {
|
for v in &mesh.vertices {
|
||||||
positions.push(v.pos.x);
|
positions.push(v.pos.x);
|
||||||
positions.push(v.pos.y);
|
positions.push(v.pos.y);
|
||||||
tex_coords.push(v.uv.x);
|
tex_coords.push(v.uv.x);
|
||||||
tex_coords.push(v.uv.y);
|
tex_coords.push(v.uv.y);
|
||||||
}
|
|
||||||
|
|
||||||
let mut colors: Vec<u8> = Vec::with_capacity(4 * mesh.vertices.len());
|
|
||||||
for v in &mesh.vertices {
|
|
||||||
colors.push(v.color[0]);
|
colors.push(v.color[0]);
|
||||||
colors.push(v.color[1]);
|
colors.push(v.color[1]);
|
||||||
colors.push(v.color[2]);
|
colors.push(v.color[2]);
|
||||||
|
|
Loading…
Reference in a new issue