Browse Source

Fix debug-assert hit in panel sizing code

pull/4478/head
Emil Ernerfeldt 6 months ago
parent
commit
155e138998
  1. 8
      crates/egui/src/containers/panel.rs
  2. 6
      crates/egui/src/placer.rs
  3. 2
      crates/egui/src/ui.rs

8
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 frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style()));
let inner_response = frame.show(&mut panel_ui, |ui| { 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_height(ui.max_rect().height()); // Make sure the frame fills the full height
ui.set_min_width( ui.set_min_width((width_range.min - frame.inner_margin.sum().x).at_least(0.0));
width_range.min - (frame.inner_margin.left + frame.inner_margin.right),
);
add_contents(ui) add_contents(ui)
}); });
@ -730,9 +728,7 @@ impl TopBottomPanel {
let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style())); let frame = frame.unwrap_or_else(|| Frame::side_top_panel(ui.style()));
let inner_response = frame.show(&mut panel_ui, |ui| { 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_width(ui.max_rect().width()); // Make the frame fill full width
ui.set_min_height( ui.set_min_height((height_range.min - frame.inner_margin.sum().y).at_least(0.0));
height_range.min - (frame.inner_margin.top + frame.inner_margin.bottom),
);
add_contents(ui) add_contents(ui)
}); });

6
crates/egui/src/placer.rs

@ -248,6 +248,9 @@ impl Placer {
/// Set the minimum width of the ui. /// Set the minimum width of the ui.
/// This can't shrink the ui, only make it larger. /// This can't shrink the ui, only make it larger.
pub(crate) fn set_min_width(&mut self, width: f32) { 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)); 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.min.x);
self.region.expand_to_include_x(rect.max.x); self.region.expand_to_include_x(rect.max.x);
@ -256,6 +259,9 @@ impl Placer {
/// Set the minimum height of the ui. /// Set the minimum height of the ui.
/// This can't shrink the ui, only make it larger. /// This can't shrink the ui, only make it larger.
pub(crate) fn set_min_height(&mut self, height: f32) { 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)); 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.min.y);
self.region.expand_to_include_y(rect.max.y); self.region.expand_to_include_y(rect.max.y);

2
crates/egui/src/ui.rs

@ -530,12 +530,14 @@ impl Ui {
/// Set the minimum width of the ui. /// Set the minimum width of the ui.
/// This can't shrink the ui, only make it larger. /// This can't shrink the ui, only make it larger.
pub fn set_min_width(&mut self, width: f32) { pub fn set_min_width(&mut self, width: f32) {
egui_assert!(0.0 <= width);
self.placer.set_min_width(width); self.placer.set_min_width(width);
} }
/// Set the minimum height of the ui. /// Set the minimum height of the ui.
/// This can't shrink the ui, only make it larger. /// This can't shrink the ui, only make it larger.
pub fn set_min_height(&mut self, height: f32) { pub fn set_min_height(&mut self, height: f32) {
egui_assert!(0.0 <= height);
self.placer.set_min_height(height); self.placer.set_min_height(height);
} }

Loading…
Cancel
Save