diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-12-15 12:49:20 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-12-15 12:49:20 +0100 |
| commit | 244ad386ec271ff86a2101eb4cc38d37a55552b9 (patch) | |
| tree | a22dbbdb3f8a39c9c5a3ff347afbaf5708acec6b /src/library | |
| parent | 57f5c0a1b15775f9500335f455c7dc7d70cea9f5 (diff) | |
Set Rules Episode VI: Return of the Refactor
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/flow.rs | 32 | ||||
| -rw-r--r-- | src/library/page.rs | 6 | ||||
| -rw-r--r-- | src/library/placed.rs | 7 |
3 files changed, 19 insertions, 26 deletions
diff --git a/src/library/flow.rs b/src/library/flow.rs index eaa1811c..de6ab812 100644 --- a/src/library/flow.rs +++ b/src/library/flow.rs @@ -30,30 +30,30 @@ impl Debug for FlowNode { /// A child of a flow node. #[derive(Hash)] pub enum FlowChild { + /// A paragraph/block break. + Break(Styles), /// Vertical spacing between other children. Spacing(SpacingNode), /// An arbitrary node. Node(PackedNode), - /// A paragraph break. - Parbreak(Styles), } impl FlowChild { /// A reference to the child's styles. pub fn styles(&self) -> &Styles { match self { + Self::Break(styles) => styles, Self::Spacing(node) => &node.styles, Self::Node(node) => &node.styles, - Self::Parbreak(styles) => styles, } } /// A mutable reference to the child's styles. pub fn styles_mut(&mut self) -> &mut Styles { match self { + Self::Break(styles) => styles, Self::Spacing(node) => &mut node.styles, Self::Node(node) => &mut node.styles, - Self::Parbreak(styles) => styles, } } } @@ -61,14 +61,14 @@ impl FlowChild { impl Debug for FlowChild { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { - Self::Spacing(node) => node.fmt(f), - Self::Node(node) => node.fmt(f), - Self::Parbreak(styles) => { + Self::Break(styles) => { if f.alternate() { styles.fmt(f)?; } - write!(f, "Parbreak") + write!(f, "Break") } + Self::Spacing(node) => node.fmt(f), + Self::Node(node) => node.fmt(f), } } } @@ -132,6 +132,13 @@ impl<'a> FlowLayouter<'a> { fn layout(mut self, ctx: &mut LayoutContext) -> Vec<Constrained<Rc<Frame>>> { for child in self.children { match child { + FlowChild::Break(styles) => { + let chain = styles.chain(&ctx.styles); + let amount = chain + .get(ParNode::SPACING) + .resolve(chain.get(TextNode::SIZE).abs); + self.layout_absolute(amount.into()); + } FlowChild::Spacing(node) => match node.kind { SpacingKind::Linear(v) => self.layout_absolute(v), SpacingKind::Fractional(v) => { @@ -146,13 +153,6 @@ impl<'a> FlowLayouter<'a> { self.layout_node(ctx, node); } - FlowChild::Parbreak(styles) => { - let chain = styles.chain(&ctx.styles); - let amount = chain - .get(ParNode::SPACING) - .resolve(chain.get(TextNode::SIZE).abs); - self.layout_absolute(amount.into()); - } } } @@ -248,7 +248,7 @@ impl<'a> FlowLayouter<'a> { output.push_frame(pos, frame); } FlowItem::Placed(frame) => { - output.push_frame(Point::with_y(offset), frame); + output.push_frame(Point::zero(), frame); } } } diff --git a/src/library/page.rs b/src/library/page.rs index 8905ffb6..4a4fab03 100644 --- a/src/library/page.rs +++ b/src/library/page.rs @@ -62,7 +62,7 @@ pub fn pagebreak(_: &mut EvalContext, _: &mut Args) -> TypResult<Value> { #[derive(Hash)] pub struct PageNode { /// The node producing the content. - pub node: PackedNode, + pub child: PackedNode, /// The page's styles. pub styles: Styles, } @@ -116,7 +116,7 @@ impl PageNode { }; // Pad the child. - let padded = PadNode { child: self.node.clone(), padding }.pack(); + let padded = PadNode { child: self.child.clone(), padding }.pack(); // Layout the child. let expand = size.map(Length::is_finite); @@ -143,7 +143,7 @@ impl Debug for PageNode { self.styles.fmt(f)?; } f.write_str("Page(")?; - self.node.fmt(f)?; + self.child.fmt(f)?; f.write_str(")") } } diff --git a/src/library/placed.rs b/src/library/placed.rs index 3e2e1b26..589a299b 100644 --- a/src/library/placed.rs +++ b/src/library/placed.rs @@ -51,13 +51,6 @@ impl Layout for PlacedNode { let target = regions.expand.select(regions.current, Size::zero()); Rc::make_mut(frame).resize(target, Align::LEFT_TOP); - // Place relative to parent's base origin by offsetting our elements by - // the negative cursor position. - if out_of_flow { - let offset = (regions.current - regions.base).to_point(); - Rc::make_mut(frame).translate(offset); - } - // Set base constraint because our pod size is base and exact // constraints if we needed to expand or offset. *cts = Constraints::new(regions.expand); |
