mirror of
https://github.com/typst/typst
synced 2025-05-17 02:25:27 +08:00
Iterate over target regions instead in columns loop
This commit is contained in:
parent
7efdcdf247
commit
ee12bf6716
@ -81,7 +81,10 @@ impl Layout for ColumnsNode {
|
|||||||
(size, gutter)
|
(size, gutter)
|
||||||
});
|
});
|
||||||
|
|
||||||
let frames = self.child.layout(ctx, &pod);
|
// We reverse the frames so they can be used as a stack.
|
||||||
|
let mut frames = self.child.layout(ctx, &pod);
|
||||||
|
frames.reverse();
|
||||||
|
|
||||||
let dir = ctx.styles.get(ParNode::DIR);
|
let dir = ctx.styles.get(ParNode::DIR);
|
||||||
|
|
||||||
// Dealing with infinite height areas here.
|
// Dealing with infinite height areas here.
|
||||||
@ -95,8 +98,6 @@ impl Layout for ColumnsNode {
|
|||||||
regions.current.y
|
regions.current.y
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut regions = regions.clone();
|
|
||||||
|
|
||||||
let to = |cursor: Length, width: Length, regions: &Regions| {
|
let to = |cursor: Length, width: Length, regions: &Regions| {
|
||||||
if dir.is_positive() {
|
if dir.is_positive() {
|
||||||
cursor
|
cursor
|
||||||
@ -108,47 +109,44 @@ impl Layout for ColumnsNode {
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
for (i, child_frame) in frames.into_iter().enumerate() {
|
for (i, (current, base)) in regions.iter().take(total_regions).enumerate() {
|
||||||
let region = i / columns;
|
for col in 0 .. columns {
|
||||||
let size = std::iter::once(&first)
|
let total_col = i * columns + col;
|
||||||
.chain(sizes.iter())
|
let child_frame = match frames.pop() {
|
||||||
.nth(i)
|
Some(frame) => frame.item,
|
||||||
.copied()
|
None => break,
|
||||||
.unwrap_or_else(|| last_column_gutter.unwrap().0);
|
|
||||||
|
|
||||||
frame.push_frame(
|
|
||||||
Point::new(to(cursor, size.x, ®ions), Length::zero()),
|
|
||||||
child_frame.item,
|
|
||||||
);
|
|
||||||
|
|
||||||
cursor += size.x;
|
|
||||||
|
|
||||||
if i % columns == columns - 1 {
|
|
||||||
// Refresh column height for non-infinite regions here.
|
|
||||||
let height = if regions.current.y.is_infinite() {
|
|
||||||
height
|
|
||||||
} else {
|
|
||||||
regions.current.y
|
|
||||||
};
|
};
|
||||||
|
|
||||||
regions.next();
|
let size = std::iter::once(&first)
|
||||||
let old_frame = std::mem::replace(
|
.chain(sizes.iter())
|
||||||
&mut frame,
|
.nth(total_col)
|
||||||
Frame::new(Spec::new(regions.current.x, height)),
|
|
||||||
);
|
|
||||||
res.push(old_frame.constrain(Constraints::tight(®ions)));
|
|
||||||
cursor = Length::zero();
|
|
||||||
} else {
|
|
||||||
cursor += gutters
|
|
||||||
.get(region)
|
|
||||||
.copied()
|
.copied()
|
||||||
.unwrap_or_else(|| last_column_gutter.unwrap().1);
|
.unwrap_or_else(|| last_column_gutter.unwrap().0);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !frame.elements.is_empty() {
|
frame.push_frame(
|
||||||
res.push(frame.constrain(Constraints::tight(®ions)));
|
Point::new(to(cursor, size.x, ®ions), Length::zero()),
|
||||||
|
child_frame,
|
||||||
|
);
|
||||||
|
|
||||||
|
cursor += size.x
|
||||||
|
+ gutters
|
||||||
|
.get(i)
|
||||||
|
.copied()
|
||||||
|
.unwrap_or_else(|| last_column_gutter.unwrap().1)
|
||||||
|
}
|
||||||
|
|
||||||
|
let old_frame = std::mem::replace(
|
||||||
|
&mut frame,
|
||||||
|
Frame::new(Spec::new(regions.current.x, height)),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut cts = Constraints::new(regions.expand);
|
||||||
|
cts.base = base.map(Some);
|
||||||
|
cts.exact = current.map(Some);
|
||||||
|
res.push(old_frame.constrain(cts));
|
||||||
|
cursor = Length::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user