diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-09 18:16:59 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-09 18:20:02 +0100 |
| commit | 010cc2effc2fd0e1c4e52d5c914cb4d74506bc0a (patch) | |
| tree | e50060d271f076b00945e5569e7f8ffef2c28e9f /library/src/layout/spacing.rs | |
| parent | 12a59963b08b68cc39dcded4d3d3e6a6631c2732 (diff) | |
New block spacing model
Diffstat (limited to 'library/src/layout/spacing.rs')
| -rw-r--r-- | library/src/layout/spacing.rs | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/library/src/layout/spacing.rs b/library/src/layout/spacing.rs index 67fff5db..66d71ed1 100644 --- a/library/src/layout/spacing.rs +++ b/library/src/layout/spacing.rs @@ -1,10 +1,9 @@ use std::cmp::Ordering; use crate::prelude::*; -use crate::text::ParNode; /// Horizontal spacing. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Copy, Clone, Hash)] pub struct HNode { pub amount: Spacing, pub weak: bool, @@ -20,11 +19,22 @@ impl HNode { } /// Vertical spacing. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, PartialOrd)] pub struct VNode { pub amount: Spacing, pub weak: bool, - pub generated: bool, +} + +impl VNode { + /// Create weak vertical spacing. + pub fn weak(amount: Spacing) -> Self { + Self { amount, weak: true } + } + + /// Create strong vertical spacing. + pub fn strong(amount: Spacing) -> Self { + Self { amount, weak: false } + } } #[node] @@ -32,7 +42,7 @@ impl VNode { fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { let amount = args.expect("spacing")?; let weak = args.named("weak")?.unwrap_or(false); - Ok(Self { amount, weak, generated: false }.pack()) + Ok(Self { amount, weak }.pack()) } } @@ -59,6 +69,12 @@ impl From<Abs> for Spacing { } } +impl From<Em> for Spacing { + fn from(em: Em) -> Self { + Self::Relative(Rel::new(Ratio::zero(), em.into())) + } +} + impl PartialOrd for Spacing { fn partial_cmp(&self, other: &Self) -> Option<Ordering> { match (self, other) { @@ -77,24 +93,3 @@ castable! { Value::Relative(v) => Self::Relative(v), Value::Fraction(v) => Self::Fractional(v), } - -/// Spacing around and between blocks, relative to paragraph spacing. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub struct BlockSpacing(Rel<Length>); - -castable!(BlockSpacing: Rel<Length>); - -impl Resolve for BlockSpacing { - type Output = Abs; - - fn resolve(self, styles: StyleChain) -> Self::Output { - let whole = styles.get(ParNode::SPACING); - self.0.resolve(styles).relative_to(whole) - } -} - -impl From<Ratio> for BlockSpacing { - fn from(ratio: Ratio) -> Self { - Self(ratio.into()) - } -} |
