From 4e8a6e3370ef12924ad7baff7e289b52a4fbfcf8 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 29 Jul 2022 16:07:26 +0200 Subject: [PATCH] misc code cleanup --- egui/src/placer.rs | 1 + egui_demo_app/src/backend_panel.rs | 16 +++++++++------- egui_extras/src/image.rs | 10 ++++++++++ egui_glow/src/painter.rs | 2 ++ epaint/src/tessellator.rs | 9 +++++---- sh/check.sh | 2 +- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/egui/src/placer.rs b/egui/src/placer.rs index 6a9da6c5..c9f9ddef 100644 --- a/egui/src/placer.rs +++ b/egui/src/placer.rs @@ -106,6 +106,7 @@ impl Placer { /// This is what you then pass to `advance_after_rects`. /// Use `justify_and_align` to get the inner `widget_rect`. pub(crate) fn next_space(&self, child_size: Vec2, item_spacing: Vec2) -> Rect { + egui_assert!(child_size.is_finite() && child_size.x >= 0.0 && child_size.y >= 0.0); self.region.sanity_check(); if let Some(grid) = &self.grid { grid.next_cell(self.region.cursor, child_size) diff --git a/egui_demo_app/src/backend_panel.rs b/egui_demo_app/src/backend_panel.rs index ccf77145..6ff02b6a 100644 --- a/egui_demo_app/src/backend_panel.rs +++ b/egui_demo_app/src/backend_panel.rs @@ -142,13 +142,6 @@ impl BackendPanel { if ui.button("Quit").clicked() { frame.quit(); } - - if ui - .button("Drag me to drag window") - .is_pointer_button_down_on() - { - frame.drag_window(); - } } } @@ -191,9 +184,18 @@ impl BackendPanel { { // frame.set_window_size(egui::vec2(375.0, 812.0)); // iPhone 12 mini frame.set_window_size(egui::vec2(375.0, 667.0)); // iPhone SE 2nd gen + frame.set_fullscreen(false); ui.close_menu(); } }); + + if !frame.info().window_info.fullscreen + && ui + .button("Drag me to drag window") + .is_pointer_button_down_on() + { + frame.drag_window(); + } } } diff --git a/egui_extras/src/image.rs b/egui_extras/src/image.rs index f92e238a..9c8fb3be 100644 --- a/egui_extras/src/image.rs +++ b/egui_extras/src/image.rs @@ -99,6 +99,16 @@ impl RetainedImage { self.size } + /// The width of the image. + pub fn width(&self) -> usize { + self.size[0] + } + + /// The height of the image. + pub fn height(&self) -> usize { + self.size[1] + } + /// The size of the image data (number of pixels wide/high). pub fn size_vec2(&self) -> egui::Vec2 { let [w, h] = self.size(); diff --git a/egui_glow/src/painter.rs b/egui_glow/src/painter.rs index 8eb3ce37..e6dfb429 100644 --- a/egui_glow/src/painter.rs +++ b/egui_glow/src/painter.rs @@ -468,6 +468,8 @@ impl Painter { } check_for_gl_error!(&self.gl, "paint_mesh"); + } else { + tracing::warn!("Failed to find texture {:?}", mesh.texture_id); } } diff --git a/epaint/src/tessellator.rs b/epaint/src/tessellator.rs index 6f9f69bb..32826f4e 100644 --- a/epaint/src/tessellator.rs +++ b/epaint/src/tessellator.rs @@ -1058,10 +1058,11 @@ impl Tessellator { None => true, Some(output_clipped_primitive) => { output_clipped_primitive.clip_rect != new_clip_rect - || if let Primitive::Mesh(output_mesh) = &output_clipped_primitive.primitive { - output_mesh.texture_id != new_shape.texture_id() - } else { - true + || match &output_clipped_primitive.primitive { + Primitive::Mesh(output_mesh) => { + output_mesh.texture_id != new_shape.texture_id() + } + Primitive::Callback(_) => true, } } }; diff --git a/sh/check.sh b/sh/check.sh index 23d80fab..7741bda3 100755 --- a/sh/check.sh +++ b/sh/check.sh @@ -62,8 +62,8 @@ cargo deny check # Also try https://github.com/google/bloaty # what compiles slowly? +# cargo clean && time cargo build -p eframe --timings # https://fasterthanli.me/articles/why-is-my-rust-build-so-slow -# (cd egui_demo_app && cargo clean && RUSTC_BOOTSTRAP=1 cargo build --release --quiet -Z timings) # what compiles slowly? # cargo llvm-lines --lib -p egui | head -20