summaryrefslogtreecommitdiff
path: root/src/library/page.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-04 19:34:29 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-04 19:35:28 +0100
commit9fb31defd037a90bf8f9e38fa33acae23a70b269 (patch)
treee0fd887792a59cbb3262a5d3157d0c786df56d60 /src/library/page.rs
parentace57c34206a13b4bc3885b944cc51e274f30b0f (diff)
Expand functionality of function! macro 🛰
Diffstat (limited to 'src/library/page.rs')
-rw-r--r--src/library/page.rs79
1 files changed, 0 insertions, 79 deletions
diff --git a/src/library/page.rs b/src/library/page.rs
deleted file mode 100644
index e8a80870..00000000
--- a/src/library/page.rs
+++ /dev/null
@@ -1,79 +0,0 @@
-use crate::func::prelude::*;
-
-/// `page.break`: Ends the current page.
-#[derive(Debug, PartialEq)]
-pub struct PageBreak;
-
-function! {
- data: PageBreak,
- parse: plain,
- layout(_, _) { Ok(vec![FinishSpace]) }
-}
-
-/// `page.size`: Set the size of pages.
-#[derive(Debug, PartialEq)]
-pub struct PageSize {
- width: Option<Size>,
- height: Option<Size>,
-}
-
-function! {
- data: PageSize,
-
- parse(args, body, _ctx) {
- parse!(forbidden: body);
- Ok(PageSize {
- width: args.get_key_opt::<ArgSize>("width")?.map(|a| a.val),
- height: args.get_key_opt::<ArgSize>("height")?.map(|a| a.val),
- })
- }
-
- layout(this, ctx) {
- let mut style = ctx.style.page;
-
- if let Some(width) = this.width { style.dimensions.x = width; }
- if let Some(height) = this.height { style.dimensions.y = height; }
-
- Ok(vec![SetPageStyle(style)])
- }
-}
-
-/// `page.margins`: Set the margins of pages.
-#[derive(Debug, PartialEq)]
-pub struct PageMargins {
- left: Option<Size>,
- top: Option<Size>,
- right: Option<Size>,
- bottom: Option<Size>,
-}
-
-function! {
- data: PageMargins,
-
- parse(args, body, _ctx) {
- parse!(forbidden: body);
- let default = args.get_pos_opt::<ArgSize>()?;
- let mut get = |which| {
- args.get_key_opt::<ArgSize>(which)
- .map(|size| size.or(default).map(|a| a.val))
- };
-
- Ok(PageMargins {
- left: get("left")?,
- top: get("top")?,
- right: get("right")?,
- bottom: get("bottom")?,
- })
- }
-
- layout(this, ctx) {
- let mut style = ctx.style.page;
-
- if let Some(left) = this.left { style.margins.left = left; }
- if let Some(top) = this.top { style.margins.top = top; }
- if let Some(right) = this.right { style.margins.right = right; }
- if let Some(bottom) = this.bottom { style.margins.bottom = bottom; }
-
- Ok(vec![SetPageStyle(style)])
- }
-}