From ecf0ff4d054f11c79ec0ddbbdf45f3dfcf9fc8d7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 23 Oct 2019 00:14:43 +0200 Subject: =?UTF-8?q?Introduce=20a=20set=20of=20macros=20for=20writing=20fun?= =?UTF-8?q?ctions=20more=20concisely=20=F0=9F=8E=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/styles.rs | 65 --------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 src/library/styles.rs (limited to 'src/library/styles.rs') 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 - } - - impl Function for $struct { - fn parse(header: &FuncHeader, body: Option<&str>, ctx: ParseContext) - -> ParseResult 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 { - 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 -} -- cgit v1.2.3