From 769199648db30dadbec21cd1845bc325c5c91024 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Thu, 21 Mar 2024 21:47:25 +0900 Subject: [PATCH] Prevent egui::Window from becoming larger than Viewport (#4199) * Closes #3987 * Closes #3988 There is a need to prevent egui::Window from becoming larger than the Viewport. --------- Co-authored-by: Emil Ernerfeldt --- crates/egui/src/containers/window.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 698033cf..af6f6b16 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -431,6 +431,16 @@ impl<'open> Window<'open> { (0.0, 0.0) }; + { + // Prevent window from becoming larger than the constraint rect and/or screen rect. + let screen_rect = ctx.screen_rect(); + let max_rect = area.constrain_rect().unwrap_or(screen_rect); + let max_width = max_rect.width(); + let max_height = max_rect.height() - title_bar_height; + resize.max_size.x = resize.max_size.x.min(max_width); + resize.max_size.y = resize.max_size.y.min(max_height); + } + // First check for resize to avoid frame delay: let last_frame_outer_rect = area.state().rect(); let resize_interaction =