diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-16 22:14:27 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-16 22:39:21 +0200 |
| commit | 30f16bbf6431ca0c174ca0a1abaa6a13ef50ab06 (patch) | |
| tree | f5a5c0adad15840ebe24b39e77ff467862067c91 /src/library/boxed.rs | |
| parent | 9f6137d8a829fe8f34554623495fa620252a0184 (diff) | |
Add Value type and replace dyn-nodes with call-exprs 🏗
- In addition to syntax trees there are now `Value`s, which syntax trees can be evaluated into (e.g. the tree is `5+5` and the value is `10`)
- Parsing is completely pure, function calls are not parsed into nodes, but into simple call expressions, which are resolved later
- Functions aren't dynamic nodes anymore, but simply functions which receive their arguments as a table and the layouting context
- Functions may return any `Value`
- Layouting is powered by functions which return the new `Commands` value, which informs the layouting engine what to do
- When a function returns a non-`Commands` value, the layouter simply dumps the value into the document in monospace
Diffstat (limited to 'src/library/boxed.rs')
| -rw-r--r-- | src/library/boxed.rs | 60 |
1 files changed, 22 insertions, 38 deletions
diff --git a/src/library/boxed.rs b/src/library/boxed.rs index 3637f072..c03043ae 100644 --- a/src/library/boxed.rs +++ b/src/library/boxed.rs @@ -6,48 +6,32 @@ use super::*; /// # Keyword arguments /// - `width`: The width of the box (length of relative to parent's width). /// - `height`: The height of the box (length of relative to parent's height). -pub fn boxed(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { +pub async fn boxed(mut args: TableValue, mut ctx: LayoutContext<'_>) -> Pass<Value> { let mut f = Feedback::new(); - let mut args = call.args; - let node = BoxNode { - content: args.take::<SyntaxTree>().unwrap_or(SyntaxTree::new()), - width: args.take_with_key::<_, ScaleLength>("width", &mut f), - height: args.take_with_key::<_, ScaleLength>("height", &mut f), - }; + let content = args.take::<SyntaxTree>().unwrap_or(SyntaxTree::new()); + let width = args.take_with_key::<_, ScaleLength>("width", &mut f); + let height = args.take_with_key::<_, ScaleLength>("height", &mut f); args.unexpected(&mut f); - Pass::node(node, f) -} - -#[derive(Debug, Clone, PartialEq)] -struct BoxNode { - content: SyntaxTree, - width: Option<ScaleLength>, - height: Option<ScaleLength>, -} -#[async_trait(?Send)] -impl Layout for BoxNode { - async fn layout<'a>(&'a self, mut ctx: LayoutContext<'_>) -> Pass<Commands<'a>> { - ctx.spaces.truncate(1); - ctx.repeat = false; + ctx.spaces.truncate(1); + ctx.repeat = false; - self.width.with(|v| { - let length = v.raw_scaled(ctx.base.x); - ctx.base.x = length; - ctx.spaces[0].size.x = length; - ctx.spaces[0].expansion.horizontal = true; - }); + width.with(|v| { + let length = v.raw_scaled(ctx.base.x); + ctx.base.x = length; + ctx.spaces[0].size.x = length; + ctx.spaces[0].expansion.horizontal = true; + }); - self.height.with(|v| { - let length = v.raw_scaled(ctx.base.y); - ctx.base.y = length; - ctx.spaces[0].size.y = length; - ctx.spaces[0].expansion.vertical = true; - }); + height.with(|v| { + let length = v.raw_scaled(ctx.base.y); + ctx.base.y = length; + ctx.spaces[0].size.y = length; + ctx.spaces[0].expansion.vertical = true; + }); - layout(&self.content, ctx).await.map(|out| { - let layout = out.into_iter().next().unwrap(); - vec![Add(layout)] - }) - } + let layouted = layout(&content, ctx).await; + let layout = layouted.output.into_iter().next().unwrap(); + f.extend(layouted.feedback); + Pass::commands(vec![Add(layout)], f) } |
