summaryrefslogtreecommitdiff
path: root/src/library/styles.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-23 00:14:43 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-23 00:21:40 +0200
commitecf0ff4d054f11c79ec0ddbbdf45f3dfcf9fc8d7 (patch)
treeefdc76915e5c7f43629aa3aa5d5aa3998d7f5367 /src/library/styles.rs
parentcff325b520727ac0eec46a3757831afaa0916cc1 (diff)
Introduce a set of macros for writing functions more concisely 🎁
Diffstat (limited to 'src/library/styles.rs')
-rw-r--r--src/library/styles.rs65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/library/styles.rs b/src/library/styles.rs
deleted file mode 100644
index bc84ac3b..00000000
--- a/src/library/styles.rs
+++ /dev/null
@@ -1,65 +0,0 @@
-use toddle::query::FontClass;
-
-use super::prelude::*;
-
-macro_rules! style_func {
- (
- $(#[$outer:meta])*
- pub struct $struct:ident { $name:expr },
- $style:ident => $class:ident
- ) => {
- $(#[$outer])*
- #[derive(Debug, PartialEq)]
- pub struct $struct {
- body: Option<SyntaxTree>
- }
-
- impl Function for $struct {
- fn parse(header: &FuncHeader, body: Option<&str>, ctx: ParseContext)
- -> ParseResult<Self> where Self: Sized {
- // Accept only invocations without arguments and with body.
- if has_arguments(header) {
- return err(format!("{}: expected no arguments", $name));
- }
-
- let body = parse_maybe_body(body, ctx)?;
-
- Ok($struct { body })
- }
-
- fn layout(&self, ctx: LayoutContext) -> LayoutResult<CommandList> {
- let mut new_style = ctx.style.clone();
- new_style.toggle_class(FontClass::$class);
-
- if let Some(body) = &self.body {
- let saved_style = ctx.style.clone();
- Ok(commands![
- Command::SetStyle(new_style),
- Command::Layout(body),
- Command::SetStyle(saved_style),
- ])
- } else {
- Ok(commands![Command::SetStyle(new_style)])
- }
- }
- }
- };
-}
-
-style_func! {
- /// Typesets text in bold.
- pub struct BoldFunc { "bold" },
- style => Bold
-}
-
-style_func! {
- /// Typesets text in italics.
- pub struct ItalicFunc { "italic" },
- style => Italic
-}
-
-style_func! {
- /// Typesets text in monospace.
- pub struct MonospaceFunc { "mono" },
- style => Monospace
-}