Add a vskip constructor for vertical glue

This commit is contained in:
gloamxun committed 2026-10-20 13:25:06 +08:00
1 parent af8a34c2e2
commit b17e16df08
2 files changed
+22

No files matched your search

+20
View File
@@ -300,6 +300,11 @@ impl Unit {
Self::halign(id, rows, column_count, intercolumn)
}
/// A vertical glue item, corresponding to `\vskip`.
pub fn vskip(id: UnitId, height: i64) -> Self {
Self::vertical(id, vec![VerticalItem::Glue(height)])
}
/// A filled rule in the vertical list.
pub fn rule(id: UnitId, width: i64, height: i64) -> Self {
Self::vertical(id, vec![VerticalItem::Rule { width, height }])
@@ -1217,6 +1222,21 @@ mod tests {
assert_eq!(halign.cell_box(2, 0), Some((30, 110)));
}
#[test]
fn vskip_consumes_vertical_space() {
let block = |id| {
Unit::vertical(
id,
vec![VerticalItem::Box(VerticalBox {
width: 100,
height: 30,
})],
)
};
let document = Document::new(50, vec![block(1), Unit::vskip(2, 10), block(3)]);
let engine = Engine::layout(&document);
assert_eq!(engine.pages().len(), 2);
}
#[test]
fn vertical_rules_consume_page_height() {
let unit = Unit::rule(1, 100, 60);
+2
View File
@@ -208,3 +208,5 @@ for a later overlaid slash.
`\mathinner{...}` uses `MathClass::Inner` with 3mu on either side.
`\boxed{x}` adds 3pt padding around its body in the math model.
`Unit::vskip(id, height)` adds a vertical glue item to the page list.