diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-03-12 14:24:24 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-03-12 14:24:24 +0100 |
| commit | 2890a156d27c02a101137bf01dc2046597110bd1 (patch) | |
| tree | c6bdeb48242c0fbd5b5e13120ca3c8f502d41b75 /src/library/layout | |
| parent | 5ac7eb3860ebd3247f6486c227e816894cb8fd91 (diff) | |
Remove classes and improve naming
Diffstat (limited to 'src/library/layout')
| -rw-r--r-- | src/library/layout/align.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/columns.rs | 4 | ||||
| -rw-r--r-- | src/library/layout/container.rs | 4 | ||||
| -rw-r--r-- | src/library/layout/flow.rs | 10 | ||||
| -rw-r--r-- | src/library/layout/grid.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/pad.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/page.rs | 10 | ||||
| -rw-r--r-- | src/library/layout/place.rs | 2 | ||||
| -rw-r--r-- | src/library/layout/spacing.rs | 12 | ||||
| -rw-r--r-- | src/library/layout/stack.rs | 22 |
10 files changed, 36 insertions, 34 deletions
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)); } |
