From a9fdff244aef859449a76e5f762ee7c343a8ddcc Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 10 Mar 2023 20:47:23 +0100 Subject: Expose content representation more --- library/src/layout/align.rs | 2 +- library/src/layout/flow.rs | 10 +++++----- library/src/layout/hide.rs | 2 +- library/src/layout/mod.rs | 26 +++++++++++++------------- library/src/layout/par.rs | 8 +++----- library/src/layout/stack.rs | 2 +- 6 files changed, 24 insertions(+), 26 deletions(-) (limited to 'library/src/layout') diff --git a/library/src/layout/align.rs b/library/src/layout/align.rs index cf6d08f2..2a3998bf 100644 --- a/library/src/layout/align.rs +++ b/library/src/layout/align.rs @@ -58,7 +58,7 @@ pub struct AlignNode { } impl Show for AlignNode { - fn show(&self, _: &mut Vt, _: &Content, styles: StyleChain) -> SourceResult { + fn show(&self, _: &mut Vt, styles: StyleChain) -> SourceResult { Ok(self .body() .styled(Self::set_alignment(self.alignment(styles).map(Some)))) diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs index 7a063bce..2671b983 100644 --- a/library/src/layout/flow.rs +++ b/library/src/layout/flow.rs @@ -32,7 +32,7 @@ impl Layout for FlowNode { let outer = styles; let mut styles = outer; if let Some(node) = child.to::() { - map = node.map(); + map = node.styles(); styles = outer.chain(&map); child = node.body(); } @@ -48,15 +48,15 @@ impl Layout for FlowNode { || child.is::() { layouter.layout_single(vt, &child, styles)?; - } else if child.has::() { + } else if child.can::() { layouter.layout_multiple(vt, &child, styles)?; } else if child.is::() { if !layouter.regions.backlog.is_empty() || layouter.regions.last.is_some() { layouter.finish_region(); } - } else if let Some(span) = child.span() { - bail!(span, "unexpected flow child"); + } else { + bail!(child.span(), "unexpected flow child"); } } @@ -207,7 +207,7 @@ impl<'a> FlowLayouter<'a> { let aligns = if let Some(align) = block.to::() { align.alignment(styles) } else if let Some(styled) = block.to::() { - AlignNode::alignment_in(styles.chain(&styled.map())) + AlignNode::alignment_in(styles.chain(&styled.styles())) } else { AlignNode::alignment_in(styles) } diff --git a/library/src/layout/hide.rs b/library/src/layout/hide.rs index 62628445..e939e6c3 100644 --- a/library/src/layout/hide.rs +++ b/library/src/layout/hide.rs @@ -23,7 +23,7 @@ pub struct HideNode { } impl Show for HideNode { - fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult { + fn show(&self, _: &mut Vt, _: StyleChain) -> SourceResult { Ok(self.body().styled(MetaNode::set_data(vec![Meta::Hidden]))) } } diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index e846f6f0..dc373ff5 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -148,7 +148,7 @@ fn realize_root<'a>( content: &'a Content, styles: StyleChain<'a>, ) -> SourceResult<(Content, StyleChain<'a>)> { - if content.has::() && !applicable(content, styles) { + if content.can::() && !applicable(content, styles) { return Ok((content.clone(), styles)); } @@ -166,7 +166,7 @@ fn realize_block<'a>( content: &'a Content, styles: StyleChain<'a>, ) -> SourceResult<(Content, StyleChain<'a>)> { - if content.has::() + if content.can::() && !content.is::() && !content.is::() && !content.is::() @@ -227,16 +227,20 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> { mut content: &'a Content, styles: StyleChain<'a>, ) -> SourceResult<()> { - if content.has::() && !content.is::() { + if content.can::() && !content.is::() { content = self.scratch.content.alloc(FormulaNode::new(content.clone()).pack()); } // Prepare only if this is the first application for this node. - if let Some(node) = content.with::() { + if content.can::() { if !content.is_prepared() { - let prepared = - node.prepare(self.vt, content.clone().prepared(), styles)?; + let prepared = content + .clone() + .prepared() + .with::() + .unwrap() + .prepare(self.vt, styles)?; let stored = self.scratch.content.alloc(prepared); return self.accept(stored, styles); } @@ -291,11 +295,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> { } } - if let Some(span) = content.span() { - bail!(span, "not allowed here"); - } - - Ok(()) + bail!(content.span(), "not allowed here"); } fn styled( @@ -303,7 +303,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> { styled: &'a StyledNode, styles: StyleChain<'a>, ) -> SourceResult<()> { - let map = self.scratch.maps.alloc(styled.map()); + let map = self.scratch.maps.alloc(styled.styles()); let stored = self.scratch.styles.alloc(styles); let content = self.scratch.content.alloc(styled.body()); let styles = stored.chain(map); @@ -436,7 +436,7 @@ impl<'a> FlowBuilder<'a> { return true; } - if content.has::() || content.is::() { + if content.can::() || content.is::() { let is_tight_list = if let Some(node) = content.to::() { node.tight(styles) } else if let Some(node) = content.to::() { diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs index e5644a2e..8dd81d29 100644 --- a/library/src/layout/par.rs +++ b/library/src/layout/par.rs @@ -519,7 +519,7 @@ fn collect<'a>( let mut styles = *styles; if let Some(node) = child.to::() { child = Box::leak(Box::new(node.body())); - styles = outer.chain(Box::leak(Box::new(node.map()))); + styles = outer.chain(Box::leak(Box::new(node.styles()))); } let segment = if child.is::() { @@ -570,10 +570,8 @@ fn collect<'a>( let frac = node.width(styles).is_fractional(); full.push(if frac { SPACING_REPLACE } else { NODE_REPLACE }); Segment::Box(node, frac) - } else if let Some(span) = child.span() { - bail!(span, "unexpected document child"); } else { - continue; + bail!(child.span(), "unexpected paragraph child"); }; if let Some(last) = full.chars().last() { @@ -730,7 +728,7 @@ fn shared_get<'a, T: PartialEq>( children .iter() .filter_map(|child| child.to::()) - .all(|node| getter(styles.chain(&node.map())) == value) + .all(|node| getter(styles.chain(&node.styles())) == value) .then(|| value) } diff --git a/library/src/layout/stack.rs b/library/src/layout/stack.rs index c21fa884..1dd81a60 100644 --- a/library/src/layout/stack.rs +++ b/library/src/layout/stack.rs @@ -201,7 +201,7 @@ impl<'a> StackLayouter<'a> { let aligns = if let Some(align) = block.to::() { align.alignment(styles) } else if let Some(styled) = block.to::() { - AlignNode::alignment_in(styles.chain(&styled.map())) + AlignNode::alignment_in(styles.chain(&styled.styles())) } else { AlignNode::alignment_in(styles) } -- cgit v1.2.3