mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Make column child frames expand horizontally
This commit is contained in:
parent
ee12bf6716
commit
accf70949d
@ -69,6 +69,7 @@ impl Layout for ColumnsNode {
|
|||||||
let mut pod =
|
let mut pod =
|
||||||
Regions::one(first, Spec::new(first.x, regions.base.y), regions.expand);
|
Regions::one(first, Spec::new(first.x, regions.base.y), regions.expand);
|
||||||
pod.backlog = sizes.clone().into_iter();
|
pod.backlog = sizes.clone().into_iter();
|
||||||
|
pod.expand.x = true;
|
||||||
|
|
||||||
// We have to treat the last region separately.
|
// We have to treat the last region separately.
|
||||||
let last_column_gutter = regions.last.map(|last| {
|
let last_column_gutter = regions.last.map(|last| {
|
||||||
@ -81,9 +82,7 @@ impl Layout for ColumnsNode {
|
|||||||
(size, gutter)
|
(size, gutter)
|
||||||
});
|
});
|
||||||
|
|
||||||
// We reverse the frames so they can be used as a stack.
|
let frames = self.child.layout(ctx, &pod);
|
||||||
let mut frames = self.child.layout(ctx, &pod);
|
|
||||||
frames.reverse();
|
|
||||||
|
|
||||||
let dir = ctx.styles.get(ParNode::DIR);
|
let dir = ctx.styles.get(ParNode::DIR);
|
||||||
|
|
||||||
@ -107,30 +106,26 @@ impl Layout for ColumnsNode {
|
|||||||
};
|
};
|
||||||
let mut cursor = Length::zero();
|
let mut cursor = Length::zero();
|
||||||
|
|
||||||
|
let mut frames = frames.into_iter();
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
let mut frame = Frame::new(Spec::new(regions.current.x, height));
|
let mut frame = Frame::new(Spec::new(regions.current.x, height));
|
||||||
let total_regions = (frames.len() as f32 / columns as f32).ceil() as usize;
|
let total_regions = (frames.len() as f32 / columns as f32).ceil() as usize;
|
||||||
|
|
||||||
for (i, (current, base)) in regions.iter().take(total_regions).enumerate() {
|
for (i, (current, base)) in regions.iter().take(total_regions).enumerate() {
|
||||||
for col in 0 .. columns {
|
for _ in 0 .. columns {
|
||||||
let total_col = i * columns + col;
|
let child_frame = match frames.next() {
|
||||||
let child_frame = match frames.pop() {
|
|
||||||
Some(frame) => frame.item,
|
Some(frame) => frame.item,
|
||||||
None => break,
|
None => break,
|
||||||
};
|
};
|
||||||
|
|
||||||
let size = std::iter::once(&first)
|
let size = child_frame.size.x;
|
||||||
.chain(sizes.iter())
|
|
||||||
.nth(total_col)
|
|
||||||
.copied()
|
|
||||||
.unwrap_or_else(|| last_column_gutter.unwrap().0);
|
|
||||||
|
|
||||||
frame.push_frame(
|
frame.push_frame(
|
||||||
Point::new(to(cursor, size.x, ®ions), Length::zero()),
|
Point::new(to(cursor, size, ®ions), Length::zero()),
|
||||||
child_frame,
|
child_frame,
|
||||||
);
|
);
|
||||||
|
|
||||||
cursor += size.x
|
cursor += size
|
||||||
+ gutters
|
+ gutters
|
||||||
.get(i)
|
.get(i)
|
||||||
.copied()
|
.copied()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user