summaryrefslogtreecommitdiff
path: root/src/library/boxed.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/boxed.rs
parentace57c34206a13b4bc3885b944cc51e274f30b0f (diff)
Expand functionality of function! macro 🛰
Diffstat (limited to 'src/library/boxed.rs')
-rw-r--r--src/library/boxed.rs59
1 files changed, 33 insertions, 26 deletions
diff --git a/src/library/boxed.rs b/src/library/boxed.rs
index 8984417c..d4e39450 100644
--- a/src/library/boxed.rs
+++ b/src/library/boxed.rs
@@ -1,37 +1,44 @@
use crate::func::prelude::*;
-/// `box`: Layouts content into a box.
-#[derive(Debug, PartialEq)]
-pub struct Boxed {
- body: SyntaxTree,
- width: Option<Size>,
- height: Option<Size>,
-}
-
function! {
- data: Boxed,
+ /// `box`: Layouts content into a box.
+ #[derive(Debug, PartialEq)]
+ pub struct Boxed {
+ body: SyntaxTree,
+ map: ArgMap<AxisKey, Size>,
+ }
parse(args, body, ctx) {
- let width = args.get_key_opt::<ArgSize>("width")?.map(|a| a.val);
- let height = args.get_key_opt::<ArgSize>("height")?.map(|a| a.val);
- args.done()?;
-
- let body = parse!(required: body, ctx);
- Ok(Boxed {
- body,
- width,
- height,
- })
- }
+ let mut map = ArgMap::new();
+
+ for arg in args.keys() {
+ let key = match arg.val.0.val {
+ "width" | "w" => AxisKey::Horizontal,
+ "height" | "h" => AxisKey::Vertical,
+ "primary-size" => AxisKey::Primary,
+ "secondary-size" => AxisKey::Secondary,
+ _ => pr!("unexpected argument"),
+ };
- layout(this, mut ctx) {
- if let Some(width) = this.width {
- ctx.spaces[0].dimensions.x = width;
+ let size = ArgParser::convert::<ArgSize>(arg.val.1.val)?;
+ map.add(key, size);
}
- if let Some(height) = this.height {
- ctx.spaces[0].dimensions.y = height;
+
+ Boxed {
+ body: parse!(expected: body, ctx),
+ map,
}
+ }
+
+ layout(self, mut ctx) {
+ let map = self.map.dedup(|key, val| {
+ Ok((key.specific(ctx.axes), val))
+ });
+
+ let mut dimensions = &mut ctx.spaces[0].dimensions;
+ map.with(AxisKey::Horizontal, |val| dimensions.x = val);
+ map.with(AxisKey::Vertical, |val| dimensions.y = val);
- Ok(vec![AddMultiple(layout_tree(&this.body, ctx)?)])
+ vec![AddMultiple(layout_tree(&self.body, ctx)?)]
}
}