summaryrefslogtreecommitdiff
path: root/src/library/boxed.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-07 17:07:44 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-07 17:07:44 +0200
commit537545e7f8351d7677c396456e46568f5a5e2a7a (patch)
treef4c7614293246db06c7fa7496458da01b15c3b84 /src/library/boxed.rs
parentca1256c924f3672feb76dbc2bc2e309eb4fc4cf5 (diff)
Evaluation and node-based layouting 🚀
Diffstat (limited to 'src/library/boxed.rs')
-rw-r--r--src/library/boxed.rs52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/library/boxed.rs b/src/library/boxed.rs
index b88f5b7c..6edb3b17 100644
--- a/src/library/boxed.rs
+++ b/src/library/boxed.rs
@@ -1,4 +1,5 @@
use crate::geom::Linear;
+use crate::layout::nodes::{Fixed, Stack};
use crate::prelude::*;
/// `box`: Layouts its contents into a box.
@@ -6,34 +7,37 @@ use crate::prelude::*;
/// # Keyword arguments
/// - `width`: The width of the box (length or relative to parent's width).
/// - `height`: The height of the box (length or relative to parent's height).
-pub async fn boxed(mut args: Args, ctx: &mut LayoutContext) -> Value {
+pub fn boxed(mut args: Args, ctx: &mut EvalContext) -> Value {
let body = args.find::<SynTree>().unwrap_or_default();
let width = args.get::<_, Linear>(ctx, "width");
let height = args.get::<_, Linear>(ctx, "height");
args.done(ctx);
+ let dirs = ctx.state.dirs;
let aligns = ctx.state.aligns;
- let constraints = &mut ctx.constraints;
- constraints.base = constraints.spaces[0].size;
- constraints.spaces.truncate(1);
- constraints.repeat = false;
-
- if let Some(width) = width {
- let abs = width.eval(constraints.base.width);
- constraints.base.width = abs;
- constraints.spaces[0].size.width = abs;
- constraints.spaces[0].expansion.horizontal = true;
- }
-
- if let Some(height) = height {
- let abs = height.eval(constraints.base.height);
- constraints.base.height = abs;
- constraints.spaces[0].size.height = abs;
- constraints.spaces[0].expansion.vertical = true;
- }
-
- let layouted = layout_tree(&body, ctx).await;
- let layout = layouted.into_iter().next().unwrap();
-
- Value::Commands(vec![Add(layout, aligns)])
+
+ let snapshot = ctx.state.clone();
+
+ ctx.start_group(());
+ ctx.start_par_group();
+
+ body.eval(ctx);
+
+ ctx.end_par_group();
+ let ((), children) = ctx.end_group();
+
+ ctx.push(Fixed {
+ width,
+ height,
+ child: LayoutNode::dynamic(Stack {
+ dirs,
+ children,
+ aligns,
+ expand: Spec2::new(width.is_some(), height.is_some()),
+ }),
+ });
+
+ ctx.state = snapshot;
+
+ Value::None
}