summaryrefslogtreecommitdiff
path: root/src/library/spacing.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-04 19:34:29 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-04 19:35:28 +0100
commit9fb31defd037a90bf8f9e38fa33acae23a70b269 (patch)
treee0fd887792a59cbb3262a5d3157d0c786df56d60 /src/library/spacing.rs
parentace57c34206a13b4bc3885b944cc51e274f30b0f (diff)
Expand functionality of function! macro 🛰
Diffstat (limited to 'src/library/spacing.rs')
-rw-r--r--src/library/spacing.rs71
1 files changed, 0 insertions, 71 deletions
diff --git a/src/library/spacing.rs b/src/library/spacing.rs
deleted file mode 100644
index 47fe9fff..00000000
--- a/src/library/spacing.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-use crate::func::prelude::*;
-
-/// `line.break`, `n`: Ends the current line.
-#[derive(Debug, PartialEq)]
-pub struct LineBreak;
-
-function! {
- data: LineBreak,
- parse: plain,
- layout(_, _) { Ok(vec![FinishLine]) }
-}
-
-/// `paragraph.break`: Ends the current paragraph.
-///
-/// This has the same effect as two subsequent newlines.
-#[derive(Debug, PartialEq)]
-pub struct ParagraphBreak;
-
-function! {
- data: ParagraphBreak,
- parse: plain,
- layout(_, _) { Ok(vec![BreakParagraph]) }
-}
-
-macro_rules! space_func {
- ($ident:ident, $doc:expr, $var:ident => $command:expr) => (
- #[doc = $doc]
- #[derive(Debug, PartialEq)]
- pub struct $ident(Spacing);
-
- function! {
- data: $ident,
-
- parse(args, body, _ctx) {
- parse!(forbidden: body);
-
- let arg = args.get_pos::<ArgExpr>()?;
- let spacing = match arg.val {
- Expression::Size(s) => Spacing::Absolute(*s),
- Expression::Num(f) => Spacing::Relative(*f as f32),
- _ => perr!("invalid spacing, expected size or number"),
- };
-
- Ok($ident(spacing))
- }
-
- layout(this, ctx) {
- let $var = match this.0 {
- Spacing::Absolute(s) => s,
- Spacing::Relative(f) => f * ctx.style.text.font_size,
- };
-
- Ok(vec![$command])
- }
- }
- );
-}
-
-/// Absolute or font-relative spacing.
-#[derive(Debug, PartialEq)]
-enum Spacing {
- Absolute(Size),
- Relative(f32),
-}
-
-// FIXME: h != primary and v != secondary.
-space_func!(HorizontalSpace, "📖 `h`: Adds horizontal whitespace.",
- space => AddSpacing(space, SpacingKind::Hard, AxisKind::Primary));
-
-space_func!(VerticalSpace, "📑 `v`: Adds vertical whitespace.",
- space => AddSpacing(space, SpacingKind::Hard, AxisKind::Secondary));