mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Copyable regions
This commit is contained in:
parent
11c7ceb29e
commit
e6857f810e
@ -81,7 +81,7 @@ impl<const L: ListKind> Layout for ListNode<L> {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut cells = vec![];
|
let mut cells = vec![];
|
||||||
let mut number = NonZeroUsize::new(1).unwrap();
|
let mut number = NonZeroUsize::new(1).unwrap();
|
||||||
|
@ -55,7 +55,7 @@ impl Layout for TableNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let fill = styles.get(Self::FILL);
|
let fill = styles.get(Self::FILL);
|
||||||
let stroke = styles.get(Self::STROKE).map(PartialStroke::unwrap_or_default);
|
let stroke = styles.get(Self::STROKE).map(PartialStroke::unwrap_or_default);
|
||||||
|
@ -31,7 +31,7 @@ impl Layout for AlignNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
// The child only needs to expand along an axis if there's no alignment.
|
// The child only needs to expand along an axis if there's no alignment.
|
||||||
let mut pod = regions.clone();
|
let mut pod = regions.clone();
|
||||||
@ -44,7 +44,7 @@ impl Layout for AlignNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Layout the child.
|
// Layout the child.
|
||||||
let mut fragment = self.child.layout(vt, styles.chain(&map), &pod)?;
|
let mut fragment = self.child.layout(vt, styles.chain(&map), pod)?;
|
||||||
for (region, frame) in regions.iter().zip(&mut fragment) {
|
for (region, frame) in regions.iter().zip(&mut fragment) {
|
||||||
// Align in the target size. The target size depends on whether we
|
// Align in the target size. The target size depends on whether we
|
||||||
// should expand.
|
// should expand.
|
||||||
|
@ -31,7 +31,7 @@ impl Layout for ColumnsNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
// Separating the infinite space into infinite columns does not make
|
// Separating the infinite space into infinite columns does not make
|
||||||
// much sense.
|
// much sense.
|
||||||
@ -44,21 +44,23 @@ impl Layout for ColumnsNode {
|
|||||||
let gutter = styles.get(Self::GUTTER).relative_to(regions.base.x);
|
let gutter = styles.get(Self::GUTTER).relative_to(regions.base.x);
|
||||||
let width = (regions.first.x - gutter * (columns - 1) as f64) / columns as f64;
|
let width = (regions.first.x - gutter * (columns - 1) as f64) / columns as f64;
|
||||||
|
|
||||||
|
let backlog: Vec<_> = std::iter::once(®ions.first.y)
|
||||||
|
.chain(regions.backlog)
|
||||||
|
.flat_map(|&height| std::iter::repeat(height).take(columns))
|
||||||
|
.skip(1)
|
||||||
|
.collect();
|
||||||
|
|
||||||
// Create the pod regions.
|
// Create the pod regions.
|
||||||
let pod = Regions {
|
let pod = Regions {
|
||||||
first: Size::new(width, regions.first.y),
|
first: Size::new(width, regions.first.y),
|
||||||
base: Size::new(width, regions.base.y),
|
base: Size::new(width, regions.base.y),
|
||||||
backlog: std::iter::once(®ions.first.y)
|
backlog: &backlog,
|
||||||
.chain(regions.backlog.as_slice())
|
|
||||||
.flat_map(|&height| std::iter::repeat(height).take(columns))
|
|
||||||
.skip(1)
|
|
||||||
.collect(),
|
|
||||||
last: regions.last,
|
last: regions.last,
|
||||||
expand: Axes::new(true, regions.expand.y),
|
expand: Axes::new(true, regions.expand.y),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Layout the children.
|
// Layout the children.
|
||||||
let mut frames = self.child.layout(vt, styles, &pod)?.into_iter();
|
let mut frames = self.child.layout(vt, styles, pod)?.into_iter();
|
||||||
let mut finished = vec![];
|
let mut finished = vec![];
|
||||||
|
|
||||||
let dir = styles.get(TextNode::DIR);
|
let dir = styles.get(TextNode::DIR);
|
||||||
|
@ -25,7 +25,7 @@ impl Layout for BoxNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
// The "pod" is the region into which the child will be layouted.
|
// The "pod" is the region into which the child will be layouted.
|
||||||
let pod = {
|
let pod = {
|
||||||
@ -47,7 +47,7 @@ impl Layout for BoxNode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Layout the child.
|
// Layout the child.
|
||||||
let mut frame = self.child.layout(vt, styles, &pod)?.into_frame();
|
let mut frame = self.child.layout(vt, styles, pod)?.into_frame();
|
||||||
|
|
||||||
// Ensure frame size matches regions size if expansion is on.
|
// Ensure frame size matches regions size if expansion is on.
|
||||||
let target = regions.expand.select(regions.first, frame.size());
|
let target = regions.expand.select(regions.first, frame.size());
|
||||||
@ -97,7 +97,7 @@ impl Layout for BlockNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
self.0.layout(vt, styles, regions)
|
self.0.layout(vt, styles, regions)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ impl Layout for FlowNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut layouter = FlowLayouter::new(regions, self.1);
|
let mut layouter = FlowLayouter::new(regions, self.1);
|
||||||
|
|
||||||
@ -55,11 +55,11 @@ impl Debug for FlowNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Performs flow layout.
|
/// Performs flow layout.
|
||||||
struct FlowLayouter {
|
struct FlowLayouter<'a> {
|
||||||
/// Whether this is a root page-level flow.
|
/// Whether this is a root page-level flow.
|
||||||
root: bool,
|
root: bool,
|
||||||
/// The regions to layout children into.
|
/// The regions to layout children into.
|
||||||
regions: Regions,
|
regions: Regions<'a>,
|
||||||
/// Whether the flow should expand to fill the region.
|
/// Whether the flow should expand to fill the region.
|
||||||
expand: Axes<bool>,
|
expand: Axes<bool>,
|
||||||
/// The full size of `regions.size` that was available before we started
|
/// The full size of `regions.size` that was available before we started
|
||||||
@ -88,14 +88,13 @@ enum FlowItem {
|
|||||||
Placed(Frame),
|
Placed(Frame),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlowLayouter {
|
impl<'a> FlowLayouter<'a> {
|
||||||
/// Create a new flow layouter.
|
/// Create a new flow layouter.
|
||||||
fn new(regions: &Regions, root: bool) -> Self {
|
fn new(mut regions: Regions<'a>, root: bool) -> Self {
|
||||||
let expand = regions.expand;
|
let expand = regions.expand;
|
||||||
let full = regions.first;
|
let full = regions.first;
|
||||||
|
|
||||||
// Disable vertical expansion for children.
|
// Disable vertical expansion for children.
|
||||||
let mut regions = regions.clone();
|
|
||||||
regions.expand.y = false;
|
regions.expand.y = false;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -166,7 +165,7 @@ impl FlowLayouter {
|
|||||||
// aligned later.
|
// aligned later.
|
||||||
if let Some(placed) = block.to::<PlaceNode>() {
|
if let Some(placed) = block.to::<PlaceNode>() {
|
||||||
if placed.out_of_flow() {
|
if placed.out_of_flow() {
|
||||||
let frame = block.layout(vt, styles, &self.regions)?.into_frame();
|
let frame = block.layout(vt, styles, self.regions)?.into_frame();
|
||||||
self.layout_item(FlowItem::Placed(frame));
|
self.layout_item(FlowItem::Placed(frame));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -187,7 +186,7 @@ impl FlowLayouter {
|
|||||||
|
|
||||||
// Layout the block itself.
|
// Layout the block itself.
|
||||||
let sticky = styles.get(BlockNode::STICKY);
|
let sticky = styles.get(BlockNode::STICKY);
|
||||||
let fragment = block.layout(vt, styles, &self.regions)?;
|
let fragment = block.layout(vt, styles, self.regions)?;
|
||||||
for frame in fragment {
|
for frame in fragment {
|
||||||
self.layout_item(FlowItem::Frame(frame, aligns, sticky));
|
self.layout_item(FlowItem::Frame(frame, aligns, sticky));
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ impl Layout for GridNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
// Prepare grid layout by unifying content and gutter tracks.
|
// Prepare grid layout by unifying content and gutter tracks.
|
||||||
let layouter = GridLayouter::new(
|
let layouter = GridLayouter::new(
|
||||||
@ -120,7 +120,7 @@ struct GridLayouter<'a, 'v> {
|
|||||||
/// The row tracks including gutter tracks.
|
/// The row tracks including gutter tracks.
|
||||||
rows: Vec<TrackSizing>,
|
rows: Vec<TrackSizing>,
|
||||||
/// The regions to layout children into.
|
/// The regions to layout children into.
|
||||||
regions: Regions,
|
regions: Regions<'a>,
|
||||||
/// The inherited styles.
|
/// The inherited styles.
|
||||||
styles: StyleChain<'a>,
|
styles: StyleChain<'a>,
|
||||||
/// Resolved column sizes.
|
/// Resolved column sizes.
|
||||||
@ -156,7 +156,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
tracks: Axes<&[TrackSizing]>,
|
tracks: Axes<&[TrackSizing]>,
|
||||||
gutter: Axes<&[TrackSizing]>,
|
gutter: Axes<&[TrackSizing]>,
|
||||||
cells: &'a [Content],
|
cells: &'a [Content],
|
||||||
regions: &Regions,
|
regions: Regions<'a>,
|
||||||
styles: StyleChain<'a>,
|
styles: StyleChain<'a>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut cols = vec![];
|
let mut cols = vec![];
|
||||||
@ -318,7 +318,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
v.resolve(self.styles).relative_to(self.regions.base.y);
|
v.resolve(self.styles).relative_to(self.regions.base.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
let frame = cell.layout(self.vt, self.styles, &pod)?.into_frame();
|
let frame = cell.layout(self.vt, self.styles, pod)?.into_frame();
|
||||||
resolved.set_max(frame.width());
|
resolved.set_max(frame.width());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,7 +395,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut sizes = cell
|
let mut sizes = cell
|
||||||
.layout(self.vt, self.styles, &pod)?
|
.layout(self.vt, self.styles, pod)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|frame| frame.height());
|
.map(|frame| frame.height());
|
||||||
|
|
||||||
@ -483,7 +483,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
.select(self.regions.base, size);
|
.select(self.regions.base, size);
|
||||||
|
|
||||||
let pod = Regions::one(size, base, Axes::splat(true));
|
let pod = Regions::one(size, base, Axes::splat(true));
|
||||||
let frame = cell.layout(self.vt, self.styles, &pod)?.into_frame();
|
let frame = cell.layout(self.vt, self.styles, pod)?.into_frame();
|
||||||
output.push_frame(pos, frame);
|
output.push_frame(pos, frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +504,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
// Prepare regions.
|
// Prepare regions.
|
||||||
let size = Size::new(self.used.x, heights[0]);
|
let size = Size::new(self.used.x, heights[0]);
|
||||||
let mut pod = Regions::one(size, self.regions.base, Axes::splat(true));
|
let mut pod = Regions::one(size, self.regions.base, Axes::splat(true));
|
||||||
pod.backlog = heights[1..].to_vec();
|
pod.backlog = &heights[1..];
|
||||||
|
|
||||||
// Layout the row.
|
// Layout the row.
|
||||||
let mut pos = Point::zero();
|
let mut pos = Point::zero();
|
||||||
@ -519,7 +519,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Push the layouted frames into the individual output frames.
|
// Push the layouted frames into the individual output frames.
|
||||||
let fragment = cell.layout(self.vt, self.styles, &pod)?;
|
let fragment = cell.layout(self.vt, self.styles, pod)?;
|
||||||
for (output, frame) in outputs.iter_mut().zip(fragment) {
|
for (output, frame) in outputs.iter_mut().zip(fragment) {
|
||||||
output.push_frame(pos, frame);
|
output.push_frame(pos, frame);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ impl Layout for HideNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut fragment = self.0.layout(vt, styles, regions)?;
|
let mut fragment = self.0.layout(vt, styles, regions)?;
|
||||||
for frame in &mut fragment {
|
for frame in &mut fragment {
|
||||||
|
@ -90,7 +90,7 @@ pub trait Layout {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment>;
|
) -> SourceResult<Fragment>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ impl Layout for Content {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
#[comemo::memoize]
|
#[comemo::memoize]
|
||||||
fn cached(
|
fn cached(
|
||||||
@ -108,7 +108,7 @@ impl Layout for Content {
|
|||||||
provider: TrackedMut<StabilityProvider>,
|
provider: TrackedMut<StabilityProvider>,
|
||||||
introspector: Tracked<Introspector>,
|
introspector: Tracked<Introspector>,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut vt = Vt { world, provider, introspector };
|
let mut vt = Vt { world, provider, introspector };
|
||||||
let scratch = Scratch::default();
|
let scratch = Scratch::default();
|
||||||
@ -137,14 +137,14 @@ impl Layout for Content {
|
|||||||
pub trait Inline: Layout {}
|
pub trait Inline: Layout {}
|
||||||
|
|
||||||
/// A sequence of regions to layout into.
|
/// A sequence of regions to layout into.
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Copy, Clone, Hash)]
|
||||||
pub struct Regions {
|
pub struct Regions<'a> {
|
||||||
/// The (remaining) size of the first region.
|
/// The (remaining) size of the first region.
|
||||||
pub first: Size,
|
pub first: Size,
|
||||||
/// The base size for relative sizing.
|
/// The base size for relative sizing.
|
||||||
pub base: Size,
|
pub base: Size,
|
||||||
/// The height of followup regions. The width is the same for all regions.
|
/// The height of followup regions. The width is the same for all regions.
|
||||||
pub backlog: Vec<Abs>,
|
pub backlog: &'a [Abs],
|
||||||
/// The height of the final region that is repeated once the backlog is
|
/// The height of the final region that is repeated once the backlog is
|
||||||
/// drained. The width is the same for all regions.
|
/// drained. The width is the same for all regions.
|
||||||
pub last: Option<Abs>,
|
pub last: Option<Abs>,
|
||||||
@ -153,13 +153,13 @@ pub struct Regions {
|
|||||||
pub expand: Axes<bool>,
|
pub expand: Axes<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Regions {
|
impl<'a> Regions<'a> {
|
||||||
/// Create a new region sequence with exactly one region.
|
/// Create a new region sequence with exactly one region.
|
||||||
pub fn one(size: Size, base: Size, expand: Axes<bool>) -> Self {
|
pub fn one(size: Size, base: Size, expand: Axes<bool>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
first: size,
|
first: size,
|
||||||
base,
|
base,
|
||||||
backlog: vec![],
|
backlog: &[],
|
||||||
last: None,
|
last: None,
|
||||||
expand,
|
expand,
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ impl Regions {
|
|||||||
Self {
|
Self {
|
||||||
first: size,
|
first: size,
|
||||||
base,
|
base,
|
||||||
backlog: vec![],
|
backlog: &[],
|
||||||
last: Some(size.y),
|
last: Some(size.y),
|
||||||
expand,
|
expand,
|
||||||
}
|
}
|
||||||
@ -180,15 +180,17 @@ impl Regions {
|
|||||||
///
|
///
|
||||||
/// Note that since all regions must have the same width, the width returned
|
/// Note that since all regions must have the same width, the width returned
|
||||||
/// by `f` is ignored for the backlog and the final region.
|
/// by `f` is ignored for the backlog and the final region.
|
||||||
pub fn map<F>(&self, mut f: F) -> Self
|
pub fn map<'v, F>(&self, backlog: &'v mut Vec<Abs>, mut f: F) -> Regions<'v>
|
||||||
where
|
where
|
||||||
F: FnMut(Size) -> Size,
|
F: FnMut(Size) -> Size,
|
||||||
{
|
{
|
||||||
let x = self.first.x;
|
let x = self.first.x;
|
||||||
Self {
|
backlog.clear();
|
||||||
|
backlog.extend(self.backlog.iter().map(|&y| f(Size::new(x, y)).y));
|
||||||
|
Regions {
|
||||||
first: f(self.first),
|
first: f(self.first),
|
||||||
base: f(self.base),
|
base: f(self.base),
|
||||||
backlog: self.backlog.iter().map(|&y| f(Size::new(x, y)).y).collect(),
|
backlog,
|
||||||
last: self.last.map(|y| f(Size::new(x, y)).y),
|
last: self.last.map(|y| f(Size::new(x, y)).y),
|
||||||
expand: self.expand,
|
expand: self.expand,
|
||||||
}
|
}
|
||||||
@ -208,8 +210,13 @@ impl Regions {
|
|||||||
|
|
||||||
/// Advance to the next region if there is any.
|
/// Advance to the next region if there is any.
|
||||||
pub fn next(&mut self) {
|
pub fn next(&mut self) {
|
||||||
if let Some(height) = (!self.backlog.is_empty())
|
if let Some(height) = self
|
||||||
.then(|| self.backlog.remove(0))
|
.backlog
|
||||||
|
.split_first()
|
||||||
|
.map(|(first, tail)| {
|
||||||
|
self.backlog = tail;
|
||||||
|
*first
|
||||||
|
})
|
||||||
.or(self.last)
|
.or(self.last)
|
||||||
{
|
{
|
||||||
self.first.y = height;
|
self.first.y = height;
|
||||||
|
@ -30,12 +30,14 @@ impl Layout for PadNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
|
let mut backlog = vec![];
|
||||||
|
|
||||||
// Layout child into padded regions.
|
// Layout child into padded regions.
|
||||||
let padding = self.padding.resolve(styles);
|
let padding = self.padding.resolve(styles);
|
||||||
let pod = regions.map(|size| shrink(size, padding));
|
let pod = regions.map(&mut backlog, |size| shrink(size, padding));
|
||||||
let mut fragment = self.child.layout(vt, styles, &pod)?;
|
let mut fragment = self.child.layout(vt, styles, pod)?;
|
||||||
|
|
||||||
for frame in &mut fragment {
|
for frame in &mut fragment {
|
||||||
// Apply the padding inversely such that the grown size padded
|
// Apply the padding inversely such that the grown size padded
|
||||||
|
@ -97,7 +97,7 @@ impl PageNode {
|
|||||||
|
|
||||||
// Layout the child.
|
// Layout the child.
|
||||||
let regions = Regions::repeat(size, size, size.map(Abs::is_finite));
|
let regions = Regions::repeat(size, size, size.map(Abs::is_finite));
|
||||||
let mut fragment = child.layout(vt, styles, ®ions)?;
|
let mut fragment = child.layout(vt, styles, regions)?;
|
||||||
|
|
||||||
let header = styles.get(Self::HEADER);
|
let header = styles.get(Self::HEADER);
|
||||||
let footer = styles.get(Self::FOOTER);
|
let footer = styles.get(Self::FOOTER);
|
||||||
@ -118,7 +118,7 @@ impl PageNode {
|
|||||||
] {
|
] {
|
||||||
if let Some(content) = marginal.resolve(vt, page)? {
|
if let Some(content) = marginal.resolve(vt, page)? {
|
||||||
let pod = Regions::one(area, area, Axes::splat(true));
|
let pod = Regions::one(area, area, Axes::splat(true));
|
||||||
let sub = content.layout(vt, styles, &pod)?.into_frame();
|
let sub = content.layout(vt, styles, pod)?.into_frame();
|
||||||
if std::ptr::eq(marginal, background) {
|
if std::ptr::eq(marginal, background) {
|
||||||
frame.prepend_frame(pos, sub);
|
frame.prepend_frame(pos, sub);
|
||||||
} else {
|
} else {
|
||||||
|
@ -538,7 +538,7 @@ fn prepare<'a>(
|
|||||||
} else {
|
} else {
|
||||||
let size = Size::new(width, base.y);
|
let size = Size::new(width, base.y);
|
||||||
let pod = Regions::one(size, base, Axes::splat(false));
|
let pod = Regions::one(size, base, Axes::splat(false));
|
||||||
let mut frame = inline.layout(vt, styles, &pod)?.into_frame();
|
let mut frame = inline.layout(vt, styles, pod)?.into_frame();
|
||||||
frame.translate(Point::with_y(styles.get(TextNode::BASELINE)));
|
frame.translate(Point::with_y(styles.get(TextNode::BASELINE)));
|
||||||
items.push(Item::Frame(frame));
|
items.push(Item::Frame(frame));
|
||||||
}
|
}
|
||||||
@ -1125,7 +1125,7 @@ fn commit(
|
|||||||
let fill = Fr::one().share(fr, remaining);
|
let fill = Fr::one().share(fr, remaining);
|
||||||
let size = Size::new(fill, base.y);
|
let size = Size::new(fill, base.y);
|
||||||
let pod = Regions::one(size, base, Axes::new(false, false));
|
let pod = Regions::one(size, base, Axes::new(false, false));
|
||||||
let frame = repeat.layout(vt, *styles, &pod)?.into_frame();
|
let frame = repeat.layout(vt, *styles, pod)?.into_frame();
|
||||||
let width = frame.width();
|
let width = frame.width();
|
||||||
let count = (fill / width).floor();
|
let count = (fill / width).floor();
|
||||||
let remaining = fill % width;
|
let remaining = fill % width;
|
||||||
|
@ -21,7 +21,7 @@ impl Layout for PlaceNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let out_of_flow = self.out_of_flow();
|
let out_of_flow = self.out_of_flow();
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ impl Layout for PlaceNode {
|
|||||||
Regions::one(regions.base, regions.base, expand)
|
Regions::one(regions.base, regions.base, expand)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut frame = self.0.layout(vt, styles, &pod)?.into_frame();
|
let mut frame = self.0.layout(vt, styles, pod)?.into_frame();
|
||||||
|
|
||||||
// If expansion is off, zero all sizes so that we don't take up any
|
// If expansion is off, zero all sizes so that we don't take up any
|
||||||
// space in our parent. Otherwise, respect the expand settings.
|
// space in our parent. Otherwise, respect the expand settings.
|
||||||
|
@ -16,7 +16,7 @@ impl Layout for RepeatNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
self.0.layout(vt, styles, regions)
|
self.0.layout(vt, styles, regions)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ impl Layout for StackNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut layouter = StackLayouter::new(self.dir, regions, styles);
|
let mut layouter = StackLayouter::new(self.dir, regions, styles);
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ struct StackLayouter<'a> {
|
|||||||
/// The axis of the stacking direction.
|
/// The axis of the stacking direction.
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
/// The regions to layout children into.
|
/// The regions to layout children into.
|
||||||
regions: Regions,
|
regions: Regions<'a>,
|
||||||
/// The inherited styles.
|
/// The inherited styles.
|
||||||
styles: StyleChain<'a>,
|
styles: StyleChain<'a>,
|
||||||
/// Whether the stack itself should expand to fill the region.
|
/// Whether the stack itself should expand to fill the region.
|
||||||
@ -124,7 +124,7 @@ enum StackItem {
|
|||||||
|
|
||||||
impl<'a> StackLayouter<'a> {
|
impl<'a> StackLayouter<'a> {
|
||||||
/// Create a new stack layouter.
|
/// Create a new stack layouter.
|
||||||
fn new(dir: Dir, regions: &Regions, styles: StyleChain<'a>) -> Self {
|
fn new(dir: Dir, regions: Regions<'a>, styles: StyleChain<'a>) -> Self {
|
||||||
let axis = dir.axis();
|
let axis = dir.axis();
|
||||||
let expand = regions.expand;
|
let expand = regions.expand;
|
||||||
let full = regions.first;
|
let full = regions.first;
|
||||||
@ -195,7 +195,7 @@ impl<'a> StackLayouter<'a> {
|
|||||||
self.dir.start().into()
|
self.dir.start().into()
|
||||||
});
|
});
|
||||||
|
|
||||||
let fragment = block.layout(vt, styles, &self.regions)?;
|
let fragment = block.layout(vt, styles, self.regions)?;
|
||||||
let len = fragment.len();
|
let len = fragment.len();
|
||||||
for (i, frame) in fragment.into_iter().enumerate() {
|
for (i, frame) in fragment.into_iter().enumerate() {
|
||||||
// Grow our size, shrink the region and save the frame for later.
|
// Grow our size, shrink the region and save the frame for later.
|
||||||
|
@ -29,7 +29,7 @@ impl Layout for MoveNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut fragment = self.child.layout(vt, styles, regions)?;
|
let mut fragment = self.child.layout(vt, styles, regions)?;
|
||||||
for frame in &mut fragment {
|
for frame in &mut fragment {
|
||||||
@ -87,7 +87,7 @@ impl<const T: TransformKind> Layout for TransformNode<T> {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut fragment = self.child.layout(vt, styles, regions)?;
|
let mut fragment = self.child.layout(vt, styles, regions)?;
|
||||||
for frame in &mut fragment {
|
for frame in &mut fragment {
|
||||||
|
@ -57,7 +57,7 @@ impl Layout for MathNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
_: &Regions,
|
_: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut t = Texifier::new(styles);
|
let mut t = Texifier::new(styles);
|
||||||
self.texify(&mut t)?;
|
self.texify(&mut t)?;
|
||||||
|
@ -114,7 +114,7 @@ impl Layout for FillNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut fragment = self.child.layout(vt, styles, regions)?;
|
let mut fragment = self.child.layout(vt, styles, regions)?;
|
||||||
for frame in &mut fragment {
|
for frame in &mut fragment {
|
||||||
@ -142,7 +142,7 @@ impl Layout for StrokeNode {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut fragment = self.child.layout(vt, styles, regions)?;
|
let mut fragment = self.child.layout(vt, styles, regions)?;
|
||||||
for frame in &mut fragment {
|
for frame in &mut fragment {
|
||||||
|
@ -41,14 +41,14 @@ impl Layout for ImageNode {
|
|||||||
&self,
|
&self,
|
||||||
_: &mut Vt,
|
_: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let pxw = self.0.width() as f64;
|
let pxw = self.0.width() as f64;
|
||||||
let pxh = self.0.height() as f64;
|
let pxh = self.0.height() as f64;
|
||||||
let px_ratio = pxw / pxh;
|
let px_ratio = pxw / pxh;
|
||||||
|
|
||||||
// Find out whether the image is wider or taller than the target size.
|
// Find out whether the image is wider or taller than the target size.
|
||||||
let &Regions { first, expand, .. } = regions;
|
let Regions { first, expand, .. } = regions;
|
||||||
let region_ratio = first.x / first.y;
|
let region_ratio = first.x / first.y;
|
||||||
let wide = px_ratio > region_ratio;
|
let wide = px_ratio > region_ratio;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ impl Layout for LineNode {
|
|||||||
&self,
|
&self,
|
||||||
_: &mut Vt,
|
_: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let stroke = styles.get(Self::STROKE).unwrap_or_default();
|
let stroke = styles.get(Self::STROKE).unwrap_or_default();
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
|
|||||||
&self,
|
&self,
|
||||||
vt: &mut Vt,
|
vt: &mut Vt,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: &Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Fragment> {
|
||||||
let mut frame;
|
let mut frame;
|
||||||
if let Some(child) = &self.0 {
|
if let Some(child) = &self.0 {
|
||||||
@ -89,7 +89,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
|
|||||||
let child = child.clone().padded(inset.map(|side| side.map(Length::from)));
|
let child = child.clone().padded(inset.map(|side| side.map(Length::from)));
|
||||||
|
|
||||||
let mut pod = Regions::one(regions.first, regions.base, regions.expand);
|
let mut pod = Regions::one(regions.first, regions.base, regions.expand);
|
||||||
frame = child.layout(vt, styles, &pod)?.into_frame();
|
frame = child.layout(vt, styles, pod)?.into_frame();
|
||||||
|
|
||||||
// Relayout with full expansion into square region to make sure
|
// Relayout with full expansion into square region to make sure
|
||||||
// the result is really a square or circle.
|
// the result is really a square or circle.
|
||||||
@ -105,7 +105,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
|
|||||||
|
|
||||||
pod.first = Size::splat(length);
|
pod.first = Size::splat(length);
|
||||||
pod.expand = Axes::splat(true);
|
pod.expand = Axes::splat(true);
|
||||||
frame = child.layout(vt, styles, &pod)?.into_frame();
|
frame = child.layout(vt, styles, pod)?.into_frame();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The default size that a shape takes on if it has no child and
|
// The default size that a shape takes on if it has no child and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user