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() { for y in 0..self.rows.len() {
if let Some(cell) = self.cell(x, y) { if let Some(cell) = self.cell(x, y) {
let size = Size::new(available, self.regions.base.y); let size = Size::new(available, self.regions.base.y);
let mut pod = let mut pod = Regions::one(size, size, Axes::splat(false));
Regions::one(size, self.regions.base, Axes::splat(false));
// For relative rows, we can already resolve the correct // For relative rows, we can already resolve the correct
// base, for auto it's already correct and for fr we could // base and for auto and fr we could only guess anyway.
// only guess anyway.
if let TrackSizing::Relative(v) = self.rows[y] { if let TrackSizing::Relative(v) = self.rows[y] {
pod.base.y = pod.base.y =
v.resolve(self.styles).relative_to(self.regions.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. // Determine the size for each region of the row.
for (x, &rcol) in self.rcols.iter().enumerate() { for (x, &rcol) in self.rcols.iter().enumerate() {
if let Some(cell) = self.cell(x, y) { if let Some(cell) = self.cell(x, y) {
let mut pod = self.regions.clone(); let mut pod = self.regions;
pod.first.x = rcol; pod.first.x = rcol;
pod.base.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 let mut sizes = cell
.layout(self.vt, self.styles, pod)? .layout(self.vt, self.styles, pod)?
.into_iter() .into_iter()
@ -578,13 +571,13 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
for (x, &rcol) in self.rcols.iter().enumerate() { for (x, &rcol) in self.rcols.iter().enumerate() {
if let Some(cell) = self.cell(x, y) { if let Some(cell) = self.cell(x, y) {
let size = Size::new(rcol, height); let size = Size::new(rcol, height);
let base = Size::new(
// Set the base to the region's base for auto rows and to the rcol,
// size for relative and fractional rows. match self.rows[y] {
let base = Axes::new(self.cols[x], self.rows[y]) TrackSizing::Auto => self.regions.base.y,
.map(|s| s == TrackSizing::Auto) _ => height,
.select(self.regions.base, size); },
);
let pod = Regions::one(size, base, Axes::splat(true)); let pod = Regions::one(size, base, Axes::splat(true));
let frame = cell.layout(self.vt, self.styles, pod)?.into_frame(); let frame = cell.layout(self.vt, self.styles, pod)?.into_frame();
output.push_frame(pos, frame); output.push_frame(pos, frame);
@ -616,11 +609,6 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
pod.first.x = rcol; pod.first.x = rcol;
pod.base.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. // Push the layouted frames into the individual output frames.
let fragment = cell.layout(self.vt, self.styles, pod)?; let fragment = cell.layout(self.vt, self.styles, pod)?;
for (output, frame) in outputs.iter_mut().zip(fragment) { 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)