Resize exact fix, stack overflow now works

This commit is contained in:
Jonathan Johnson 2023-11-10 15:11:46 -08:00
parent e44872351d
commit 60e85c78d0
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
2 changed files with 25 additions and 18 deletions

View file

@ -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::<UPx>::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)),
},
}
}

View file

@ -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),