From bd372792822ef4ac947fcc017fc4692b294eb53a Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Wed, 29 Nov 2023 19:05:43 -0800 Subject: [PATCH] Resizable windows now expand automatically This expansion only triggers if the root widget measures larger than the window's current size. We can't set a minimum size explicitly unless a Resize widget is present, as we don't have enough knowledge to ensure that the exact measurement we received was indeed the smallest layout in any given direction. We only know that given the current constraints, the returned measurement was the smallest possible. All future queries will have to still be done again, as any change to the constraints could impact the measured size. --- src/widgets/align.rs | 1 + src/window.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/widgets/align.rs b/src/widgets/align.rs index eb5da22..403f883 100644 --- a/src/widgets/align.rs +++ b/src/widgets/align.rs @@ -150,6 +150,7 @@ impl FrameInfo { fn measure(&self, available: ConstraintLimit, content: UPx) -> (UPx, UPx, UPx) { match available { ConstraintLimit::Fill(size) => { + let size = size.max(content); let remaining = size.saturating_sub(content); let (a, b) = match (self.a, self.b) { (Some(a), Some(b)) => (a, b), diff --git a/src/window.rs b/src/window.rs index 0892a72..42c2809 100644 --- a/src/window.rs +++ b/src/window.rs @@ -664,7 +664,7 @@ where window_size.map(ConstraintLimit::SizeToFit) }); let actual_size = if root_mode == RootMode::Align { - window_size + window_size.max(layout_size) } else { layout_size }; @@ -680,6 +680,10 @@ where let _ = layout_context .winit() .request_inner_size(PhysicalSize::from(new_size)); + } else if render_size != actual_size && resizable { + let _ = layout_context + .winit() + .request_inner_size(PhysicalSize::from(actual_size)); } self.root.set_layout(Rect::from(render_size.into_signed()));