diff options
| author | Martin Haug <mhaug@live.de> | 2022-05-03 11:40:27 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2022-05-03 12:59:41 +0200 |
| commit | 6a8a0ec6ec8bb8cf346ee0dd2c45ddcfbee7fbe6 (patch) | |
| tree | 0d8716d2fa0c01a2319bb84be0283253bc6490fe /src/library/graphics | |
| parent | 33213abe7dfcb8d8065faadd2f5b72ec4b718af1 (diff) | |
Code Review: Heap is Stack. Unsafe is Good.
Spaghetti Code is Style.
Diffstat (limited to 'src/library/graphics')
| -rw-r--r-- | src/library/graphics/shape.rs | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs index a5523a2e..40b6e1e3 100644 --- a/src/library/graphics/shape.rs +++ b/src/library/graphics/shape.rs @@ -78,7 +78,7 @@ impl<const S: ShapeKind> ShapeNode<S> { styles.set_opt(Self::INSET, args.named("inset")?); styles.set_opt(Self::OUTSET, args.named("outset")?); - if S != CIRCLE { + if !is_round(S) { styles.set_opt(Self::RADIUS, args.named("radius")?); } @@ -97,10 +97,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { if let Some(child) = &self.0 { let mut inset = styles.get(Self::INSET); if is_round(S) { - inset = inset.map(|mut side| { - side.rel += Ratio::new(0.5 - SQRT_2 / 4.0); - side - }); + inset = inset.map(|side| side + Ratio::new(0.5 - SQRT_2 / 4.0)); } // Pad the child. @@ -158,18 +155,8 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { } }; - let outset = styles.get(Self::OUTSET); - let outset = Sides { - left: outset.left.relative_to(frame.size.x), - top: outset.top.relative_to(frame.size.y), - right: outset.right.relative_to(frame.size.x), - bottom: outset.bottom.relative_to(frame.size.y), - }; - - let size = Spec::new( - frame.size.x + outset.left + outset.right, - frame.size.y + outset.top + outset.bottom, - ); + let outset = styles.get(Self::OUTSET).relative_to(frame.size); + let size = frame.size + outset.sum_by_axis(); let radius = styles .get(Self::RADIUS) @@ -186,11 +173,12 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { }; frame.prepend(pos, Element::Shape(shape)); } else { - for shape in - Rect::new(size, radius).shapes(fill, stroke).into_iter().rev() - { - frame.prepend(pos, Element::Shape(shape)); - } + frame.prepend_multiple( + Rect::new(size, radius) + .shapes(fill, stroke) + .into_iter() + .map(|x| (pos, Element::Shape(x))), + ) } } |
