From 9b9f6ff59d5b5f9f2b8e1cb108f8f2c325482603 Mon Sep 17 00:00:00 2001 From: Arduano Date: Wed, 8 Nov 2023 19:19:21 +1100 Subject: [PATCH 1/2] Add max width and max height options to resize and window containers --- crates/egui/src/containers/resize.rs | 12 ++++++++++++ crates/egui/src/containers/window.rs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index 78917234216..533601d4b34 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -123,6 +123,18 @@ impl Resize { self } + /// Won't expand to larger than this + pub fn max_width(mut self, max_width: f32) -> Self { + self.max_size.x = max_width; + self + } + + /// Won't expand to larger than this + pub fn max_height(mut self, max_height: f32) -> Self { + self.max_size.y = max_height; + self + } + /// Can you resize it with the mouse? /// /// Note that a window can still auto-resize. diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index c12199d40ac..1f458853695 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -126,6 +126,18 @@ impl<'open> Window<'open> { self } + /// Set maximum width of the window. + pub fn max_width(mut self, max_width: f32) -> Self { + self.resize = self.resize.max_width(max_width); + self + } + + /// Set maximum height of the window. + pub fn max_height(mut self, max_height: f32) -> Self { + self.resize = self.resize.max_height(max_height); + self + } + /// Set current position of the window. /// If the window is movable it is up to you to keep track of where it moved to! pub fn current_pos(mut self, current_pos: impl Into) -> Self { From 405ccbbeb301fee654bbf1836ef6d74d4d0fc959 Mon Sep 17 00:00:00 2001 From: Arduano Date: Wed, 8 Nov 2023 19:24:21 +1100 Subject: [PATCH 2/2] Add more helpers --- crates/egui/src/containers/window.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 1f458853695..a2deb6094e3 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -126,6 +126,12 @@ impl<'open> Window<'open> { self } + /// Set minimum size of the window, equivalent to calling both `min_width` and `min_height`. + pub fn min_size(mut self, min_size: impl Into) -> Self { + self.resize = self.resize.min_size(min_size); + self + } + /// Set maximum width of the window. pub fn max_width(mut self, max_width: f32) -> Self { self.resize = self.resize.max_width(max_width); @@ -138,6 +144,12 @@ impl<'open> Window<'open> { self } + /// Set maximum size of the window, equivalent to calling both `max_width` and `max_height`. + pub fn max_size(mut self, max_size: impl Into) -> Self { + self.resize = self.resize.max_size(max_size); + self + } + /// Set current position of the window. /// If the window is movable it is up to you to keep track of where it moved to! pub fn current_pos(mut self, current_pos: impl Into) -> Self {