diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-01-07 10:46:55 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-01-07 10:46:55 +0100 |
| commit | af014cfe5eea4233d8034c79c1a5f898c972396c (patch) | |
| tree | 3345554e62d3f1696006fdb42296be5c744fbf77 /src/library | |
| parent | 5fd9c0b0d7b519802d56dd04cb61340c11014cb1 (diff) | |
Tidy up styling
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/link.rs | 10 | ||||
| -rw-r--r-- | src/library/mod.rs | 47 | ||||
| -rw-r--r-- | src/library/page.rs | 4 | ||||
| -rw-r--r-- | src/library/par.rs | 5 | ||||
| -rw-r--r-- | src/library/text.rs | 12 |
5 files changed, 38 insertions, 40 deletions
diff --git a/src/library/link.rs b/src/library/link.rs index 1050963c..b7e3d587 100644 --- a/src/library/link.rs +++ b/src/library/link.rs @@ -15,9 +15,9 @@ pub fn link(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { Node::Text(text.into()) }); - let mut passed = StyleMap::new(); - passed.set(TextNode::LINK, Some(url.clone())); - passed.set(ImageNode::LINK, Some(url.clone())); - passed.set(ShapeNode::LINK, Some(url)); - Ok(Value::Node(body.styled(passed))) + let mut map = StyleMap::new(); + map.set(TextNode::LINK, Some(url.clone())); + map.set(ImageNode::LINK, Some(url.clone())); + map.set(ShapeNode::LINK, Some(url)); + Ok(Value::Node(body.styled_with_map(map))) } diff --git a/src/library/mod.rs b/src/library/mod.rs index 89f4ab9d..461716a1 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -61,8 +61,8 @@ prelude! { pub use crate::diag::{At, TypResult}; pub use crate::eval::{ - Args, Construct, EvalContext, Node, Property, Set, Smart, StyleChain, StyleMap, - Styled, Value, + Args, Construct, EvalContext, Node, Property, Scope, Set, Smart, StyleChain, + StyleMap, Styled, Value, }; pub use crate::frame::*; pub use crate::geom::*; @@ -73,52 +73,49 @@ prelude! { pub use crate::util::{EcoString, OptionExt}; } -use crate::eval::Scope; use prelude::*; /// Construct a scope containing all standard library definitions. pub fn new() -> Scope { let mut std = Scope::new(); - // Classes. + // Structure and semantics. std.def_class::<PageNode>("page"); std.def_class::<ParNode>("par"); std.def_class::<TextNode>("text"); - std.def_class::<HeadingNode>("heading"); - std.def_class::<ListNode<Unordered>>("list"); - std.def_class::<ListNode<Ordered>>("enum"); - - // Text functions. std.def_func("underline", underline); std.def_func("strike", strike); std.def_func("overline", overline); std.def_func("link", link); + std.def_class::<HeadingNode>("heading"); + std.def_class::<ListNode<Unordered>>("list"); + std.def_class::<ListNode<Ordered>>("enum"); + std.def_func("image", image); + std.def_func("rect", rect); + std.def_func("square", square); + std.def_func("ellipse", ellipse); + std.def_func("circle", circle); - // Break and spacing functions. - std.def_func("pagebreak", pagebreak); - std.def_func("colbreak", colbreak); - std.def_func("parbreak", parbreak); - std.def_func("linebreak", linebreak); + // Layout. std.def_func("h", h); std.def_func("v", v); - - // Layout functions. std.def_func("box", box_); std.def_func("block", block); - std.def_func("stack", stack); - std.def_func("grid", grid); - std.def_func("pad", pad); - std.def_func("columns", columns); std.def_func("align", align); + std.def_func("pad", pad); std.def_func("place", place); std.def_func("move", move_); std.def_func("scale", scale); std.def_func("rotate", rotate); - std.def_func("image", image); - std.def_func("rect", rect); - std.def_func("square", square); - std.def_func("ellipse", ellipse); - std.def_func("circle", circle); + std.def_func("stack", stack); + std.def_func("grid", grid); + std.def_func("columns", columns); + + // Breaks. + std.def_func("pagebreak", pagebreak); + std.def_func("colbreak", colbreak); + std.def_func("parbreak", parbreak); + std.def_func("linebreak", linebreak); // Utility functions. std.def_func("assert", assert); diff --git a/src/library/page.rs b/src/library/page.rs index a6d489ba..522fd3ac 100644 --- a/src/library/page.rs +++ b/src/library/page.rs @@ -4,7 +4,7 @@ use std::fmt::{self, Display, Formatter}; use std::str::FromStr; use super::prelude::*; -use super::{ColumnsNode, PadNode}; +use super::ColumnsNode; /// Layouts its child onto one or multiple pages. #[derive(Clone, PartialEq, Hash)] @@ -111,7 +111,7 @@ impl PageNode { } // Realize margins with padding node. - child = PadNode { child, padding }.pack(); + child = child.padded(padding); // Layout the child. let expand = size.map(Length::is_finite); diff --git a/src/library/par.rs b/src/library/par.rs index 87ad2ebe..38d15097 100644 --- a/src/library/par.rs +++ b/src/library/par.rs @@ -29,7 +29,10 @@ impl ParNode { impl Construct for ParNode { fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Node> { - // Lift to a block so that it doesn't merge with adjacent stuff. + // The paragraph constructor is special: It doesn't create a paragraph + // since that happens automatically through markup. Instead, it just + // lifts the passed body to the block level so that it won't merge with + // adjacent stuff and it styles the contained paragraphs. Ok(Node::Block(args.expect("body")?)) } } diff --git a/src/library/text.rs b/src/library/text.rs index ab5c15c3..d5c87949 100644 --- a/src/library/text.rs +++ b/src/library/text.rs @@ -96,10 +96,10 @@ impl TextNode { impl Construct for TextNode { fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Node> { - // We don't need to do anything more here because the whole point of the - // text constructor is to apply the styles and that happens - // automatically during class construction. - args.expect::<Node>("body") + // The text constructor is special: It doesn't create a text node. + // Instead, it leaves the passed argument structurally unchanged, but + // styles all text in it. + args.expect("body") } } @@ -404,9 +404,7 @@ fn line_impl(args: &mut Args, kind: LineKind) -> TypResult<Value> { let extent = args.named("extent")?.unwrap_or_default(); let body: Node = args.expect("body")?; let deco = LineDecoration { kind, stroke, thickness, offset, extent }; - Ok(Value::Node( - body.styled(StyleMap::with(TextNode::LINES, vec![deco])), - )) + Ok(Value::Node(body.styled(TextNode::LINES, vec![deco]))) } /// Defines a line that is positioned over, under or on top of text. |
