summaryrefslogtreecommitdiff
path: root/src/library/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-12 11:41:04 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-12 11:41:04 +0100
commite7277fec232b5bc30f7ffe49a123550d1a096cb7 (patch)
tree3f69430fa47f361b0bc507f0be4e372812f75975 /src/library/mod.rs
parenta791ef162868c65284903ab479731e0dc9e7a223 (diff)
Add font size function 🌱
Diffstat (limited to 'src/library/mod.rs')
-rw-r--r--src/library/mod.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 4439f137..342b2721 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -29,6 +29,8 @@ pub fn std() -> Scope {
std.add::<ParBreak>("par.break");
std.add::<PageBreak>("page.break");
+ std.add::<FontSize>("font.size");
+
std.add_with_metadata::<Spacing, Option<AxisKey>>("spacing", None);
for (name, key) in &[("h", AxisKey::Horizontal), ("v", AxisKey::Vertical)] {
@@ -188,3 +190,33 @@ function! {
}
}
}
+
+function! {
+ /// `font.size`: Set the font size.
+ #[derive(Debug, PartialEq)]
+ pub struct FontSize {
+ body: Option<SyntaxTree>,
+ size: Size,
+ }
+
+ parse(args, body, ctx) {
+ FontSize {
+ body: parse!(optional: body, ctx),
+ size: args.get_pos::<Size>()?.v,
+ }
+ }
+
+ layout(self, mut ctx) {
+ let mut style = ctx.style.text.clone();
+ style.font_size = self.size;
+
+ match &self.body {
+ Some(body) => vec![
+ SetTextStyle(style),
+ LayoutTree(body),
+ SetTextStyle(ctx.style.text.clone()),
+ ],
+ None => vec![SetTextStyle(style)]
+ }
+ }
+}