blob: 397375a4879d1a912119041c0a679e09a1c182c4 (
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) => {
/// Styles text.
#[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 new_style = ctx.style.clone();
new_style.toggle_class(FontClass::$ident);
Ok(match &this.body {
Some(body) => commands![
Command::SetStyle(new_style),
Command::Layout(body),
Command::SetStyle(ctx.style.clone()),
],
None => commands![Command::SetStyle(new_style)]
})
}
}
};
}
stylefunc!(Italic);
stylefunc!(Bold);
stylefunc!(Monospace);
|