1//! Build different kinds of 2D shapes.
2pub mod arc;
34mod builder;
56#[doc(no_inline)]
7pub use arc::Arc;
8pub use builder::Builder;
910pub use lyon_path;
1112use crate::core::border;
13use crate::core::{Point, Size};
1415/// An immutable set of points that may or may not be connected.
16///
17/// A single [`Path`] can represent different kinds of 2D shapes!
18#[derive(Debug, Clone)]
19pub struct Path {
20 raw: lyon_path::Path,
21}
2223impl Path {
24/// Creates a new [`Path`] with the provided closure.
25 ///
26 /// Use the [`Builder`] to configure your [`Path`].
27pub fn new(f: impl FnOnce(&mut Builder)) -> Self {
28let mut builder = Builder::new();
2930// TODO: Make it pure instead of side-effect-based (?)
31f(&mut builder);
3233 builder.build()
34 }
3536/// Creates a new [`Path`] representing a line segment given its starting
37 /// and end points.
38pub fn line(from: Point, to: Point) -> Self {
39Self::new(|p| {
40 p.move_to(from);
41 p.line_to(to);
42 })
43 }
4445/// Creates a new [`Path`] representing a rectangle given its top-left
46 /// corner coordinate and its `Size`.
47pub fn rectangle(top_left: Point, size: Size) -> Self {
48Self::new(|p| p.rectangle(top_left, size))
49 }
5051/// Creates a new [`Path`] representing a rounded rectangle given its top-left
52 /// corner coordinate, its [`Size`] and [`border::Radius`].
53pub fn rounded_rectangle(
54 top_left: Point,
55 size: Size,
56 radius: border::Radius,
57 ) -> Self {
58Self::new(|p| p.rounded_rectangle(top_left, size, radius))
59 }
6061/// Creates a new [`Path`] representing a circle given its center
62 /// coordinate and its radius.
63pub fn circle(center: Point, radius: f32) -> Self {
64Self::new(|p| p.circle(center, radius))
65 }
6667/// Returns the internal [`lyon_path::Path`].
68#[inline]
69pub fn raw(&self) -> &lyon_path::Path {
70&self.raw
71 }
7273/// Returns the current [`Path`] with the given transform applied to it.
74#[inline]
75pub fn transform(&self, transform: &lyon_path::math::Transform) -> Path {
76 Path {
77 raw: self.raw.clone().transformed(transform),
78 }
79 }
80}