summaryrefslogtreecommitdiff
path: root/library/src/layout
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/layout')
-rw-r--r--library/src/layout/align.rs2
-rw-r--r--library/src/layout/flow.rs10
-rw-r--r--library/src/layout/hide.rs2
-rw-r--r--library/src/layout/mod.rs26
-rw-r--r--library/src/layout/par.rs8
-rw-r--r--library/src/layout/stack.rs2
6 files changed, 24 insertions, 26 deletions
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<Content> {
+ fn show(&self, _: &mut Vt, styles: StyleChain) -> SourceResult<Content> {
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::<StyledNode>() {
- map = node.map();
+ map = node.styles();
styles = outer.chain(&map);
child = node.body();
}
@@ -48,15 +48,15 @@ impl Layout for FlowNode {
|| child.is::<ImageNode>()
{
layouter.layout_single(vt, &child, styles)?;
- } else if child.has::<dyn Layout>() {
+ } else if child.can::<dyn Layout>() {
layouter.layout_multiple(vt, &child, styles)?;
} else if child.is::<ColbreakNode>() {
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::<AlignNode>() {
align.alignment(styles)
} else if let Some(styled) = block.to::<StyledNode>() {
- 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<Content> {
+ fn show(&self, _: &mut Vt, _: StyleChain) -> SourceResult<Content> {
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::<dyn LayoutRoot>() && !applicable(content, styles) {
+ if content.can::<dyn LayoutRoot>() && !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::<dyn Layout>()
+ if content.can::<dyn Layout>()
&& !content.is::<RectNode>()
&& !content.is::<SquareNode>()
&& !content.is::<EllipseNode>()
@@ -227,16 +227,20 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
mut content: &'a Content,
styles: StyleChain<'a>,
) -> SourceResult<()> {
- if content.has::<dyn LayoutMath>() && !content.is::<FormulaNode>() {
+ if content.can::<dyn LayoutMath>() && !content.is::<FormulaNode>() {
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::<dyn Prepare>() {
+ if content.can::<dyn Prepare>() {
if !content.is_prepared() {
- let prepared =
- node.prepare(self.vt, content.clone().prepared(), styles)?;
+ let prepared = content
+ .clone()
+ .prepared()
+ .with::<dyn Prepare>()
+ .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::<dyn Layout>() || content.is::<ParNode>() {
+ if content.can::<dyn Layout>() || content.is::<ParNode>() {
let is_tight_list = if let Some(node) = content.to::<ListNode>() {
node.tight(styles)
} else if let Some(node) = content.to::<EnumNode>() {
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::<StyledNode>() {
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::<SpaceNode>() {
@@ -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::<StyledNode>())
- .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::<AlignNode>() {
align.alignment(styles)
} else if let Some(styled) = block.to::<StyledNode>() {
- AlignNode::alignment_in(styles.chain(&styled.map()))
+ AlignNode::alignment_in(styles.chain(&styled.styles()))
} else {
AlignNode::alignment_in(styles)
}