summaryrefslogtreecommitdiff
path: root/src/library/structure
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-01 16:56:35 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-02 09:18:33 +0100
commit37ac5d966ebaf97ac79c507028cd5b742b510b89 (patch)
tree249d43ff0f8d880cb5d00c236993f8ff0c1f10d8 /src/library/structure
parentf547c97072881069417acd3b79b08fb7ecf40ba2 (diff)
More dynamic content representation
Diffstat (limited to 'src/library/structure')
-rw-r--r--src/library/structure/heading.rs13
-rw-r--r--src/library/structure/list.rs48
-rw-r--r--src/library/structure/reference.rs8
-rw-r--r--src/library/structure/table.rs16
4 files changed, 47 insertions, 38 deletions
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index fa96248f..5b056c30 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -1,4 +1,4 @@
-use crate::library::layout::BlockSpacing;
+use crate::library::layout::{BlockNode, BlockSpacing};
use crate::library::prelude::*;
use crate::library::text::{FontFamily, TextNode, TextSize};
@@ -12,7 +12,7 @@ pub struct HeadingNode {
pub body: Content,
}
-#[node(showable)]
+#[node(Show)]
impl HeadingNode {
/// The heading's font family. Just the normal text family if `auto`.
#[property(referenced)]
@@ -61,15 +61,16 @@ impl HeadingNode {
pub const NUMBERED: bool = true;
fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> {
- Ok(Content::show(Self {
+ Ok(Self {
body: args.expect("body")?,
level: args.named("level")?.unwrap_or(NonZeroUsize::new(1).unwrap()),
- }))
+ }
+ .pack())
}
}
impl Show for HeadingNode {
- fn unguard(&self, sel: Selector) -> ShowNode {
+ fn unguard_parts(&self, sel: Selector) -> Content {
Self { body: self.body.unguard(sel), ..*self }.pack()
}
@@ -82,7 +83,7 @@ impl Show for HeadingNode {
}
fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
- Ok(Content::block(self.body.clone()))
+ Ok(BlockNode(self.body.clone()).pack())
}
fn finalize(
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index 8a57069e..f061c5f8 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -1,8 +1,8 @@
use unscanny::Scanner;
-use crate::library::layout::{BlockSpacing, GridNode, TrackSizing};
+use crate::library::layout::{BlockSpacing, GridNode, HNode, TrackSizing};
use crate::library::prelude::*;
-use crate::library::text::ParNode;
+use crate::library::text::{ParNode, SpaceNode};
use crate::library::utility::Numbering;
/// An unordered (bulleted) or ordered (numbered) list.
@@ -22,7 +22,7 @@ pub type EnumNode = ListNode<ENUM>;
/// A description list.
pub type DescNode = ListNode<DESC>;
-#[node(showable)]
+#[node(Show)]
impl<const L: ListKind> ListNode<L> {
/// How the list is labelled.
#[property(referenced)]
@@ -73,16 +73,17 @@ impl<const L: ListKind> ListNode<L> {
.collect(),
};
- Ok(Content::show(Self {
+ Ok(Self {
tight: args.named("tight")?.unwrap_or(true),
attached: args.named("attached")?.unwrap_or(false),
items,
- }))
+ }
+ .pack())
}
}
impl<const L: ListKind> Show for ListNode<L> {
- fn unguard(&self, sel: Selector) -> ShowNode {
+ fn unguard_parts(&self, sel: Selector) -> Content {
Self {
items: self.items.map(|item| item.unguard(sel)),
..*self
@@ -123,36 +124,37 @@ impl<const L: ListKind> Show for ListNode<L> {
number = n;
}
- cells.push(LayoutNode::default());
+ cells.push(Content::empty());
let label = if L == LIST || L == ENUM {
- label.resolve(world, L, number)?.styled_with_map(map.clone()).pack()
+ label.resolve(world, L, number)?.styled_with_map(map.clone())
} else {
- LayoutNode::default()
+ Content::empty()
};
cells.push(label);
- cells.push(LayoutNode::default());
+ cells.push(Content::empty());
let body = match &item {
ListItem::List(body) => body.as_ref().clone(),
ListItem::Enum(_, body) => body.as_ref().clone(),
ListItem::Desc(item) => Content::sequence(vec![
- Content::Horizontal {
+ HNode {
amount: (-body_indent).into(),
weak: false,
- },
- (item.term.clone() + Content::Text(':'.into())).strong(),
- Content::Space,
+ }
+ .pack(),
+ (item.term.clone() + TextNode(':'.into()).pack()).strong(),
+ SpaceNode.pack(),
item.body.clone(),
]),
};
- cells.push(body.styled_with_map(map.clone()).pack());
+ cells.push(body.styled_with_map(map.clone()));
number += 1;
}
- Ok(Content::block(GridNode {
+ Ok(GridNode {
tracks: Axes::with_x(vec![
TrackSizing::Relative(indent.into()),
TrackSizing::Auto,
@@ -161,7 +163,8 @@ impl<const L: ListKind> Show for ListNode<L> {
]),
gutter: Axes::with_y(vec![TrackSizing::Relative(gutter.into())]),
cells,
- }))
+ }
+ .pack())
}
fn finalize(
@@ -250,6 +253,9 @@ impl Debug for ListItem {
}
}
+#[node]
+impl ListItem {}
+
/// A description list item.
#[derive(Clone, PartialEq, Hash)]
pub struct DescItem {
@@ -310,14 +316,14 @@ impl Label {
) -> SourceResult<Content> {
Ok(match self {
Self::Default => match kind {
- LIST => Content::Text('•'.into()),
- ENUM => Content::Text(format_eco!("{}.", number)),
+ LIST => TextNode('•'.into()).pack(),
+ ENUM => TextNode(format_eco!("{}.", number)).pack(),
DESC | _ => panic!("description lists don't have a label"),
},
Self::Pattern(prefix, numbering, upper, suffix) => {
let fmt = numbering.apply(number);
let mid = if *upper { fmt.to_uppercase() } else { fmt.to_lowercase() };
- Content::Text(format_eco!("{}{}{}", prefix, mid, suffix))
+ TextNode(format_eco!("{}{}{}", prefix, mid, suffix)).pack()
}
Self::Content(content) => content.clone(),
Self::Func(func, span) => {
@@ -335,7 +341,7 @@ impl Cast<Spanned<Value>> for Label {
fn cast(value: Spanned<Value>) -> StrResult<Self> {
match value.v {
- Value::None => Ok(Self::Content(Content::Empty)),
+ Value::None => Ok(Self::Content(Content::empty())),
Value::Str(pattern) => {
let mut s = Scanner::new(&pattern);
let mut prefix;
diff --git a/src/library/structure/reference.rs b/src/library/structure/reference.rs
index 425ee518..b4e8b047 100644
--- a/src/library/structure/reference.rs
+++ b/src/library/structure/reference.rs
@@ -4,15 +4,15 @@ use crate::library::prelude::*;
#[derive(Debug, Hash)]
pub struct RefNode(pub EcoString);
-#[node(showable)]
+#[node(Show)]
impl RefNode {
fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> {
- Ok(Content::show(Self(args.expect("label")?)))
+ Ok(Self(args.expect("label")?).pack())
}
}
impl Show for RefNode {
- fn unguard(&self, _: Selector) -> ShowNode {
+ fn unguard_parts(&self, _: Selector) -> Content {
Self(self.0.clone()).pack()
}
@@ -24,6 +24,6 @@ impl Show for RefNode {
}
fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
- Ok(Content::Text(format_eco!("@{}", self.0)))
+ Ok(TextNode(format_eco!("@{}", self.0)).pack())
}
}
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index 41dcd104..d5e8920e 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -12,7 +12,7 @@ pub struct TableNode {
pub cells: Vec<Content>,
}
-#[node(showable)]
+#[node(Show)]
impl TableNode {
/// How to fill the cells.
#[property(referenced)]
@@ -36,19 +36,20 @@ impl TableNode {
let base_gutter: Vec<TrackSizing> = args.named("gutter")?.unwrap_or_default();
let column_gutter = args.named("column-gutter")?;
let row_gutter = args.named("row-gutter")?;
- Ok(Content::show(Self {
+ Ok(Self {
tracks: Axes::new(columns, rows),
gutter: Axes::new(
column_gutter.unwrap_or_else(|| base_gutter.clone()),
row_gutter.unwrap_or(base_gutter),
),
cells: args.all()?,
- }))
+ }
+ .pack())
}
}
impl Show for TableNode {
- fn unguard(&self, sel: Selector) -> ShowNode {
+ fn unguard_parts(&self, sel: Selector) -> Content {
Self {
tracks: self.tracks.clone(),
gutter: self.gutter.clone(),
@@ -82,7 +83,7 @@ impl Show for TableNode {
.cloned()
.enumerate()
.map(|(i, child)| {
- let mut child = child.pack().padded(Sides::splat(padding));
+ let mut child = child.padded(Sides::splat(padding));
if let Some(stroke) = stroke {
child = child.stroked(stroke);
@@ -98,11 +99,12 @@ impl Show for TableNode {
})
.collect::<SourceResult<_>>()?;
- Ok(Content::block(GridNode {
+ Ok(GridNode {
tracks: self.tracks.clone(),
gutter: self.gutter.clone(),
cells,
- }))
+ }
+ .pack())
}
fn finalize(