summaryrefslogtreecommitdiff
path: root/src/library/elements.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-19 15:31:29 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-19 15:52:15 +0200
commita6f260ca39f70f82617eca87855789413715f47d (patch)
tree08141ae619bd21e0544d21433bce759aebc7ba83 /src/library/elements.rs
parentfdab7158c91c52a4ace211c804fdd8e9110f56de (diff)
Refactor layouting a bit
Notably: - Handle aspect ratio in fixed node - Inline constraint inflation into pad node
Diffstat (limited to 'src/library/elements.rs')
-rw-r--r--src/library/elements.rs36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/library/elements.rs b/src/library/elements.rs
index f90363bb..6e71626a 100644
--- a/src/library/elements.rs
+++ b/src/library/elements.rs
@@ -64,18 +64,19 @@ fn rect_impl(
body: Template,
) -> Value {
Value::Template(Template::from_inline(move |state| {
- let mut stack = body.to_stack(state);
- stack.aspect = aspect;
-
- let mut node = FixedNode { width, height, child: stack.into() }.into();
+ let mut node = LayoutNode::new(FixedNode {
+ width,
+ height,
+ aspect,
+ child: body.to_stack(state).into(),
+ });
if let Some(fill) = fill {
- node = BackgroundNode {
+ node = LayoutNode::new(BackgroundNode {
shape: BackgroundShape::Rect,
fill: Paint::Color(fill),
child: node,
- }
- .into();
+ });
}
node
@@ -120,27 +121,22 @@ fn ellipse_impl(
// perfectly into the ellipse.
const PAD: f64 = 0.5 - SQRT_2 / 4.0;
- let mut stack = body.to_stack(state);
- stack.aspect = aspect;
-
- let mut node = FixedNode {
+ let mut node = LayoutNode::new(FixedNode {
width,
height,
- child: PadNode {
+ aspect,
+ child: LayoutNode::new(PadNode {
padding: Sides::splat(Relative::new(PAD).into()),
- child: stack.into(),
- }
- .into(),
- }
- .into();
+ child: body.to_stack(state).into(),
+ }),
+ });
if let Some(fill) = fill {
- node = BackgroundNode {
+ node = LayoutNode::new(BackgroundNode {
shape: BackgroundShape::Ellipse,
fill: Paint::Color(fill),
child: node,
- }
- .into();
+ });
}
node