Skip to content

Commit f1cd846

Browse files
emilkhacknus
authored andcommitted
Fix debug-assert hit in panel sizing code
1 parent a7fa541 commit f1cd846

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

crates/egui/src/containers/panel.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ impl SidePanel {
262262
let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style()));
263263
let inner_response = frame.show(&mut panel_ui, |ui| {
264264
ui.set_min_height(ui.max_rect().height()); // Make sure the frame fills the full height
265-
ui.set_min_width(
266-
width_range.min - (frame.inner_margin.left + frame.inner_margin.right),
267-
);
265+
ui.set_min_width((width_range.min - frame.inner_margin.sum().x).at_least(0.0));
268266
add_contents(ui)
269267
});
270268

@@ -730,9 +728,7 @@ impl TopBottomPanel {
730728
let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style()));
731729
let inner_response = frame.show(&mut panel_ui, |ui| {
732730
ui.set_min_width(ui.max_rect().width()); // Make the frame fill full width
733-
ui.set_min_height(
734-
height_range.min - (frame.inner_margin.top + frame.inner_margin.bottom),
735-
);
731+
ui.set_min_height((height_range.min - frame.inner_margin.sum().y).at_least(0.0));
736732
add_contents(ui)
737733
});
738734

crates/egui/src/placer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ impl Placer {
248248
/// Set the minimum width of the ui.
249249
/// This can't shrink the ui, only make it larger.
250250
pub(crate) fn set_min_width(&mut self, width: f32) {
251+
if width <= 0.0 {
252+
return;
253+
}
251254
let rect = self.next_widget_space_ignore_wrap_justify(vec2(width, 0.0));
252255
self.region.expand_to_include_x(rect.min.x);
253256
self.region.expand_to_include_x(rect.max.x);
@@ -256,6 +259,9 @@ impl Placer {
256259
/// Set the minimum height of the ui.
257260
/// This can't shrink the ui, only make it larger.
258261
pub(crate) fn set_min_height(&mut self, height: f32) {
262+
if height <= 0.0 {
263+
return;
264+
}
259265
let rect = self.next_widget_space_ignore_wrap_justify(vec2(0.0, height));
260266
self.region.expand_to_include_y(rect.min.y);
261267
self.region.expand_to_include_y(rect.max.y);

crates/egui/src/ui.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,14 @@ impl Ui {
530530
/// Set the minimum width of the ui.
531531
/// This can't shrink the ui, only make it larger.
532532
pub fn set_min_width(&mut self, width: f32) {
533+
egui_assert!(0.0 <= width);
533534
self.placer.set_min_width(width);
534535
}
535536

536537
/// Set the minimum height of the ui.
537538
/// This can't shrink the ui, only make it larger.
538539
pub fn set_min_height(&mut self, height: f32) {
540+
egui_assert!(0.0 <= height);
539541
self.placer.set_min_height(height);
540542
}
541543

0 commit comments

Comments
 (0)