summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-03-12 14:24:24 +0100
committerLaurenz <laurmaedje@gmail.com>2022-03-12 14:24:24 +0100
commit2890a156d27c02a101137bf01dc2046597110bd1 (patch)
treec6bdeb48242c0fbd5b5e13120ca3c8f502d41b75 /src/library
parent5ac7eb3860ebd3247f6486c227e816894cb8fd91 (diff)
Remove classes and improve naming
Diffstat (limited to 'src/library')
-rw-r--r--src/library/graphics/hide.rs2
-rw-r--r--src/library/graphics/image.rs2
-rw-r--r--src/library/graphics/shape.rs2
-rw-r--r--src/library/graphics/transform.rs2
-rw-r--r--src/library/layout/align.rs2
-rw-r--r--src/library/layout/columns.rs4
-rw-r--r--src/library/layout/container.rs4
-rw-r--r--src/library/layout/flow.rs10
-rw-r--r--src/library/layout/grid.rs2
-rw-r--r--src/library/layout/pad.rs2
-rw-r--r--src/library/layout/page.rs10
-rw-r--r--src/library/layout/place.rs2
-rw-r--r--src/library/layout/spacing.rs12
-rw-r--r--src/library/layout/stack.rs22
-rw-r--r--src/library/math/mod.rs2
-rw-r--r--src/library/mod.rs122
-rw-r--r--src/library/prelude.rs7
-rw-r--r--src/library/structure/heading.rs2
-rw-r--r--src/library/structure/list.rs2
-rw-r--r--src/library/structure/table.rs7
-rw-r--r--src/library/text/deco.rs2
-rw-r--r--src/library/text/link.rs2
-rw-r--r--src/library/text/mod.rs6
-rw-r--r--src/library/text/par.rs23
-rw-r--r--src/library/text/raw.rs2
25 files changed, 129 insertions, 126 deletions
diff --git a/src/library/graphics/hide.rs b/src/library/graphics/hide.rs
index 21fc58c2..85971c36 100644
--- a/src/library/graphics/hide.rs
+++ b/src/library/graphics/hide.rs
@@ -4,7 +4,7 @@ use crate::library::prelude::*;
#[derive(Debug, Hash)]
pub struct HideNode(pub LayoutNode);
-#[class]
+#[node]
impl HideNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::inline(Self(args.expect("body")?)))
diff --git a/src/library/graphics/image.rs b/src/library/graphics/image.rs
index faf89850..54793754 100644
--- a/src/library/graphics/image.rs
+++ b/src/library/graphics/image.rs
@@ -7,7 +7,7 @@ use crate::library::text::TextNode;
#[derive(Debug, Hash)]
pub struct ImageNode(pub ImageId);
-#[class]
+#[node]
impl ImageNode {
/// How the image should adjust itself to a given area.
pub const FIT: ImageFit = ImageFit::Cover;
diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs
index fbe21347..9f9ff889 100644
--- a/src/library/graphics/shape.rs
+++ b/src/library/graphics/shape.rs
@@ -19,7 +19,7 @@ pub type CircleNode = ShapeNode<CIRCLE>;
/// Place a node into an ellipse.
pub type EllipseNode = ShapeNode<ELLIPSE>;
-#[class]
+#[node]
impl<const S: ShapeKind> ShapeNode<S> {
/// How to fill the shape.
pub const FILL: Option<Paint> = None;
diff --git a/src/library/graphics/transform.rs b/src/library/graphics/transform.rs
index fcd7528d..0dc50166 100644
--- a/src/library/graphics/transform.rs
+++ b/src/library/graphics/transform.rs
@@ -19,7 +19,7 @@ pub type RotateNode = TransformNode<ROTATE>;
/// Transform a node by scaling it without affecting layout.
pub type ScaleNode = TransformNode<SCALE>;
-#[class]
+#[node]
impl<const T: TransformKind> TransformNode<T> {
/// The origin of the transformation.
pub const ORIGIN: Spec<Option<Align>> = Spec::default();
diff --git a/src/library/layout/align.rs b/src/library/layout/align.rs
index 2a969524..b08e5fce 100644
--- a/src/library/layout/align.rs
+++ b/src/library/layout/align.rs
@@ -10,7 +10,7 @@ pub struct AlignNode {
pub child: LayoutNode,
}
-#[class]
+#[node]
impl AlignNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let aligns: Spec<_> = args.find()?.unwrap_or_default();
diff --git a/src/library/layout/columns.rs b/src/library/layout/columns.rs
index 9e461108..b5ec7de9 100644
--- a/src/library/layout/columns.rs
+++ b/src/library/layout/columns.rs
@@ -11,7 +11,7 @@ pub struct ColumnsNode {
pub child: LayoutNode,
}
-#[class]
+#[node]
impl ColumnsNode {
/// The size of the gutter space between each column.
pub const GUTTER: Linear = Relative::new(0.04).into();
@@ -103,7 +103,7 @@ impl Layout for ColumnsNode {
/// A column break.
pub struct ColbreakNode;
-#[class]
+#[node]
impl ColbreakNode {
fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> {
Ok(Content::Colbreak)
diff --git a/src/library/layout/container.rs b/src/library/layout/container.rs
index f7f4017c..6689dd48 100644
--- a/src/library/layout/container.rs
+++ b/src/library/layout/container.rs
@@ -3,7 +3,7 @@ use crate::library::prelude::*;
/// An inline-level container that sizes content and places it into a paragraph.
pub struct BoxNode;
-#[class]
+#[node]
impl BoxNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let width = args.named("width")?;
@@ -16,7 +16,7 @@ impl BoxNode {
/// A block-level container that places content into a separate flow.
pub struct BlockNode;
-#[class]
+#[node]
impl BlockNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::Block(args.find()?.unwrap_or_default()))
diff --git a/src/library/layout/flow.rs b/src/library/layout/flow.rs
index f4b885b1..3602bea6 100644
--- a/src/library/layout/flow.rs
+++ b/src/library/layout/flow.rs
@@ -1,4 +1,4 @@
-use super::{AlignNode, PlaceNode, SpacingKind};
+use super::{AlignNode, PlaceNode, Spacing};
use crate::library::prelude::*;
use crate::library::text::{ParNode, TextNode};
@@ -19,7 +19,7 @@ pub enum FlowChild {
/// A column / region break.
Colbreak,
/// Vertical spacing between other children.
- Spacing(SpacingKind),
+ Spacing(Spacing),
/// An arbitrary block-level node.
Node(LayoutNode),
}
@@ -142,9 +142,9 @@ impl FlowLayouter {
}
/// Layout spacing.
- pub fn layout_spacing(&mut self, spacing: SpacingKind) {
+ pub fn layout_spacing(&mut self, spacing: Spacing) {
match spacing {
- SpacingKind::Linear(v) => {
+ Spacing::Linear(v) => {
// Resolve the linear and limit it to the remaining space.
let resolved = v.resolve(self.full.y);
let limited = resolved.min(self.regions.first.y);
@@ -152,7 +152,7 @@ impl FlowLayouter {
self.used.y += limited;
self.items.push(FlowItem::Absolute(resolved));
}
- SpacingKind::Fractional(v) => {
+ Spacing::Fractional(v) => {
self.items.push(FlowItem::Fractional(v));
self.fr += v;
}
diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs
index 90cf6da3..716ac853 100644
--- a/src/library/layout/grid.rs
+++ b/src/library/layout/grid.rs
@@ -11,7 +11,7 @@ pub struct GridNode {
pub children: Vec<LayoutNode>,
}
-#[class]
+#[node]
impl GridNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let columns = args.named("columns")?.unwrap_or_default();
diff --git a/src/library/layout/pad.rs b/src/library/layout/pad.rs
index 835beef9..664c63ac 100644
--- a/src/library/layout/pad.rs
+++ b/src/library/layout/pad.rs
@@ -9,7 +9,7 @@ pub struct PadNode {
pub child: LayoutNode,
}
-#[class]
+#[node]
impl PadNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let all = args.find()?;
diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs
index def2940e..b1008feb 100644
--- a/src/library/layout/page.rs
+++ b/src/library/layout/page.rs
@@ -7,7 +7,7 @@ use crate::library::prelude::*;
#[derive(Clone, PartialEq, Hash)]
pub struct PageNode(pub LayoutNode);
-#[class]
+#[node]
impl PageNode {
/// The unflipped width of the page.
pub const WIDTH: Smart<Length> = Smart::Custom(Paper::A4.width());
@@ -36,7 +36,9 @@ impl PageNode {
Ok(Content::Page(Self(args.expect("body")?)))
}
- fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> {
+ fn set(args: &mut Args) -> TypResult<StyleMap> {
+ let mut styles = StyleMap::new();
+
if let Some(paper) = args.named_or_find::<Paper>("paper")? {
styles.set(Self::WIDTH, Smart::Custom(paper.width()));
styles.set(Self::HEIGHT, Smart::Custom(paper.height()));
@@ -59,7 +61,7 @@ impl PageNode {
styles.set_opt(Self::HEADER, args.named("header")?);
styles.set_opt(Self::FOOTER, args.named("footer")?);
- Ok(())
+ Ok(styles)
}
}
@@ -153,7 +155,7 @@ impl Debug for PageNode {
/// A page break.
pub struct PagebreakNode;
-#[class]
+#[node]
impl PagebreakNode {
fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> {
Ok(Content::Pagebreak)
diff --git a/src/library/layout/place.rs b/src/library/layout/place.rs
index 99ff5292..2d4ebc4d 100644
--- a/src/library/layout/place.rs
+++ b/src/library/layout/place.rs
@@ -5,7 +5,7 @@ use crate::library::prelude::*;
#[derive(Debug, Hash)]
pub struct PlaceNode(pub LayoutNode);
-#[class]
+#[node]
impl PlaceNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let aligns = args.find()?.unwrap_or(Spec::with_x(Some(Align::Left)));
diff --git a/src/library/layout/spacing.rs b/src/library/layout/spacing.rs
index 9a27a8b2..8aea780c 100644
--- a/src/library/layout/spacing.rs
+++ b/src/library/layout/spacing.rs
@@ -3,7 +3,7 @@ use crate::library::prelude::*;
/// Horizontal spacing.
pub struct HNode;
-#[class]
+#[node]
impl HNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::Horizontal(args.expect("spacing")?))
@@ -13,7 +13,7 @@ impl HNode {
/// Vertical spacing.
pub struct VNode;
-#[class]
+#[node]
impl VNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::Vertical(args.expect("spacing")?))
@@ -22,28 +22,28 @@ impl VNode {
/// Kinds of spacing.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-pub enum SpacingKind {
+pub enum Spacing {
/// A length stated in absolute values and/or relative to the parent's size.
Linear(Linear),
/// A length that is the fraction of the remaining free space in the parent.
Fractional(Fractional),
}
-impl SpacingKind {
+impl Spacing {
/// Whether this is fractional spacing.
pub fn is_fractional(self) -> bool {
matches!(self, Self::Fractional(_))
}
}
-impl From<Length> for SpacingKind {
+impl From<Length> for Spacing {
fn from(length: Length) -> Self {
Self::Linear(length.into())
}
}
castable! {
- SpacingKind,
+ Spacing,
Expected: "linear or fractional",
Value::Length(v) => Self::Linear(v.into()),
Value::Relative(v) => Self::Linear(v.into()),
diff --git a/src/library/layout/stack.rs b/src/library/layout/stack.rs
index 88e27116..11d45bb4 100644
--- a/src/library/layout/stack.rs
+++ b/src/library/layout/stack.rs
@@ -1,4 +1,4 @@
-use super::{AlignNode, SpacingKind};
+use super::{AlignNode, Spacing};
use crate::library::prelude::*;
/// Arrange nodes and spacing along an axis.
@@ -7,12 +7,12 @@ pub struct StackNode {
/// The stacking direction.
pub dir: Dir,
/// The spacing between non-spacing children.
- pub spacing: Option<SpacingKind>,
+ pub spacing: Option<Spacing>,
/// The children to be stacked.
pub children: Vec<StackChild>,
}
-#[class]
+#[node]
impl StackNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::block(Self {
@@ -60,7 +60,7 @@ impl Layout for StackNode {
#[derive(Hash)]
pub enum StackChild {
/// Spacing between other nodes.
- Spacing(SpacingKind),
+ Spacing(Spacing),
/// An arbitrary node.
Node(LayoutNode),
}
@@ -77,10 +77,10 @@ impl Debug for StackChild {
castable! {
StackChild,
Expected: "linear, fractional or content",
- Value::Length(v) => Self::Spacing(SpacingKind::Linear(v.into())),
- Value::Relative(v) => Self::Spacing(SpacingKind::Linear(v.into())),
- Value::Linear(v) => Self::Spacing(SpacingKind::Linear(v)),
- Value::Fractional(v) => Self::Spacing(SpacingKind::Fractional(v)),
+ Value::Length(v) => Self::Spacing(Spacing::Linear(v.into())),
+ Value::Relative(v) => Self::Spacing(Spacing::Linear(v.into())),
+ Value::Linear(v) => Self::Spacing(Spacing::Linear(v)),
+ Value::Fractional(v) => Self::Spacing(Spacing::Fractional(v)),
Value::Content(v) => Self::Node(v.pack()),
}
@@ -142,9 +142,9 @@ impl StackLayouter {
}
/// Add spacing along the spacing direction.
- pub fn layout_spacing(&mut self, spacing: SpacingKind) {
+ pub fn layout_spacing(&mut self, spacing: Spacing) {
match spacing {
- SpacingKind::Linear(v) => {
+ Spacing::Linear(v) => {
// Resolve the linear and limit it to the remaining space.
let resolved = v.resolve(self.regions.base.get(self.axis));
let remaining = self.regions.first.get_mut(self.axis);
@@ -153,7 +153,7 @@ impl StackLayouter {
self.used.main += limited;
self.items.push(StackItem::Absolute(resolved));
}
- SpacingKind::Fractional(v) => {
+ Spacing::Fractional(v) => {
self.fr += v;
self.items.push(StackItem::Fractional(v));
}
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs
index b43db22e..f20d6543 100644
--- a/src/library/math/mod.rs
+++ b/src/library/math/mod.rs
@@ -11,7 +11,7 @@ pub struct MathNode {
pub display: bool,
}
-#[class]
+#[node(showable)]
impl MathNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self {
diff --git a/src/library/mod.rs b/src/library/mod.rs
index b2e4e408..8f00e5fe 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -18,77 +18,77 @@ pub fn new() -> Scope {
let mut std = Scope::new();
// Text.
- std.def_class::<text::TextNode>("text");
- std.def_class::<text::ParNode>("par");
- std.def_class::<text::LinebreakNode>("linebreak");
- std.def_class::<text::ParbreakNode>("parbreak");
- std.def_class::<text::StrongNode>("strong");
- std.def_class::<text::EmphNode>("emph");
- std.def_class::<text::RawNode>("raw");
- std.def_class::<text::UnderlineNode>("underline");
- std.def_class::<text::StrikethroughNode>("strike");
- std.def_class::<text::OverlineNode>("overline");
- std.def_class::<text::LinkNode>("link");
+ std.def_node::<text::TextNode>("text");
+ std.def_node::<text::ParNode>("par");
+ std.def_node::<text::LinebreakNode>("linebreak");
+ std.def_node::<text::ParbreakNode>("parbreak");
+ std.def_node::<text::StrongNode>("strong");
+ std.def_node::<text::EmphNode>("emph");
+ std.def_node::<text::RawNode>("raw");
+ std.def_node::<text::UnderlineNode>("underline");
+ std.def_node::<text::StrikethroughNode>("strike");
+ std.def_node::<text::OverlineNode>("overline");
+ std.def_node::<text::LinkNode>("link");
// Structure.
- std.def_class::<structure::HeadingNode>("heading");
- std.def_class::<structure::ListNode>("list");
- std.def_class::<structure::EnumNode>("enum");
- std.def_class::<structure::TableNode>("table");
+ std.def_node::<structure::HeadingNode>("heading");
+ std.def_node::<structure::ListNode>("list");
+ std.def_node::<structure::EnumNode>("enum");
+ std.def_node::<structure::TableNode>("table");
// Layout.
- std.def_class::<layout::PageNode>("page");
- std.def_class::<layout::PagebreakNode>("pagebreak");
- std.def_class::<layout::HNode>("h");
- std.def_class::<layout::VNode>("v");
- std.def_class::<layout::BoxNode>("box");
- std.def_class::<layout::BlockNode>("block");
- std.def_class::<layout::AlignNode>("align");
- std.def_class::<layout::PadNode>("pad");
- std.def_class::<layout::StackNode>("stack");
- std.def_class::<layout::GridNode>("grid");
- std.def_class::<layout::ColumnsNode>("columns");
- std.def_class::<layout::ColbreakNode>("colbreak");
- std.def_class::<layout::PlaceNode>("place");
+ std.def_node::<layout::PageNode>("page");
+ std.def_node::<layout::PagebreakNode>("pagebreak");
+ std.def_node::<layout::HNode>("h");
+ std.def_node::<layout::VNode>("v");
+ std.def_node::<layout::BoxNode>("box");
+ std.def_node::<layout::BlockNode>("block");
+ std.def_node::<layout::AlignNode>("align");
+ std.def_node::<layout::PadNode>("pad");
+ std.def_node::<layout::StackNode>("stack");
+ std.def_node::<layout::GridNode>("grid");
+ std.def_node::<layout::ColumnsNode>("columns");
+ std.def_node::<layout::ColbreakNode>("colbreak");
+ std.def_node::<layout::PlaceNode>("place");
// Graphics.
- std.def_class::<graphics::ImageNode>("image");
- std.def_class::<graphics::RectNode>("rect");
- std.def_class::<graphics::SquareNode>("square");
- std.def_class::<graphics::EllipseNode>("ellipse");
- std.def_class::<graphics::CircleNode>("circle");
- std.def_class::<graphics::MoveNode>("move");
- std.def_class::<graphics::ScaleNode>("scale");
- std.def_class::<graphics::RotateNode>("rotate");
- std.def_class::<graphics::HideNode>("hide");
+ std.def_node::<graphics::ImageNode>("image");
+ std.def_node::<graphics::RectNode>("rect");
+ std.def_node::<graphics::SquareNode>("square");
+ std.def_node::<graphics::EllipseNode>("ellipse");
+ std.def_node::<graphics::CircleNode>("circle");
+ std.def_node::<graphics::MoveNode>("move");
+ std.def_node::<graphics::ScaleNode>("scale");
+ std.def_node::<graphics::RotateNode>("rotate");
+ std.def_node::<graphics::HideNode>("hide");
// Math.
- std.def_class::<math::MathNode>("math");
+ std.def_node::<math::MathNode>("math");
// Utility functions.
- std.def_func("assert", utility::assert);
- std.def_func("type", utility::type_);
- std.def_func("repr", utility::repr);
- std.def_func("join", utility::join);
- std.def_func("int", utility::int);
- std.def_func("float", utility::float);
- std.def_func("str", utility::str);
- std.def_func("abs", utility::abs);
- std.def_func("min", utility::min);
- std.def_func("max", utility::max);
- std.def_func("even", utility::even);
- std.def_func("odd", utility::odd);
- std.def_func("mod", utility::modulo);
- std.def_func("range", utility::range);
- std.def_func("rgb", utility::rgb);
- std.def_func("cmyk", utility::cmyk);
- std.def_func("lower", utility::lower);
- std.def_func("upper", utility::upper);
- std.def_func("letter", utility::letter);
- std.def_func("roman", utility::roman);
- std.def_func("symbol", utility::symbol);
- std.def_func("len", utility::len);
- std.def_func("sorted", utility::sorted);
+ std.def_fn("assert", utility::assert);
+ std.def_fn("type", utility::type_);
+ std.def_fn("repr", utility::repr);
+ std.def_fn("join", utility::join);
+ std.def_fn("int", utility::int);
+ std.def_fn("float", utility::float);
+ std.def_fn("str", utility::str);
+ std.def_fn("abs", utility::abs);
+ std.def_fn("min", utility::min);
+ std.def_fn("max", utility::max);
+ std.def_fn("even", utility::even);
+ std.def_fn("odd", utility::odd);
+ std.def_fn("mod", utility::modulo);
+ std.def_fn("range", utility::range);
+ std.def_fn("rgb", utility::rgb);
+ std.def_fn("cmyk", utility::cmyk);
+ std.def_fn("lower", utility::lower);
+ std.def_fn("upper", utility::upper);
+ std.def_fn("letter", utility::letter);
+ std.def_fn("roman", utility::roman);
+ std.def_fn("symbol", utility::symbol);
+ std.def_fn("len", utility::len);
+ std.def_fn("sorted", utility::sorted);
// Predefined colors.
std.def_const("black", Color::BLACK);
diff --git a/src/library/prelude.rs b/src/library/prelude.rs
index 0cca718f..001798f3 100644
--- a/src/library/prelude.rs
+++ b/src/library/prelude.rs
@@ -5,13 +5,12 @@ pub use std::hash::Hash;
pub use std::num::NonZeroUsize;
pub use std::sync::Arc;
-pub use typst_macros::class;
+pub use typst_macros::node;
pub use crate::diag::{with_alternative, At, StrResult, TypResult};
pub use crate::eval::{
- Arg, Args, Array, Cast, Construct, Content, Dict, Func, Layout, LayoutNode, Merge,
- Property, Regions, Scope, Set, Show, ShowNode, Smart, StyleChain, StyleMap, StyleVec,
- Value,
+ Arg, Args, Array, Cast, Content, Dict, Func, Key, Layout, LayoutNode, Merge, Node,
+ Regions, Scope, Show, ShowNode, Smart, StyleChain, StyleMap, StyleVec, Value,
};
pub use crate::frame::*;
pub use crate::geom::*;
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index f5565f3c..f1bc795f 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -11,7 +11,7 @@ pub struct HeadingNode {
pub body: Content,
}
-#[class]
+#[node(showable)]
impl HeadingNode {
/// The heading's font family. Just the normal text family if `auto`.
pub const FAMILY: Leveled<Smart<FontFamily>> = Leveled::Value(Smart::Auto);
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index 2630d231..414f601e 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -28,7 +28,7 @@ pub struct ListItem {
/// An ordered list.
pub type EnumNode = ListNode<ORDERED>;
-#[class]
+#[node(showable)]
impl<const L: ListKind> ListNode<L> {
/// How the list is labelled.
pub const LABEL: Label = Label::Default;
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index 42b62eac..0e455ead 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -12,7 +12,7 @@ pub struct TableNode {
pub children: Vec<Content>,
}
-#[class]
+#[node(showable)]
impl TableNode {
/// The primary cell fill color.
pub const PRIMARY: Option<Paint> = None;
@@ -41,14 +41,15 @@ impl TableNode {
}))
}
- fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> {
+ fn set(args: &mut Args) -> TypResult<StyleMap> {
+ let mut styles = StyleMap::new();
let fill = args.named("fill")?;
styles.set_opt(Self::PRIMARY, args.named("primary")?.or(fill));
styles.set_opt(Self::SECONDARY, args.named("secondary")?.or(fill));
styles.set_opt(Self::STROKE, args.named("stroke")?);
styles.set_opt(Self::THICKNESS, args.named("thickness")?);
styles.set_opt(Self::PADDING, args.named("padding")?);
- Ok(())
+ Ok(styles)
}
}
diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs
index 608ebb18..29c04b2d 100644
--- a/src/library/text/deco.rs
+++ b/src/library/text/deco.rs
@@ -18,7 +18,7 @@ pub type StrikethroughNode = DecoNode<STRIKETHROUGH>;
/// Typeset overlined text.
pub type OverlineNode = DecoNode<OVERLINE>;
-#[class]
+#[node(showable)]
impl<const L: DecoLine> DecoNode<L> {
/// Stroke color of the line, defaults to the text color if `None`.
#[shorthand]
diff --git a/src/library/text/link.rs b/src/library/text/link.rs
index e0041df5..4c2b5e7b 100644
--- a/src/library/text/link.rs
+++ b/src/library/text/link.rs
@@ -11,7 +11,7 @@ pub struct LinkNode {
pub body: Option<Content>,
}
-#[class]
+#[node(showable)]
impl LinkNode {
/// The fill color of text in the link. Just the surrounding text color
/// if `auto`.
diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs
index dbc486fb..8939a8c1 100644
--- a/src/library/text/mod.rs
+++ b/src/library/text/mod.rs
@@ -25,7 +25,7 @@ use crate::util::EcoString;
#[derive(Hash)]
pub struct TextNode;
-#[class]
+#[node]
impl TextNode {
/// A prioritized sequence of font families.
#[variadic]
@@ -122,7 +122,7 @@ impl TextNode {
#[derive(Debug, Hash)]
pub struct StrongNode(pub Content);
-#[class]
+#[node(showable)]
impl StrongNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self(args.expect("body")?)))
@@ -141,7 +141,7 @@ impl Show for StrongNode {
#[derive(Debug, Hash)]
pub struct EmphNode(pub Content);
-#[class]
+#[node(showable)]
impl EmphNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
Ok(Content::show(Self(args.expect("body")?)))
diff --git a/src/library/text/par.rs b/src/library/text/par.rs
index dc888637..be4e8096 100644
--- a/src/library/text/par.rs
+++ b/src/library/text/par.rs
@@ -6,7 +6,7 @@ use xi_unicode::LineBreakIterator;
use super::{shape, ShapedText, TextNode};
use crate::font::FontStore;
-use crate::library::layout::SpacingKind;
+use crate::library::layout::Spacing;
use crate::library::prelude::*;
use crate::util::{ArcExt, EcoString, RangeExt, SliceExt};
@@ -20,12 +20,12 @@ pub enum ParChild {
/// A chunk of text.
Text(EcoString),
/// Horizontal spacing between other children.
- Spacing(SpacingKind),
+ Spacing(Spacing),
/// An arbitrary inline-level node.
Node(LayoutNode),
}
-#[class]
+#[node]
impl ParNode {
/// An ISO 639-1 language code.
pub const LANG: Option<EcoString> = None;
@@ -53,9 +53,10 @@ impl ParNode {
Ok(Content::Block(args.expect("body")?))
}
- fn set(args: &mut Args, styles: &mut StyleMap) -> TypResult<()> {
- let lang = args.named::<Option<EcoString>>("lang")?;
+ fn set(args: &mut Args) -> TypResult<StyleMap> {
+ let mut styles = StyleMap::new();
+ let lang = args.named::<Option<EcoString>>("lang")?;
let mut dir =
lang.clone().flatten().map(|iso| match iso.to_lowercase().as_str() {
"ar" | "dv" | "fa" | "he" | "ks" | "pa" | "ps" | "sd" | "ug" | "ur"
@@ -89,7 +90,7 @@ impl ParNode {
styles.set_opt(Self::SPACING, args.named("spacing")?);
styles.set_opt(Self::INDENT, args.named("indent")?);
- Ok(())
+ Ok(styles)
}
}
@@ -183,7 +184,7 @@ impl Merge for ParChild {
/// A paragraph break.
pub struct ParbreakNode;
-#[class]
+#[node]
impl ParbreakNode {
fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> {
Ok(Content::Parbreak)
@@ -193,7 +194,7 @@ impl ParbreakNode {
/// A line break.
pub struct LinebreakNode;
-#[class]
+#[node]
impl LinebreakNode {
fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> {
Ok(Content::Linebreak)
@@ -256,13 +257,13 @@ impl<'a> ParLayout<'a> {
ranges.push(subrange);
}
}
- ParChild::Spacing(kind) => match *kind {
- SpacingKind::Linear(v) => {
+ ParChild::Spacing(spacing) => match *spacing {
+ Spacing::Linear(v) => {
let resolved = v.resolve(regions.first.x);
items.push(ParItem::Absolute(resolved));
ranges.push(range);
}
- SpacingKind::Fractional(v) => {
+ Spacing::Fractional(v) => {
items.push(ParItem::Fractional(v));
ranges.push(range);
}
diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs
index 988bd04e..e225803f 100644
--- a/src/library/text/raw.rs
+++ b/src/library/text/raw.rs
@@ -24,7 +24,7 @@ pub struct RawNode {
pub block: bool,
}
-#[class]
+#[node(showable)]
impl RawNode {
/// The language to syntax-highlight in.
pub const LANG: Option<EcoString> = None;