Skip to content

Commit

Permalink
Resize exact fix, stack overflow now works
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Nov 10, 2023
1 parent e448723 commit 60e85c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
17 changes: 13 additions & 4 deletions src/widgets/resize.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use kludgine::figures::units::UPx;
use kludgine::figures::{Fraction, IntoSigned, IntoUnsigned, Rect, ScreenScale, Size};

use crate::context::{AsEventContext, LayoutContext};
Expand Down Expand Up @@ -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()
}
}

Expand All @@ -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)),
},
}
}
26 changes: 12 additions & 14 deletions src/widgets/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 60e85c7

Please sign in to comment.