diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-08 17:08:30 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-09 12:02:35 +0200 |
| commit | 29eb13ca6214461a4b0deb63d589cd39ad6d41c2 (patch) | |
| tree | c86797d440cfcc801c87a3c64f479e39f2c068b1 /src/library/graphics | |
| parent | 712c00ecb72b67da2c0788e5d3eb4dcc6366b2a7 (diff) | |
Sum color and length into stroke
Diffstat (limited to 'src/library/graphics')
| -rw-r--r-- | src/library/graphics/line.rs | 17 | ||||
| -rw-r--r-- | src/library/graphics/shape.rs | 15 |
2 files changed, 11 insertions, 21 deletions
diff --git a/src/library/graphics/line.rs b/src/library/graphics/line.rs index 1dd138e6..de2e4aa1 100644 --- a/src/library/graphics/line.rs +++ b/src/library/graphics/line.rs @@ -12,10 +12,8 @@ pub struct LineNode { #[node] impl LineNode { /// How to stroke the line. - pub const STROKE: Paint = Color::BLACK.into(); - /// The line's thickness. - #[property(resolve)] - pub const THICKNESS: RawLength = Length::pt(1.0).into(); + #[property(resolve, fold)] + pub const STROKE: RawStroke = RawStroke::default(); fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let origin = args.named("origin")?.unwrap_or_default(); @@ -46,11 +44,7 @@ impl Layout for LineNode { regions: &Regions, styles: StyleChain, ) -> TypResult<Vec<Arc<Frame>>> { - let thickness = styles.get(Self::THICKNESS); - let stroke = Some(Stroke { - paint: styles.get(Self::STROKE), - thickness, - }); + let stroke = styles.get(Self::STROKE).unwrap_or_default(); let origin = self .origin @@ -64,11 +58,10 @@ impl Layout for LineNode { .zip(regions.base) .map(|(l, b)| l.relative_to(b)); - let geometry = Geometry::Line(delta.to_point()); - let shape = Shape { geometry, fill: None, stroke }; - let target = regions.expand.select(regions.first, Size::zero()); let mut frame = Frame::new(target); + + let shape = Geometry::Line(delta.to_point()).stroked(stroke); frame.push(origin.to_point(), Element::Shape(shape)); Ok(vec![Arc::new(frame)]) diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs index ec6f735b..a159a3af 100644 --- a/src/library/graphics/shape.rs +++ b/src/library/graphics/shape.rs @@ -24,10 +24,8 @@ impl<const S: ShapeKind> ShapeNode<S> { /// How to fill the shape. pub const FILL: Option<Paint> = None; /// How to stroke the shape. - pub const STROKE: Smart<Option<Paint>> = Smart::Auto; - /// The stroke's thickness. - #[property(resolve)] - pub const THICKNESS: RawLength = Length::pt(1.0).into(); + #[property(resolve, fold)] + pub const STROKE: Smart<Option<RawStroke>> = Smart::Auto; /// How much to pad the shape's content. pub const PADDING: Relative<RawLength> = Relative::zero(); @@ -115,11 +113,10 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { // Add fill and/or stroke. let fill = styles.get(Self::FILL); - let thickness = styles.get(Self::THICKNESS); - let stroke = styles - .get(Self::STROKE) - .unwrap_or(fill.is_none().then(|| Color::BLACK.into())) - .map(|paint| Stroke { paint, thickness }); + let stroke = match styles.get(Self::STROKE) { + Smart::Auto => fill.is_none().then(Stroke::default), + Smart::Custom(stroke) => stroke.map(RawStroke::unwrap_or_default), + }; if fill.is_some() || stroke.is_some() { let geometry = if is_round(S) { |
