summaryrefslogtreecommitdiff
path: root/src/library/style.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/style.rs')
-rw-r--r--src/library/style.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/library/style.rs b/src/library/style.rs
new file mode 100644
index 00000000..397375a4
--- /dev/null
+++ b/src/library/style.rs
@@ -0,0 +1,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);