flush pending headers as soon as possible

- dont wait until the end of the region, as a header can start and end in the same region (i.e. never repeat).
This commit is contained in:
PgBiel 2025-04-06 03:51:06 -03:00
parent 054b3b89d1
commit 75403f86a9
2 changed files with 21 additions and 0 deletions

View File

@ -244,6 +244,7 @@ impl<'a> GridLayouter<'a> {
if y >= footer.start { if y >= footer.start {
if y == footer.start { if y == footer.start {
self.layout_footer(footer, engine, self.finished.len())?; self.layout_footer(footer, engine, self.finished.len())?;
self.flush_pending_headers();
} }
continue; continue;
} }
@ -251,6 +252,11 @@ impl<'a> GridLayouter<'a> {
self.layout_row(y, engine, 0)?; self.layout_row(y, engine, 0)?;
// After the first non-header row is placed, pending headers are no
// longer orphans and can repeat, so we move them to repeating
// headers.
self.flush_pending_headers();
y += 1; y += 1;
} }

View File

@ -73,6 +73,14 @@ impl<'a> GridLayouter<'a> {
)? )?
} }
// No chance of orphans as we're immediately placing conflicting
// headers afterwards, which basically are not headers, for all intents
// and purposes. It is therefore guaranteed that all new headers have
// been placed at least once.
if !conflicting_headers.is_empty() {
self.flush_pending_headers();
}
Ok(()) Ok(())
} }
@ -122,6 +130,13 @@ impl<'a> GridLayouter<'a> {
let [first_header, ..] = headers else { let [first_header, ..] = headers else {
return Ok(()); return Ok(());
}; };
// Should be impossible to have two consecutive chunks of pending
// headers since they are always as long as possible, only being
// interrupted by direct conflict between consecutive headers, in which
// case we flush pending headers immediately.
assert!(self.pending_headers.is_empty());
// Assuming non-conflicting headers sorted by increasing y, this must // Assuming non-conflicting headers sorted by increasing y, this must
// be the header with the lowest level (sorted by increasing levels). // be the header with the lowest level (sorted by increasing levels).
let first_level = first_header.unwrap().level; let first_level = first_header.unwrap().level;