From e873468ea7deedd6d43f24100591c60a7de5accc Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 12 Feb 2023 11:31:45 +0100 Subject: [PATCH] Change grid base for auto columns --- library/src/layout/grid.rs | 32 ++++++++++---------------------- tests/ref/bugs/grid-1.png | Bin 0 -> 928 bytes tests/ref/layout/grid-4.png | Bin 423 -> 425 bytes tests/typ/bugs/grid-1.typ | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 tests/ref/bugs/grid-1.png create mode 100644 tests/typ/bugs/grid-1.typ diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs index 60a5e7482..46518f82b 100644 --- a/library/src/layout/grid.rs +++ b/library/src/layout/grid.rs @@ -410,12 +410,10 @@ impl<'a, 'v> GridLayouter<'a, 'v> { for y in 0..self.rows.len() { if let Some(cell) = self.cell(x, y) { let size = Size::new(available, self.regions.base.y); - let mut pod = - Regions::one(size, self.regions.base, Axes::splat(false)); + let mut pod = Regions::one(size, size, Axes::splat(false)); // For relative rows, we can already resolve the correct - // base, for auto it's already correct and for fr we could - // only guess anyway. + // base and for auto and fr we could only guess anyway. if let TrackSizing::Relative(v) = self.rows[y] { pod.base.y = v.resolve(self.styles).relative_to(self.regions.base.y); @@ -488,15 +486,10 @@ impl<'a, 'v> GridLayouter<'a, 'v> { // Determine the size for each region of the row. for (x, &rcol) in self.rcols.iter().enumerate() { if let Some(cell) = self.cell(x, y) { - let mut pod = self.regions.clone(); + let mut pod = self.regions; pod.first.x = rcol; pod.base.x = rcol; - // All widths should be `rcol` except the base for auto columns. - if self.cols[x] == TrackSizing::Auto { - pod.base.x = self.regions.base.x; - } - let mut sizes = cell .layout(self.vt, self.styles, pod)? .into_iter() @@ -578,13 +571,13 @@ impl<'a, 'v> GridLayouter<'a, 'v> { for (x, &rcol) in self.rcols.iter().enumerate() { if let Some(cell) = self.cell(x, y) { let size = Size::new(rcol, height); - - // Set the base to the region's base for auto rows and to the - // size for relative and fractional rows. - let base = Axes::new(self.cols[x], self.rows[y]) - .map(|s| s == TrackSizing::Auto) - .select(self.regions.base, size); - + let base = Size::new( + rcol, + match self.rows[y] { + TrackSizing::Auto => self.regions.base.y, + _ => height, + }, + ); let pod = Regions::one(size, base, Axes::splat(true)); let frame = cell.layout(self.vt, self.styles, pod)?.into_frame(); output.push_frame(pos, frame); @@ -616,11 +609,6 @@ impl<'a, 'v> GridLayouter<'a, 'v> { pod.first.x = rcol; pod.base.x = rcol; - // All widths should be `rcol` except the base for auto columns. - if self.cols[x] == TrackSizing::Auto { - pod.base.x = self.regions.base.x; - } - // Push the layouted frames into the individual output frames. let fragment = cell.layout(self.vt, self.styles, pod)?; for (output, frame) in outputs.iter_mut().zip(fragment) { diff --git a/tests/ref/bugs/grid-1.png b/tests/ref/bugs/grid-1.png new file mode 100644 index 0000000000000000000000000000000000000000..6fd950ad3e871665ca5b95fb771a963ab6229e8b GIT binary patch literal 928 zcmeAS@N?(olHy`uVBq!ia0y~yU}OQ}6CBJyk@eb7aFJHQJ>EgwU zM~)oXzkmO}efzd=-@a4Zghl{(t`QHdb!7UJo9r{l(Vi50|vi$EAHyEu5Sb_i4{g-EvjH~6FoQ~yfo&bPDW>U&p9V`#xNgpkOGLl!V4 zhn_sH>A(10B6^3cS`0f}G=byszD9^k(HsamnhWNBU*eHp`OD&3mQmX_Nzqn+iK5>Rd9YUAGk8GB&QZ3Jz!BGkpchY64X6M*^ z#{d{{i3TleKX2}R!?AdK$MvsIIKl-5)lUlQd1*eiusrlCShN51P4#0(=U&{SdP#^A zYDB<#$AFzkHU)@3JaCWkkouw8U3MTP@tdnFcTJN`{BQdxRn_v4ugj6ZqL$Yk9fzNA z%swy3&kZzj>E5@N-b+-4px#*!*E~T99)L&;o{kCT2yWd8_6--KC+;}>bqX+nGkCiC KxvXkb literal 0 HcmV?d00001 diff --git a/tests/ref/layout/grid-4.png b/tests/ref/layout/grid-4.png index 2bbc84cc7627c3679b71409ec65bbea47d41c780..35a05ab52c1a7d863954709c437267cf8d1b12ea 100644 GIT binary patch literal 425 zcmeAS@N?(olHy`uVBq!ia0y~yU}OQ}vn91WMq8U z^FY3_0SXG{2DEQ0ES0`>T>Scem`ZGPM2~?v%;=UH7V%J!)#o@&HDH1uy5$ec?>-J> z(8;Nbu41w&6B0NS+vI!#SqDcaXInLjp}SeyCkP_@6qOz4!NCjkR-)q}#;KR}3iF>| Rd22WQ%mvv4FO#lJ0X=MNa literal 423 zcmeAS@N?(olHy`uVBq!ia0y~yU}OQ}vnF{I+w+q;fj4GIFR0sRxgU$8WWzxbD)l`Swab;Z|zVXfP*&OErm z%-;bBUQ88`Vr7Ja#1yAJGk!V>AcK9L9!FQ!t#t({hJyeDHyFF3Js|*Oz(EFSCMa-{ zb-H)i;_2?sQ5PoZPni!>iH&~Ivml|T0SXHI3|2G&*##~gy&xJ64D1f>R)(1lq7NNt zxuU^=3?2*LStE$-?sq~aipmN|V20M$eQ*mdKI;Vst0DeY%&j0`b diff --git a/tests/typ/bugs/grid-1.typ b/tests/typ/bugs/grid-1.typ new file mode 100644 index 000000000..c583cfe58 --- /dev/null +++ b/tests/typ/bugs/grid-1.typ @@ -0,0 +1,16 @@ +// Test that grid base for auto rows makes sense. + +--- +#set page(height: 150pt) +#table( + columns: (1.5cm, auto), + rows: (auto, auto), + rect(width: 100%, fill: red), + rect(width: 100%, fill: blue), + rect(width: 100%, height: 50%, fill: green), +) + +--- +#rect(width: 100%, height: 1em) +- #rect(width: 100%, height: 1em) + - #rect(width: 100%, height: 1em)