From 3b3ce22adc48f9bc362dd546e8c2633d314e68fb Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 11 May 2024 23:49:27 +0900 Subject: [PATCH] Make sure plot size is positive (#4429) * Closes #4425 Fix: in Plot, Minimum values for screen protection. --- crates/egui_demo_lib/src/demo/context_menu.rs | 2 ++ crates/egui_plot/src/lib.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/egui_demo_lib/src/demo/context_menu.rs b/crates/egui_demo_lib/src/demo/context_menu.rs index 1b71eb4f787..5195a2b0609 100644 --- a/crates/egui_demo_lib/src/demo/context_menu.rs +++ b/crates/egui_demo_lib/src/demo/context_menu.rs @@ -97,11 +97,13 @@ impl super::View for ContextMenus { egui::Grid::new("button_grid").show(ui, |ui| { ui.add( egui::DragValue::new(&mut self.width) + .clamp_range(0.0..=f32::INFINITY) .speed(1.0) .prefix("Width: "), ); ui.add( egui::DragValue::new(&mut self.height) + .clamp_range(0.0..=f32::INFINITY) .speed(1.0) .prefix("Height: "), ); diff --git a/crates/egui_plot/src/lib.rs b/crates/egui_plot/src/lib.rs index cc721bd9cff..6b9d622d6e3 100644 --- a/crates/egui_plot/src/lib.rs +++ b/crates/egui_plot/src/lib.rs @@ -742,7 +742,7 @@ impl Plot { margin_fraction, width, height, - min_size, + mut min_size, data_aspect, view_aspect, mut show_x, @@ -773,6 +773,10 @@ impl Plot { // Determine position of widget. let pos = ui.available_rect_before_wrap().min; + // Minimum values for screen protection + min_size.x = min_size.x.at_least(1.0); + min_size.y = min_size.y.at_least(1.0); + // Determine size of widget. let size = { let width = width