diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-07-29 18:09:51 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-07-29 18:09:51 +0200 |
| commit | bbcdeb128cce04cd95714b7bc7af5a23a7e38bd2 (patch) | |
| tree | e0a1620d335982669cd7671cbd71df46d100e9ea /src/library | |
| parent | f34ba3dcda182d9b9c14cc94fdb48810bf18bef0 (diff) | |
Move, rename and switch some things (boring) 🚚
- Problems -> Diagnostics
- Position -> Pos
- offset_spans -> Offset trait
- Size -> Length (and some more size types renamed)
- Paper into its own module
- scope::Parser -> parsing::CallParser
- Create `Decorations` alias
- Remove lots of double newlines
- Switch from f32 to f64
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/font.rs | 27 | ||||
| -rw-r--r-- | src/library/layout.rs | 27 | ||||
| -rw-r--r-- | src/library/mod.rs | 1 | ||||
| -rw-r--r-- | src/library/page.rs | 21 | ||||
| -rw-r--r-- | src/library/spacing.rs | 19 |
5 files changed, 45 insertions, 50 deletions
diff --git a/src/library/font.rs b/src/library/font.rs index 9f7902f6..28b79115 100644 --- a/src/library/font.rs +++ b/src/library/font.rs @@ -1,8 +1,7 @@ use toddle::query::{FontWeight, FontStyle}; -use crate::size::FSize; +use crate::length::ScaleLength; use super::*; - function! { /// `font.family`: Set the font family. #[derive(Debug, Clone, PartialEq)] @@ -13,17 +12,17 @@ function! { } parse(header, body, ctx, f) { - let list = header.args.pos.get_all::<StringLike>(&mut f.problems) + let list = header.args.pos.get_all::<StringLike>(&mut f.diagnostics) .map(|s| s.0.to_lowercase()) .collect(); let tuples: Vec<_> = header.args.key - .get_all::<String, Tuple>(&mut f.problems) + .get_all::<String, Tuple>(&mut f.diagnostics) .collect(); let classes = tuples.into_iter() .map(|(class, mut tuple)| { - let fallback = tuple.get_all::<StringLike>(&mut f.problems) + let fallback = tuple.get_all::<StringLike>(&mut f.diagnostics) .map(|s| s.0.to_lowercase()) .collect(); (class.to_lowercase(), fallback) @@ -64,8 +63,8 @@ function! { parse(header, body, ctx, f) { FontStyleFunc { body: body!(opt: body, ctx, f), - style: header.args.pos.get::<FontStyle>(&mut f.problems) - .or_missing(&mut f.problems, header.name.span, "style"), + style: header.args.pos.get::<FontStyle>(&mut f.diagnostics) + .or_missing(&mut f.diagnostics, header.name.span, "style"), } } @@ -84,7 +83,7 @@ function! { parse(header, body, ctx, f) { let body = body!(opt: body, ctx, f); - let weight = header.args.pos.get::<Spanned<(FontWeight, bool)>>(&mut f.problems) + let weight = header.args.pos.get::<Spanned<(FontWeight, bool)>>(&mut f.diagnostics) .map(|Spanned { v: (weight, is_clamped), span }| { if is_clamped { warning!( @@ -96,7 +95,7 @@ function! { weight }) - .or_missing(&mut f.problems, header.name.span, "weight"); + .or_missing(&mut f.diagnostics, header.name.span, "weight"); FontWeightFunc { body, weight } } @@ -111,25 +110,25 @@ function! { #[derive(Debug, Clone, PartialEq)] pub struct FontSizeFunc { body: Option<SyntaxModel>, - size: Option<FSize>, + size: Option<ScaleLength>, } parse(header, body, ctx, f) { FontSizeFunc { body: body!(opt: body, ctx, f), - size: header.args.pos.get::<FSize>(&mut f.problems) - .or_missing(&mut f.problems, header.name.span, "size") + size: header.args.pos.get::<ScaleLength>(&mut f.diagnostics) + .or_missing(&mut f.diagnostics, header.name.span, "size") } } layout(self, ctx, f) { styled(&self.body, ctx, self.size, |t, s| { match s { - FSize::Absolute(size) => { + ScaleLength::Absolute(size) => { t.base_font_size = size; t.font_scale = 1.0; } - FSize::Scaled(scale) => t.font_scale = scale, + ScaleLength::Scaled(scale) => t.font_scale = scale, } }) } diff --git a/src/library/layout.rs b/src/library/layout.rs index 9fac37b7..2d0e3ac5 100644 --- a/src/library/layout.rs +++ b/src/library/layout.rs @@ -1,7 +1,6 @@ -use crate::size::PSize; +use crate::length::ScaleLength; use super::*; - function! { /// `align`: Aligns content along the layouting axes. #[derive(Debug, Clone, PartialEq)] @@ -13,14 +12,14 @@ function! { parse(header, body, ctx, f) { AlignFunc { body: body!(opt: body, ctx, f), - map: PosAxisMap::parse::<AxisKey>(&mut f.problems, &mut header.args), + map: PosAxisMap::parse::<AxisKey>(&mut f.diagnostics, &mut header.args), } } layout(self, ctx, f) { ctx.base = ctx.spaces[0].dimensions; - let map = self.map.dedup(&mut f.problems, ctx.axes, |alignment| { + let map = self.map.dedup(&mut f.diagnostics, ctx.axes, |alignment| { alignment.axis().map(|s| s.to_generic(ctx.axes)) }); @@ -61,14 +60,14 @@ function! { DirectionFunc { name_span: header.name.span, body: body!(opt: body, ctx, f), - map: PosAxisMap::parse::<AxisKey>(&mut f.problems, &mut header.args), + map: PosAxisMap::parse::<AxisKey>(&mut f.diagnostics, &mut header.args), } } layout(self, ctx, f) { ctx.base = ctx.spaces[0].dimensions; - let map = self.map.dedup(&mut f.problems, ctx.axes, |direction| { + let map = self.map.dedup(&mut f.diagnostics, ctx.axes, |direction| { Some(direction.axis().to_generic(ctx.axes)) }); @@ -103,15 +102,15 @@ function! { #[derive(Debug, Clone, PartialEq)] pub struct BoxFunc { body: SyntaxModel, - extents: AxisMap<PSize>, + extents: AxisMap<ScaleLength>, debug: Option<bool>, } parse(header, body, ctx, f) { BoxFunc { body: body!(opt: body, ctx, f).unwrap_or(SyntaxModel::new()), - extents: AxisMap::parse::<ExtentKey>(&mut f.problems, &mut header.args.key), - debug: header.args.key.get::<bool>(&mut f.problems, "debug"), + extents: AxisMap::parse::<ExtentKey>(&mut f.diagnostics, &mut header.args.key), + debug: header.args.key.get::<bool>(&mut f.diagnostics, "debug"), } } @@ -123,12 +122,12 @@ function! { ctx.debug = debug; } - let map = self.extents.dedup(&mut f.problems, ctx.axes); + let map = self.extents.dedup(&mut f.diagnostics, ctx.axes); for &axis in &[Horizontal, Vertical] { - if let Some(psize) = map.get(axis) { - let size = psize.scaled(ctx.base.get(axis)); - *ctx.base.get_mut(axis) = size; - *ctx.spaces[0].dimensions.get_mut(axis) = size; + if let Some(scale) = map.get(axis) { + let length = scale.scaled(ctx.base.get(axis)); + *ctx.base.get_mut(axis) = length; + *ctx.spaces[0].dimensions.get_mut(axis) = length; *ctx.spaces[0].expansion.get_mut(axis) = true; } } diff --git a/src/library/mod.rs b/src/library/mod.rs index e1aa4ac2..433a4c73 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -8,7 +8,6 @@ pub_use_mod!(layout); pub_use_mod!(page); pub_use_mod!(spacing); - /// Create a scope with all standard functions. pub fn std() -> Scope { let mut std = Scope::new::<ValFunc>(); diff --git a/src/library/page.rs b/src/library/page.rs index 1e782f8f..dd63a0a7 100644 --- a/src/library/page.rs +++ b/src/library/page.rs @@ -1,23 +1,22 @@ -use crate::size::Size; -use crate::style::{Paper, PaperClass}; +use crate::length::Length; +use crate::paper::{Paper, PaperClass}; use super::*; - function! { /// `page.size`: Set the size of pages. #[derive(Debug, Clone, PartialEq)] pub struct PageSizeFunc { paper: Option<Paper>, - extents: AxisMap<Size>, + extents: AxisMap<Length>, flip: bool, } parse(header, body, state, f) { body!(nope: body, f); PageSizeFunc { - paper: header.args.pos.get::<Paper>(&mut f.problems), - extents: AxisMap::parse::<ExtentKey>(&mut f.problems, &mut header.args.key), - flip: header.args.key.get::<bool>(&mut f.problems, "flip").unwrap_or(false), + paper: header.args.pos.get::<Paper>(&mut f.diagnostics), + extents: AxisMap::parse::<ExtentKey>(&mut f.diagnostics, &mut header.args.key), + flip: header.args.key.get::<bool>(&mut f.diagnostics, "flip").unwrap_or(false), } } @@ -26,12 +25,12 @@ function! { if let Some(paper) = self.paper { style.class = paper.class; - style.dimensions = paper.dimensions; + style.dimensions = paper.size(); } else { style.class = PaperClass::Custom; } - let map = self.extents.dedup(&mut f.problems, ctx.axes); + let map = self.extents.dedup(&mut f.diagnostics, ctx.axes); map.with(Horizontal, |&width| style.dimensions.x = width); map.with(Vertical, |&height| style.dimensions.y = height); @@ -53,13 +52,13 @@ function! { parse(header, body, state, f) { body!(nope: body, f); PageMarginsFunc { - padding: PaddingMap::parse(&mut f.problems, &mut header.args), + padding: PaddingMap::parse(&mut f.diagnostics, &mut header.args), } } layout(self, ctx, f) { let mut style = ctx.style.page; - self.padding.apply(&mut f.problems, ctx.axes, &mut style.margins); + self.padding.apply(&mut f.diagnostics, ctx.axes, &mut style.margins); vec![SetPageStyle(style)] } } diff --git a/src/library/spacing.rs b/src/library/spacing.rs index adca20af..5ae25a92 100644 --- a/src/library/spacing.rs +++ b/src/library/spacing.rs @@ -1,10 +1,9 @@ -use crate::size::FSize; +use crate::length::ScaleLength; use crate::layout::SpacingKind; use super::*; use self::ContentKind::*; - function! { /// `line.break`, `n`: Ends the current line. #[derive(Debug, Default, Clone, PartialEq)] @@ -41,7 +40,7 @@ function! { pub struct ContentSpacingFunc { body: Option<SyntaxModel>, content: ContentKind, - spacing: Option<f32>, + spacing: Option<f64>, } type Meta = ContentKind; @@ -50,9 +49,9 @@ function! { ContentSpacingFunc { body: body!(opt: body, state, f), content: meta, - spacing: header.args.pos.get::<f64>(&mut f.problems) - .map(|num| num as f32) - .or_missing(&mut f.problems, header.name.span, "spacing"), + spacing: header.args.pos.get::<f64>(&mut f.diagnostics) + .map(|num| num as f64) + .or_missing(&mut f.diagnostics, header.name.span, "spacing"), } } @@ -79,7 +78,7 @@ function! { /// `spacing`, `h`, `v`: Adds spacing along an axis. #[derive(Debug, Clone, PartialEq)] pub struct SpacingFunc { - spacing: Option<(AxisKey, FSize)>, + spacing: Option<(AxisKey, ScaleLength)>, } type Meta = Option<SpecificAxis>; @@ -88,11 +87,11 @@ function! { body!(nope: body, f); SpacingFunc { spacing: if let Some(axis) = meta { - header.args.pos.get::<FSize>(&mut f.problems) + header.args.pos.get::<ScaleLength>(&mut f.diagnostics) .map(|s| (AxisKey::Specific(axis), s)) } else { - header.args.key.get_with_key::<AxisKey, FSize>(&mut f.problems) - }.or_missing(&mut f.problems, header.name.span, "spacing"), + header.args.key.get_with_key::<AxisKey, ScaleLength>(&mut f.diagnostics) + }.or_missing(&mut f.diagnostics, header.name.span, "spacing"), } } |
