From 34d1cf055e6afb9778b7656be33a0bca4d88dab1 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Thu, 10 Oct 2024 08:51:30 -0700 Subject: [PATCH] Stack/Grid exact-dimension scaling fix --- CHANGELOG.md | 2 ++ src/widgets/grid.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66b16c1..de0ba05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/widgets/grid.rs b/src/widgets/grid.rs index 0271c6d..e8dde71 100644 --- a/src/widgets/grid.rs +++ b/src/widgets/grid.rs @@ -278,6 +278,7 @@ pub(crate) struct GridLayout { fractional: Vec<(LotId, u8)>, fit_to_content: Vec, premeasured: Vec, + measured_scale: Fraction, pub orientation: Orientation, } @@ -300,6 +301,7 @@ impl GridLayout { fractional: Vec::new(), fit_to_content: Vec::new(), premeasured: Vec::new(), + measured_scale: Fraction::ONE, } } @@ -389,6 +391,7 @@ impl GridLayout { scale: Fraction, mut measure: impl FnMut(usize, usize, Size, bool) -> Size, ) -> Size { + 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( @@ -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()