From 60e85c78d04ff0b71ef1944245734c8ff9cba681 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Fri, 10 Nov 2023 15:11:46 -0800 Subject: [PATCH] Resize exact fix, stack overflow now works --- src/widgets/resize.rs | 17 +++++++++++++---- src/widgets/stack.rs | 26 ++++++++++++-------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/widgets/resize.rs b/src/widgets/resize.rs index af7b5ae8c..7dc81e360 100644 --- a/src/widgets/resize.rs +++ b/src/widgets/resize.rs @@ -1,3 +1,4 @@ +use kludgine::figures::units::UPx; use kludgine::figures::{Fraction, IntoSigned, IntoUnsigned, Rect, ScreenScale, Size}; use crate::context::{AsEventContext, LayoutContext}; @@ -81,7 +82,12 @@ impl WrapperWidget for Resize { ); context.for_other(&child).layout(available_space) }; - Rect::from(size.into_signed()) + Size::::new( + self.width.clamp(size.width, context.gfx.scale()), + self.height.clamp(size.height, context.gfx.scale()), + ) + .into_signed() + .into() } } @@ -92,8 +98,11 @@ fn override_constraint( ) -> ConstraintLimit { match constraint { ConstraintLimit::Known(size) => ConstraintLimit::Known(range.clamp(size, scale)), - ConstraintLimit::ClippedAfter(clipped_after) => { - ConstraintLimit::ClippedAfter(range.clamp(clipped_after, scale)) - } + ConstraintLimit::ClippedAfter(clipped_after) => match (range.minimum(), range.maximum()) { + (Some(min), Some(max)) if min == max => { + ConstraintLimit::Known(min.into_px(scale).into_unsigned()) + } + _ => ConstraintLimit::ClippedAfter(range.clamp(clipped_after, scale)), + }, } } diff --git a/src/widgets/stack.rs b/src/widgets/stack.rs index 0dc1d51bf..e3a9e841f 100644 --- a/src/widgets/stack.rs +++ b/src/widgets/stack.rs @@ -403,18 +403,14 @@ impl Layout { // Measure the children that fit their content for &id in &self.measured { let index = self.children.index_of_id(id).expect("child not found"); - if remaining > 0 { - let (measured, _) = self.orientation.split_size(measure( - index, - self.orientation - .make_size(ConstraintLimit::ClippedAfter(remaining), other_constraint), - false, - )); - self.layouts[index].size = measured; - remaining = remaining.saturating_sub(measured); - } else { - self.layouts[index].size = UPx(0); - } + let (measured, _) = self.orientation.split_size(measure( + index, + self.orientation + .make_size(ConstraintLimit::ClippedAfter(remaining), other_constraint), + false, + )); + self.layouts[index].size = measured; + remaining = remaining.saturating_sub(measured); } // Measure the weighted children within the remaining space @@ -449,15 +445,17 @@ impl Layout { offset += self.layouts[index].size; let (_, measured) = self.orientation.split_size(measure( index, - self.orientation.make_size( + dbg!(self.orientation.make_size( ConstraintLimit::Known(self.layouts[index].size.into_px(scale).into_unsigned()), other_constraint, - ), + )), true, )); self.other = self.other.max(measured); } + println!("Total height: {offset}"); + self.other = match other_constraint { ConstraintLimit::Known(max) => self.other.max(max), ConstraintLimit::ClippedAfter(clip_limit) => self.other.min(clip_limit),