diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-25 10:36:31 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-25 12:16:13 +0100 |
| commit | bf5edbbbbb75120d065d1c9587ccfa4eed4fdca1 (patch) | |
| tree | 956af910ab27a8cec0db83171cd3f0b6d0570a60 /library/src/layout | |
| parent | 96f72eee6c6b595164c7a0576c407d7a590661db (diff) | |
Tidy up
Diffstat (limited to 'library/src/layout')
| -rw-r--r-- | library/src/layout/align.rs | 8 | ||||
| -rw-r--r-- | library/src/layout/columns.rs | 6 | ||||
| -rw-r--r-- | library/src/layout/container.rs | 8 | ||||
| -rw-r--r-- | library/src/layout/flow.rs | 10 | ||||
| -rw-r--r-- | library/src/layout/grid.rs | 10 | ||||
| -rw-r--r-- | library/src/layout/mod.rs | 32 | ||||
| -rw-r--r-- | library/src/layout/pad.rs | 4 | ||||
| -rw-r--r-- | library/src/layout/page.rs | 12 | ||||
| -rw-r--r-- | library/src/layout/place.rs | 4 | ||||
| -rw-r--r-- | library/src/layout/stack.rs | 6 | ||||
| -rw-r--r-- | library/src/layout/transform.rs | 8 |
11 files changed, 54 insertions, 54 deletions
diff --git a/library/src/layout/align.rs b/library/src/layout/align.rs index 6337c941..10a4a2ed 100644 --- a/library/src/layout/align.rs +++ b/library/src/layout/align.rs @@ -30,21 +30,21 @@ impl LayoutBlock for AlignNode { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { // The child only needs to expand along an axis if there's no alignment. let mut pod = regions.clone(); pod.expand &= self.aligns.as_ref().map(Option::is_none); // Align paragraphs inside the child. - let mut passed = StyleMap::new(); + let mut map = StyleMap::new(); if let Some(align) = self.aligns.x { - passed.set(ParNode::ALIGN, HorizontalAlign(align)); + map.set(ParNode::ALIGN, HorizontalAlign(align)); } // Layout the child. - let mut frames = self.child.layout_block(world, &pod, passed.chain(&styles))?; + let mut frames = self.child.layout_block(world, styles.chain(&map), &pod)?; for (region, frame) in regions.iter().zip(&mut frames) { // Align in the target size. The target size depends on whether we // should expand. diff --git a/library/src/layout/columns.rs b/library/src/layout/columns.rs index 6e1aaeae..b18ba49f 100644 --- a/library/src/layout/columns.rs +++ b/library/src/layout/columns.rs @@ -30,13 +30,13 @@ impl LayoutBlock for ColumnsNode { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { // Separating the infinite space into infinite columns does not make // much sense. if !regions.first.x.is_finite() { - return self.child.layout_block(world, regions, styles); + return self.child.layout_block(world, styles, regions); } // Determine the width of the gutter and each column. @@ -58,7 +58,7 @@ impl LayoutBlock for ColumnsNode { }; // Layout the children. - let mut frames = self.child.layout_block(world, &pod, styles)?.into_iter(); + let mut frames = self.child.layout_block(world, styles, &pod)?.into_iter(); let mut finished = vec![]; let dir = styles.get(TextNode::DIR); diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index 9a6ccb9f..b299c0fc 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -24,8 +24,8 @@ impl LayoutInline for BoxNode { fn layout_inline( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Frame> { // The "pod" is the region into which the child will be layouted. let pod = { @@ -47,7 +47,7 @@ impl LayoutInline for BoxNode { }; // Layout the child. - let mut frame = self.child.layout_inline(world, &pod, styles)?; + let mut frame = self.child.layout_inline(world, styles, &pod)?; // Ensure frame size matches regions size if expansion is on. let target = regions.expand.select(regions.first, frame.size()); @@ -91,9 +91,9 @@ impl LayoutBlock for BlockNode { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { - self.0.layout_block(world, regions, styles) + self.0.layout_block(world, styles, regions) } } diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs index 4508023a..3338da09 100644 --- a/library/src/layout/flow.rs +++ b/library/src/layout/flow.rs @@ -18,13 +18,13 @@ impl LayoutBlock for FlowNode { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { let mut layouter = FlowLayouter::new(regions); for (child, map) in self.0.iter() { - let styles = map.chain(&styles); + let styles = styles.chain(&map); if let Some(&node) = child.to::<VNode>() { layouter.layout_spacing(node.amount, styles); } else if child.has::<dyn LayoutBlock>() { @@ -136,7 +136,7 @@ impl FlowLayouter { // aligned later. if let Some(placed) = block.to::<PlaceNode>() { if placed.out_of_flow() { - let frame = block.layout_block(world, &self.regions, styles)?.remove(0); + let frame = block.layout_block(world, styles, &self.regions)?.remove(0); self.items.push(FlowItem::Placed(frame)); return Ok(()); } @@ -162,11 +162,11 @@ impl FlowLayouter { if !self.last_block_was_par && is_par && !styles.get(ParNode::INDENT).is_zero() { let property = Property::new(ParNode::INDENT, Length::zero()); reset = Style::Property(property); - chained = reset.chain(&styles); + chained = styles.chain_one(&reset); } // Layout the block itself. - let frames = block.layout_block(world, &self.regions, chained)?; + let frames = block.layout_block(world, chained, &self.regions)?; let len = frames.len(); for (i, frame) in frames.into_iter().enumerate() { // Grow our size, shrink the region and save the frame for later. diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs index 3b5afcc5..4cbef421 100644 --- a/library/src/layout/grid.rs +++ b/library/src/layout/grid.rs @@ -37,8 +37,8 @@ impl LayoutBlock for GridNode { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { // Prepare grid layout by unifying content and gutter tracks. let layouter = GridLayouter::new( @@ -321,7 +321,7 @@ impl<'a> GridLayouter<'a> { } let frame = - cell.layout_block(self.world, &pod, self.styles)?.remove(0); + cell.layout_block(self.world, self.styles, &pod)?.remove(0); resolved.set_max(frame.width()); } } @@ -391,7 +391,7 @@ impl<'a> GridLayouter<'a> { } let mut sizes = cell - .layout_block(self.world, &pod, self.styles)? + .layout_block(self.world, self.styles, &pod)? .into_iter() .map(|frame| frame.height()); @@ -480,7 +480,7 @@ impl<'a> GridLayouter<'a> { .select(self.regions.base, size); let pod = Regions::one(size, base, Axes::splat(true)); - let frame = cell.layout_block(self.world, &pod, self.styles)?.remove(0); + let frame = cell.layout_block(self.world, self.styles, &pod)?.remove(0); output.push_frame(pos, frame); } @@ -520,7 +520,7 @@ impl<'a> GridLayouter<'a> { } // Push the layouted frames into the individual output frames. - let frames = cell.layout_block(self.world, &pod, self.styles)?; + let frames = cell.layout_block(self.world, self.styles, &pod)?; for (output, frame) in outputs.iter_mut().zip(frames) { output.push_frame(pos, frame); } diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index 983b96ba..44b7b6d8 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -32,8 +32,8 @@ use typst::diag::SourceResult; use typst::frame::Frame; use typst::geom::*; use typst::model::{ - capability, Content, Node, SequenceNode, Style, StyleChain, StyleVecBuilder, - StyledNode, + applicable, capability, realize, Content, Node, SequenceNode, Style, StyleChain, + StyleVecBuilder, StyledNode, }; use typst::World; @@ -77,8 +77,8 @@ pub trait LayoutBlock { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>>; } @@ -87,17 +87,17 @@ impl LayoutBlock for Content { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { let scratch = Scratch::default(); let (realized, styles) = realize_block(world, &scratch, self, styles)?; let barrier = Style::Barrier(realized.id()); - let styles = barrier.chain(&styles); + let styles = styles.chain_one(&barrier); realized .with::<dyn LayoutBlock>() .unwrap() - .layout_block(world, regions, styles) + .layout_block(world, styles, regions) } } @@ -108,8 +108,8 @@ pub trait LayoutInline { fn layout_inline( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Frame>; } @@ -118,22 +118,22 @@ impl LayoutInline for Content { fn layout_inline( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Frame> { assert!(regions.backlog.is_empty()); assert!(regions.last.is_none()); - if self.has::<dyn LayoutInline>() && !styles.applicable(self) { + if self.has::<dyn LayoutInline>() && !applicable(self, styles) { let barrier = Style::Barrier(self.id()); - let styles = barrier.chain(&styles); + let styles = styles.chain_one(&barrier); return self .with::<dyn LayoutInline>() .unwrap() - .layout_inline(world, regions, styles); + .layout_inline(world, styles, regions); } - Ok(self.layout_block(world, regions, styles)?.remove(0)) + Ok(self.layout_block(world, styles, regions)?.remove(0)) } } @@ -237,7 +237,7 @@ fn realize_root<'a>( content: &'a Content, styles: StyleChain<'a>, ) -> SourceResult<(Content, StyleChain<'a>)> { - if content.has::<dyn LayoutRoot>() && !styles.applicable(content) { + if content.has::<dyn LayoutRoot>() && !applicable(content, styles) { return Ok((content.clone(), styles)); } @@ -255,7 +255,7 @@ fn realize_block<'a>( content: &'a Content, styles: StyleChain<'a>, ) -> SourceResult<(Content, StyleChain<'a>)> { - if content.has::<dyn LayoutBlock>() && !styles.applicable(content) { + if content.has::<dyn LayoutBlock>() && !applicable(content, styles) { return Ok((content.clone(), styles)); } @@ -319,7 +319,7 @@ impl<'a> Builder<'a> { return Ok(()); } - if let Some(realized) = styles.show(self.world, content)? { + if let Some(realized) = realize(self.world, content, styles)? { let stored = self.scratch.content.alloc(realized); return self.accept(stored, styles); } @@ -366,7 +366,7 @@ impl<'a> Builder<'a> { styles: StyleChain<'a>, ) -> SourceResult<()> { let stored = self.scratch.styles.alloc(styles); - let styles = styled.map.chain(stored); + let styles = stored.chain(&styled.map); self.interrupt_style(&styled.map, None)?; self.accept(&styled.sub, styles)?; self.interrupt_style(&styled.map, Some(styles))?; diff --git a/library/src/layout/pad.rs b/library/src/layout/pad.rs index d860e54d..4389d990 100644 --- a/library/src/layout/pad.rs +++ b/library/src/layout/pad.rs @@ -29,13 +29,13 @@ impl LayoutBlock for PadNode { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { // Layout child into padded regions. let padding = self.padding.resolve(styles); let pod = regions.map(|size| shrink(size, padding)); - let mut frames = self.child.layout_block(world, &pod, styles)?; + let mut frames = self.child.layout_block(world, styles, &pod)?; for frame in &mut frames { // Apply the padding inversely such that the grown size padded diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs index f3249347..9d5d4f56 100644 --- a/library/src/layout/page.rs +++ b/library/src/layout/page.rs @@ -97,7 +97,7 @@ impl PageNode { // Layout the child. let regions = Regions::repeat(size, size, size.map(Abs::is_finite)); - let mut frames = child.layout_block(world, ®ions, styles)?; + let mut frames = child.layout_block(world, styles, ®ions)?; let header = styles.get(Self::HEADER); let footer = styles.get(Self::FOOTER); @@ -118,7 +118,7 @@ impl PageNode { ] { if let Some(content) = marginal.resolve(world, page)? { let pod = Regions::one(area, area, Axes::splat(true)); - let sub = content.layout_block(world, &pod, styles)?.remove(0); + let sub = content.layout_block(world, styles, &pod)?.remove(0); if std::ptr::eq(marginal, background) { frame.prepend_frame(pos, sub); } else { @@ -402,9 +402,9 @@ papers! { // ---------------------------------------------------------------------- // // Other - (NEWSPAPER_COMPACT: 280.0, 430.0, "newspaper-compact") - (NEWSPAPER_BERLINER: 315.0, 470.0, "newspaper-berliner") - (NEWSPAPER_BROADSHEET: 381.0, 578.0, "newspaper-broadsheet") + (NEWSPAPER_COMPACT: 280.0, 430.0, "newspaper-compact") + (NEWSPAPER_BERLINER: 315.0, 470.0, "newspaper-berliner") + (NEWSPAPER_BROADSHEET: 381.0, 578.0, "newspaper-broadsheet") (PRESENTATION_16_9: 297.0, 167.0625, "presentation-16-9") - (PRESENTATION_4_3: 280.0, 210.0, "presentation-4-3") + (PRESENTATION_4_3: 280.0, 210.0, "presentation-4-3") } diff --git a/library/src/layout/place.rs b/library/src/layout/place.rs index 221e9008..af313073 100644 --- a/library/src/layout/place.rs +++ b/library/src/layout/place.rs @@ -20,8 +20,8 @@ impl LayoutBlock for PlaceNode { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { let out_of_flow = self.out_of_flow(); @@ -33,7 +33,7 @@ impl LayoutBlock for PlaceNode { Regions::one(regions.base, regions.base, expand) }; - let mut frames = self.0.layout_block(world, &pod, styles)?; + let mut frames = self.0.layout_block(world, styles, &pod)?; // If expansion is off, zero all sizes so that we don't take up any // space in our parent. Otherwise, respect the expand settings. diff --git a/library/src/layout/stack.rs b/library/src/layout/stack.rs index 52de2c48..c935d971 100644 --- a/library/src/layout/stack.rs +++ b/library/src/layout/stack.rs @@ -31,8 +31,8 @@ impl LayoutBlock for StackNode { fn layout_block( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Vec<Frame>> { let mut layouter = StackLayouter::new(self.dir, regions, styles); @@ -189,14 +189,14 @@ impl<'a> StackLayouter<'a> { if let Some(styled) = block.to::<StyledNode>() { let map = &styled.map; if map.contains(ParNode::ALIGN) { - return StyleChain::with_root(map).get(ParNode::ALIGN); + return StyleChain::new(map).get(ParNode::ALIGN); } } self.dir.start().into() }); - let frames = block.layout_block(world, &self.regions, styles)?; + let frames = block.layout_block(world, styles, &self.regions)?; let len = frames.len(); for (i, frame) in frames.into_iter().enumerate() { // Grow our size, shrink the region and save the frame for later. diff --git a/library/src/layout/transform.rs b/library/src/layout/transform.rs index bee38cb4..f09b4e65 100644 --- a/library/src/layout/transform.rs +++ b/library/src/layout/transform.rs @@ -28,10 +28,10 @@ impl LayoutInline for MoveNode { fn layout_inline( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Frame> { - let mut frame = self.child.layout_inline(world, regions, styles)?; + let mut frame = self.child.layout_inline(world, styles, regions)?; let delta = self.delta.resolve(styles); let delta = delta.zip(frame.size()).map(|(d, s)| d.relative_to(s)); frame.translate(delta.to_point()); @@ -82,10 +82,10 @@ impl<const T: TransformKind> LayoutInline for TransformNode<T> { fn layout_inline( &self, world: Tracked<dyn World>, - regions: &Regions, styles: StyleChain, + regions: &Regions, ) -> SourceResult<Frame> { - let mut frame = self.child.layout_inline(world, regions, styles)?; + let mut frame = self.child.layout_inline(world, styles, regions)?; let origin = styles.get(Self::ORIGIN).unwrap_or(Align::CENTER_HORIZON); let Axes { x, y } = origin.zip(frame.size()).map(|(o, s)| o.position(s)); |
