summaryrefslogtreecommitdiff
path: root/src/library/style.rs
blob: a63166cff2b8fd559bdc2f5f73b1c8d42a67efda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::func::prelude::*;
use toddle::query::FontClass;

macro_rules! stylefunc {
    ($ident:ident, $doc:expr) => (
        #[doc = $doc]
        #[derive(Debug, PartialEq)]
        pub struct $ident {
            body: Option<SyntaxTree>
        }

        function! {
            data: $ident,

            parse(args, body, ctx) {
                args.done()?;
                Ok($ident { body: parse!(optional: body, ctx) })
            }

            layout(this, ctx) {
                let mut style = ctx.text_style.clone();
                style.toggle_class(FontClass::$ident);

                Ok(match &this.body {
                    Some(body) => commands![
                        SetTextStyle(style),
                        LayoutTree(body),
                        SetTextStyle(ctx.text_style.clone()),
                    ],
                    None => commands![SetTextStyle(style)]
                })
            }
        }
    );
}

stylefunc!(Italic, "`italic`: Sets text in _italics_.");
stylefunc!(Bold, "`bold`: Sets text in **bold**.");
stylefunc!(Monospace, "`mono`: Sets text in `monospace`.");