diff options
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/flow.rs | 4 | ||||
| -rw-r--r-- | src/library/grid.rs | 2 | ||||
| -rw-r--r-- | src/library/pad.rs | 5 | ||||
| -rw-r--r-- | src/library/shape.rs | 41 | ||||
| -rw-r--r-- | src/library/sized.rs | 18 | ||||
| -rw-r--r-- | src/library/stack.rs | 2 | ||||
| -rw-r--r-- | src/library/transform.rs | 2 |
7 files changed, 35 insertions, 39 deletions
diff --git a/src/library/flow.rs b/src/library/flow.rs index c41fb62c..25162d19 100644 --- a/src/library/flow.rs +++ b/src/library/flow.rs @@ -27,9 +27,7 @@ pub fn flow(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { .iter() .map(|child| match child { Child::Spacing(spacing) => FlowChild::Spacing(*spacing), - Child::Any(child) => { - FlowChild::Node(child.to_flow(style).pack(), style.aligns.block) - } + Child::Any(node) => FlowChild::Node(node.pack(style), style.aligns.block), }) .collect(); diff --git a/src/library/grid.rs b/src/library/grid.rs index 692ed210..62c10e5a 100644 --- a/src/library/grid.rs +++ b/src/library/grid.rs @@ -45,7 +45,7 @@ pub fn grid(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { GridNode { tracks: tracks.clone(), gutter: gutter.clone(), - children: children.iter().map(|child| child.to_flow(style).pack()).collect(), + children: children.iter().map(|child| child.pack(style)).collect(), } }))) } diff --git a/src/library/pad.rs b/src/library/pad.rs index 88f8c562..1ec1b4a2 100644 --- a/src/library/pad.rs +++ b/src/library/pad.rs @@ -17,10 +17,7 @@ pub fn pad(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { ); Ok(Value::Template(Template::from_inline(move |style| { - PadNode { - padding, - child: body.to_flow(style).pack(), - } + PadNode { padding, child: body.pack(style) } }))) } diff --git a/src/library/shape.rs b/src/library/shape.rs index 112987ad..ecf21dc9 100644 --- a/src/library/shape.rs +++ b/src/library/shape.rs @@ -56,21 +56,11 @@ pub fn circle(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { fn shape_impl( kind: ShapeKind, - mut width: Option<Linear>, - mut height: Option<Linear>, + width: Option<Linear>, + height: Option<Linear>, fill: Option<Color>, body: Option<Template>, ) -> Value { - // Set default shape size if there's no body. - if body.is_none() { - let v = Length::pt(30.0).into(); - height.get_or_insert(v); - width.get_or_insert(match kind { - ShapeKind::Square | ShapeKind::Circle => v, - ShapeKind::Rect | ShapeKind::Ellipse => 1.5 * v, - }); - } - // Set default fill if there's no fill. let fill = fill.unwrap_or(Color::Rgba(RgbaColor::gray(175))); @@ -78,7 +68,7 @@ fn shape_impl( let shape = Layout::pack(ShapeNode { kind, fill: Some(Paint::Color(fill)), - child: body.as_ref().map(|body| body.to_flow(style).pack()), + child: body.as_ref().map(|body| body.pack(style)), }); if width.is_some() || height.is_some() { @@ -126,15 +116,15 @@ impl Layout for ShapeNode { let mut frame = if let Some(child) = &self.child { let mut node: &dyn Layout = child; - let padded; + let storage; if matches!(self.kind, ShapeKind::Circle | ShapeKind::Ellipse) { // Padding with this ratio ensures that a rectangular child fits // perfectly into a circle / an ellipse. - padded = PadNode { + storage = PadNode { padding: Sides::splat(Relative::new(0.5 - SQRT_2 / 4.0).into()), child: child.clone(), }; - node = &padded; + node = &storage; } // Now, layout the child. @@ -155,7 +145,24 @@ impl Layout for ShapeNode { assert_eq!(frames.len(), 1); Rc::take(frames.into_iter().next().unwrap().item) } else { - Frame::new(regions.current, regions.current.h) + let default = Length::pt(30.0); + let size = Size::new( + if regions.expand.x && regions.current.w.is_finite() { + regions.current.w + } else { + match self.kind { + ShapeKind::Square | ShapeKind::Circle => default, + ShapeKind::Rect | ShapeKind::Ellipse => 1.5 * default, + } + }, + if regions.expand.y && regions.current.h.is_finite() { + regions.current.h + } else { + default + }, + ); + + Frame::new(size, size.h) }; // Add background shape if desired. diff --git a/src/library/sized.rs b/src/library/sized.rs index 631f9e6f..686d79b9 100644 --- a/src/library/sized.rs +++ b/src/library/sized.rs @@ -6,14 +6,11 @@ pub fn box_(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let height = args.named("height")?; let body: Template = args.find().unwrap_or_default(); Ok(Value::Template(Template::from_inline(move |style| { - let flow = body.to_flow(style).pack(); + let child = body.pack(style); if width.is_some() || height.is_some() { - Layout::pack(SizedNode { - sizing: Spec::new(width, height), - child: flow, - }) + Layout::pack(SizedNode { sizing: Spec::new(width, height), child }) } else { - flow + child } }))) } @@ -24,14 +21,11 @@ pub fn block(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { let height = args.named("height")?; let body: Template = args.find().unwrap_or_default(); Ok(Value::Template(Template::from_block(move |style| { - let flow = body.to_flow(style).pack(); + let child = body.pack(style); if width.is_some() || height.is_some() { - Layout::pack(SizedNode { - sizing: Spec::new(width, height), - child: flow, - }) + Layout::pack(SizedNode { sizing: Spec::new(width, height), child }) } else { - flow + child } }))) } diff --git a/src/library/stack.rs b/src/library/stack.rs index dec5ec2d..b97964db 100644 --- a/src/library/stack.rs +++ b/src/library/stack.rs @@ -40,7 +40,7 @@ pub fn stack(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { children.push(StackChild::Spacing(v)); } - let node = child.to_flow(style).pack(); + let node = child.pack(style); children.push(StackChild::Node(node)); delayed = spacing; } diff --git a/src/library/transform.rs b/src/library/transform.rs index 20d2bc1d..85d65703 100644 --- a/src/library/transform.rs +++ b/src/library/transform.rs @@ -9,7 +9,7 @@ pub fn move_(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { Ok(Value::Template(Template::from_inline(move |style| { MoveNode { offset: Spec::new(x, y), - child: body.to_flow(style).pack(), + child: body.pack(style), } }))) } |
