From 155e1389984ecc17f2eb90ab5614ccc8af487b09 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 10 May 2024 19:21:35 +0200 Subject: [PATCH] Fix debug-assert hit in panel sizing code --- crates/egui/src/containers/panel.rs | 8 ++------ crates/egui/src/placer.rs | 6 ++++++ crates/egui/src/ui.rs | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/egui/src/containers/panel.rs b/crates/egui/src/containers/panel.rs index ee41af879..324e17bf9 100644 --- a/crates/egui/src/containers/panel.rs +++ b/crates/egui/src/containers/panel.rs @@ -262,9 +262,7 @@ impl SidePanel { let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style())); let inner_response = frame.show(&mut panel_ui, |ui| { ui.set_min_height(ui.max_rect().height()); // Make sure the frame fills the full height - ui.set_min_width( - width_range.min - (frame.inner_margin.left + frame.inner_margin.right), - ); + ui.set_min_width((width_range.min - frame.inner_margin.sum().x).at_least(0.0)); add_contents(ui) }); @@ -730,9 +728,7 @@ impl TopBottomPanel { let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style())); let inner_response = frame.show(&mut panel_ui, |ui| { ui.set_min_width(ui.max_rect().width()); // Make the frame fill full width - ui.set_min_height( - height_range.min - (frame.inner_margin.top + frame.inner_margin.bottom), - ); + ui.set_min_height((height_range.min - frame.inner_margin.sum().y).at_least(0.0)); add_contents(ui) }); diff --git a/crates/egui/src/placer.rs b/crates/egui/src/placer.rs index 81c137f4e..7a3ca433b 100644 --- a/crates/egui/src/placer.rs +++ b/crates/egui/src/placer.rs @@ -248,6 +248,9 @@ impl Placer { /// Set the minimum width of the ui. /// This can't shrink the ui, only make it larger. pub(crate) fn set_min_width(&mut self, width: f32) { + if width <= 0.0 { + return; + } let rect = self.next_widget_space_ignore_wrap_justify(vec2(width, 0.0)); self.region.expand_to_include_x(rect.min.x); self.region.expand_to_include_x(rect.max.x); @@ -256,6 +259,9 @@ impl Placer { /// Set the minimum height of the ui. /// This can't shrink the ui, only make it larger. pub(crate) fn set_min_height(&mut self, height: f32) { + if height <= 0.0 { + return; + } let rect = self.next_widget_space_ignore_wrap_justify(vec2(0.0, height)); self.region.expand_to_include_y(rect.min.y); self.region.expand_to_include_y(rect.max.y); diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 1215d0eeb..4885b06be 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -530,12 +530,14 @@ impl Ui { /// Set the minimum width of the ui. /// This can't shrink the ui, only make it larger. pub fn set_min_width(&mut self, width: f32) { + egui_assert!(0.0 <= width); self.placer.set_min_width(width); } /// Set the minimum height of the ui. /// This can't shrink the ui, only make it larger. pub fn set_min_height(&mut self, height: f32) { + egui_assert!(0.0 <= height); self.placer.set_min_height(height); }