Skip to content

Commit

Permalink
Stack/Grid exact-dimension scaling fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Oct 10, 2024
1 parent 7da5be6 commit 34d1cf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
on the next cursor event.
- `Scroll` no longer attempts to preserve scroll amounts using a percentage when
its child changes size.
- `Stack` and `Grid` now properly recompute exact-sized `Lp` children when the
display scale is changed.

### Added

Expand Down
17 changes: 17 additions & 0 deletions src/widgets/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ pub(crate) struct GridLayout {
fractional: Vec<(LotId, u8)>,
fit_to_content: Vec<LotId>,
premeasured: Vec<LotId>,
measured_scale: Fraction,
pub orientation: Orientation,
}

Expand All @@ -300,6 +301,7 @@ impl GridLayout {
fractional: Vec::new(),
fit_to_content: Vec::new(),
premeasured: Vec::new(),
measured_scale: Fraction::ONE,
}
}

Expand Down Expand Up @@ -389,6 +391,7 @@ impl GridLayout {
scale: Fraction,
mut measure: impl FnMut(usize, usize, Size<ConstraintLimit>, bool) -> Size<UPx>,
) -> Size<UPx> {
self.update_measured(scale);
let (space_constraint, mut other_constraint) = self.orientation.split_size(available);
let available_space = space_constraint.max();
let known_gutters = gutter.saturating_mul(UPx::new(
Expand Down Expand Up @@ -534,6 +537,20 @@ impl GridLayout {
self.orientation.make_size(measured, total_other)
}

fn update_measured(&mut self, scale: Fraction) {
if self.measured_scale != scale {
self.measured_scale = scale;

for (spec, layout) in self.children.iter().zip(self.layouts.iter_mut()) {
let GridDimension::Measured { size } = spec else {
continue;
};

layout.size = size.into_upx(scale);
}
}
}

fn total_other(&self) -> UPx {
self.others
.iter()
Expand Down

0 comments on commit 34d1cf0

Please sign in to comment.