Skip to main content

place

Function place 

Source
pub fn place<R, C>(rows: R) -> Placement
where R: IntoIterator<Item = C>, C: IntoIterator<Item = Span>,
Expand description

The grid column each cell starts in, and the table’s width, for rows given as their cells’ spans in reading order.

A cell starts at the first column, from where the row has got to, that no cell merged down from a row above still covers. The width is the furthest any cell reaches — which can be further than a row’s own spans add up to, since a vertical span from above pushes the row’s cells rightward.

use unparser_shared::grid::{place, Span};

// ┌────────┬───────────┐
// │ Region │   Sales   │
// │        ├─────┬─────┤
// │        │2024 │2025 │
// └────────┴─────┴─────┘
let placement = place([
    vec![Span::new(2, 1), Span::new(1, 2)],
    vec![Span::single(), Span::single()],
]);
assert_eq!(placement.columns, vec![vec![0, 1], vec![1, 2]]);
assert_eq!(placement.width, 3);