Browse Source

Make sure egui can handle zero-sized screen rect

This would previously hit a debug assert

Fixes https://github.com/emilk/egui/issues/395
pull/422/head
Emil Ernerfeldt 4 years ago
parent
commit
dd4ac43b13
  1. 7
      egui/src/containers/frame.rs
  2. 19
      egui_demo_lib/src/lib.rs

7
egui/src/containers/frame.rs

@ -121,7 +121,12 @@ impl Frame {
pub fn begin(self, ui: &mut Ui) -> Prepared {
let where_to_put_background = ui.painter().add(Shape::Noop);
let outer_rect_bounds = ui.available_rect_before_wrap();
let inner_rect = outer_rect_bounds.shrink2(self.margin);
let mut inner_rect = outer_rect_bounds.shrink2(self.margin);
// Make sure we don't shrink to the negative:
inner_rect.max.x = inner_rect.max.x.max(inner_rect.min.x);
inner_rect.max.y = inner_rect.max.y.max(inner_rect.min.y);
let content_ui = ui.child_ui(inner_rect, *ui.layout());
// content_ui.set_clip_rect(outer_rect_bounds.shrink(self.stroke.width * 0.5)); // Can't do this since we don't know final size yet

19
egui_demo_lib/src/lib.rs

@ -139,3 +139,22 @@ fn test_egui_e2e() {
assert!(!clipped_meshes.is_empty());
}
}
#[test]
fn test_egui_zero_window_size() {
let mut demo_windows = crate::DemoWindows::default();
let mut ctx = egui::CtxRef::default();
let raw_input = egui::RawInput {
screen_rect: Some(egui::Rect::from_min_max(egui::Pos2::ZERO, egui::Pos2::ZERO)),
..Default::default()
};
const NUM_FRAMES: usize = 5;
for _ in 0..NUM_FRAMES {
ctx.begin_frame(raw_input.clone());
demo_windows.ui(&ctx);
let (_output, shapes) = ctx.end_frame();
let clipped_meshes = ctx.tessellate(shapes);
assert!(clipped_meshes.is_empty(), "There should be nothing to show");
}
}

Loading…
Cancel
Save