From 6a8a0ec6ec8bb8cf346ee0dd2c45ddcfbee7fbe6 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Tue, 3 May 2022 11:40:27 +0200 Subject: Code Review: Heap is Stack. Unsafe is Good. Spaghetti Code is Style. --- src/library/graphics/shape.rs | 32 ++++++++++---------------------- src/library/layout/page.rs | 5 ++--- 2 files changed, 12 insertions(+), 25 deletions(-) (limited to 'src/library') 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 ShapeNode { 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 Layout for ShapeNode { 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 Layout for ShapeNode { } }; - 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 Layout for ShapeNode { }; 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))), + ) } } diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs index 801a137d..c8495e64 100644 --- a/src/library/layout/page.rs +++ b/src/library/layout/page.rs @@ -20,7 +20,8 @@ impl PageNode { /// The page margin. #[property(fold)] - pub const MARGINS: Sides>> = Sides::splat(Smart::Auto); + pub const MARGINS: Sides>>> = + Sides::splat(Smart::Auto); /// How many columns the page has. pub const COLUMNS: NonZeroUsize = NonZeroUsize::new(1).unwrap(); @@ -48,9 +49,7 @@ impl PageNode { styles.set_opt(Self::WIDTH, args.named("width")?); styles.set_opt(Self::HEIGHT, args.named("height")?); - styles.set_opt(Self::MARGINS, args.named("margins")?); - styles.set_opt(Self::FLIPPED, args.named("flipped")?); styles.set_opt(Self::FILL, args.named("fill")?); styles.set_opt(Self::COLUMNS, args.named("columns")?); -- cgit v1.2.3