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 000000000..6fd950ad3 Binary files /dev/null and b/tests/ref/bugs/grid-1.png differ diff --git a/tests/ref/layout/grid-4.png b/tests/ref/layout/grid-4.png index 2bbc84cc7..35a05ab52 100644 Binary files a/tests/ref/layout/grid-4.png and b/tests/ref/layout/grid-4.png differ 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)