mirror of
https://github.com/typst/typst
synced 2025-05-15 17:45:27 +08:00
Turn repeat
into a single layouter (#4758)
This commit is contained in:
parent
d84a7e423b
commit
351bac8b68
@ -5,7 +5,7 @@ use crate::foundations::{
|
|||||||
};
|
};
|
||||||
use crate::introspection::Locator;
|
use crate::introspection::Locator;
|
||||||
use crate::layout::{
|
use crate::layout::{
|
||||||
Abs, AlignElem, Axes, BlockElem, Fragment, Frame, Point, Regions, Size,
|
Abs, AlignElem, Axes, BlockElem, Frame, Point, Region, Regions, Size,
|
||||||
};
|
};
|
||||||
use crate::utils::Numeric;
|
use crate::utils::Numeric;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ pub struct RepeatElem {
|
|||||||
|
|
||||||
impl Show for Packed<RepeatElem> {
|
impl Show for Packed<RepeatElem> {
|
||||||
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
|
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
|
||||||
Ok(BlockElem::multi_layouter(self.clone(), layout_repeat)
|
Ok(BlockElem::single_layouter(self.clone(), layout_repeat)
|
||||||
.pack()
|
.pack()
|
||||||
.spanned(self.span()))
|
.spanned(self.span()))
|
||||||
}
|
}
|
||||||
@ -52,20 +52,20 @@ fn layout_repeat(
|
|||||||
engine: &mut Engine,
|
engine: &mut Engine,
|
||||||
locator: Locator,
|
locator: Locator,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: Regions,
|
region: Region,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Frame> {
|
||||||
let pod = Regions::one(regions.size, Axes::new(false, false));
|
let pod = Regions::one(region.size, Axes::new(false, false));
|
||||||
let piece = elem.body().layout(engine, locator, styles, pod)?.into_frame();
|
let piece = elem.body().layout(engine, locator, styles, pod)?.into_frame();
|
||||||
|
|
||||||
let align = AlignElem::alignment_in(styles).resolve(styles);
|
let align = AlignElem::alignment_in(styles).resolve(styles);
|
||||||
|
|
||||||
let fill = regions.size.x;
|
let fill = region.size.x;
|
||||||
let width = piece.width();
|
let width = piece.width();
|
||||||
let count = (fill / width).floor();
|
let count = (fill / width).floor();
|
||||||
let remaining = fill % width;
|
let remaining = fill % width;
|
||||||
let apart = remaining / (count - 1.0);
|
let apart = remaining / (count - 1.0);
|
||||||
|
|
||||||
let size = Size::new(regions.size.x, piece.height());
|
let size = Size::new(region.size.x, piece.height());
|
||||||
|
|
||||||
if !size.is_finite() {
|
if !size.is_finite() {
|
||||||
bail!(elem.span(), "repeat with no size restrictions");
|
bail!(elem.span(), "repeat with no size restrictions");
|
||||||
@ -88,5 +88,5 @@ fn layout_repeat(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Fragment::frame(frame))
|
Ok(frame)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user