diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-01 15:35:09 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-01 15:35:09 +0200 |
| commit | f8770d2b2a8ac389704897f92f2753398352835b (patch) | |
| tree | e522fb7b52f780d3040e71990cf8e765fa7669df /src/library | |
| parent | e676ab53ddbab367179ee2ab214bb41ff2ee0c11 (diff) | |
Generalize layouting primitives 🛤
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/align.rs | 20 | ||||
| -rw-r--r-- | src/library/font.rs | 1 | ||||
| -rw-r--r-- | src/library/spacing.rs | 6 |
3 files changed, 14 insertions, 13 deletions
diff --git a/src/library/align.rs b/src/library/align.rs index c909087a..350724f7 100644 --- a/src/library/align.rs +++ b/src/library/align.rs @@ -23,8 +23,8 @@ pub async fn align(_: Span, mut args: DictValue, ctx: LayoutContext<'_>) -> Pass let all = args .take_all_num_vals::<Spanned<SpecAlign>>() .map(|align| (align.v.axis(), align)) - .chain(h.into_iter().map(|align| (Some(Horizontal), align))) - .chain(v.into_iter().map(|align| (Some(Vertical), align))); + .chain(h.into_iter().map(|align| (Some(SpecAxis::Horizontal), align))) + .chain(v.into_iter().map(|align| (Some(SpecAxis::Vertical), align))); let mut aligns = ctx.align; let mut had = [false; 2]; @@ -43,8 +43,8 @@ pub async fn align(_: Span, mut args: DictValue, ctx: LayoutContext<'_>) -> Pass } else if had[axis as usize] { error!(@f, align.span, "duplicate alignment for {} axis", axis); } else { - let gen_align = align.v.to_generic(ctx.axes); - *aligns.get_mut(axis.to_generic(ctx.axes)) = gen_align; + let gen_align = align.v.to_gen(ctx.sys); + *aligns.get_mut(axis.to_gen(ctx.sys)) = gen_align; had[axis as usize] = true; } } else { @@ -54,7 +54,7 @@ pub async fn align(_: Span, mut args: DictValue, ctx: LayoutContext<'_>) -> Pass // We have two unflushed centers, meaning we know that both axes // are to be centered. had = [true, true]; - aligns = LayoutAlign::new(Center, Center); + aligns = LayoutAlign::new(GenAlign::Center, GenAlign::Center); } else { deferred_center = true; } @@ -63,13 +63,13 @@ pub async fn align(_: Span, mut args: DictValue, ctx: LayoutContext<'_>) -> Pass // Flush a deferred center alignment if we know have had at least one // known alignment. if deferred_center && had != [false, false] { - let axis = if !had[Horizontal as usize] { - Horizontal + let axis = if !had[SpecAxis::Horizontal as usize] { + SpecAxis::Horizontal } else { - Vertical + SpecAxis::Vertical }; - *aligns.get_mut(axis.to_generic(ctx.axes)) = Center; + *aligns.get_mut(axis.to_gen(ctx.sys)) = GenAlign::Center; had[axis as usize] = true; deferred_center = false; @@ -79,7 +79,7 @@ pub async fn align(_: Span, mut args: DictValue, ctx: LayoutContext<'_>) -> Pass // If center has not been flushed by known, it is the only argument and then // we default to applying it to the primary axis. if deferred_center { - aligns.primary = Center; + aligns.primary = GenAlign::Center; } let commands = match content { diff --git a/src/library/font.rs b/src/library/font.rs index e0133822..1ffc50a8 100644 --- a/src/library/font.rs +++ b/src/library/font.rs @@ -1,6 +1,7 @@ use fontdock::{FontStretch, FontStyle, FontWeight}; use super::*; +use crate::eval::StringLike; use crate::length::ScaleLength; /// `font`: Configure the font. diff --git a/src/library/spacing.rs b/src/library/spacing.rs index aa2712d3..6596717b 100644 --- a/src/library/spacing.rs +++ b/src/library/spacing.rs @@ -7,7 +7,7 @@ use crate::length::ScaleLength; /// # Positional arguments /// - The spacing (length or relative to font size). pub async fn h(name: Span, args: DictValue, ctx: LayoutContext<'_>) -> Pass<Value> { - spacing(name, args, ctx, Horizontal) + spacing(name, args, ctx, SpecAxis::Horizontal) } /// `v`: Add vertical spacing. @@ -15,7 +15,7 @@ pub async fn h(name: Span, args: DictValue, ctx: LayoutContext<'_>) -> Pass<Valu /// # Positional arguments /// - The spacing (length or relative to font size). pub async fn v(name: Span, args: DictValue, ctx: LayoutContext<'_>) -> Pass<Value> { - spacing(name, args, ctx, Vertical) + spacing(name, args, ctx, SpecAxis::Vertical) } fn spacing( @@ -28,7 +28,7 @@ fn spacing( let spacing = args.expect::<ScaleLength>("spacing", name, &mut f); let commands = if let Some(spacing) = spacing { - let axis = axis.to_generic(ctx.axes); + let axis = axis.to_gen(ctx.sys); let spacing = spacing.raw_scaled(ctx.style.text.font_size()); vec![AddSpacing(spacing, SpacingKind::Hard, axis)] } else { |
