Change grid base for auto columns

This commit is contained in:
Laurenz 2023-02-12 11:31:45 +01:00
parent 03cbdea4b4
commit e873468ea7
4 changed files with 26 additions and 22 deletions

View File

@ -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) {

BIN
tests/ref/bugs/grid-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 B

After

Width:  |  Height:  |  Size: 425 B

16
tests/typ/bugs/grid-1.typ Normal file
View File

@ -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)