diff options
author | 2020-04-15 05:43:40 +0200 | |
---|---|---|
committer | 2020-04-15 05:43:40 +0200 | |
commit | 99352f02fd39250475861209d85f696b50ec9b73 (patch) | |
tree | 3bba2a04eb940bee50551601deceebbb8e1c1d8f /wgpu/src/widget/canvas/path.rs | |
parent | d0ebcdb9365b47bc28963759499f0c889f90f90f (diff) | |
parent | 6d7f2b30cc9fd4022681f766ee3b77cdb6c8de0a (diff) | |
download | iced-99352f02fd39250475861209d85f696b50ec9b73.tar.gz iced-99352f02fd39250475861209d85f696b50ec9b73.tar.bz2 iced-99352f02fd39250475861209d85f696b50ec9b73.zip |
Merge pull request #293 from hecrj/improvement/canvas-ergonomics
Improve `Canvas` ergonomics
Diffstat (limited to 'wgpu/src/widget/canvas/path.rs')
-rw-r--r-- | wgpu/src/widget/canvas/path.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/wgpu/src/widget/canvas/path.rs b/wgpu/src/widget/canvas/path.rs index e7ff47f3..c26bf187 100644 --- a/wgpu/src/widget/canvas/path.rs +++ b/wgpu/src/widget/canvas/path.rs @@ -7,6 +7,8 @@ mod builder; pub use arc::Arc; pub use builder::Builder; +use iced_native::{Point, Size}; + /// An immutable set of points that may or may not be connected. /// /// A single [`Path`] can represent different kinds of 2D shapes! @@ -33,6 +35,33 @@ impl Path { builder.build() } + /// Creates a new [`Path`] representing a line segment given its starting + /// and end points. + /// + /// [`Path`]: struct.Path.html + pub fn line(from: Point, to: Point) -> Self { + Self::new(|p| { + p.move_to(from); + p.line_to(to); + }) + } + + /// Creates a new [`Path`] representing a rectangle given its top-left + /// corner coordinate and its `Size`. + /// + /// [`Path`]: struct.Path.html + pub fn rectangle(top_left: Point, size: Size) -> Self { + Self::new(|p| p.rectangle(top_left, size)) + } + + /// Creates a new [`Path`] representing a circle given its center + /// coordinate and its radius. + /// + /// [`Path`]: struct.Path.html + pub fn circle(center: Point, radius: f32) -> Self { + Self::new(|p| p.circle(center, radius)) + } + #[inline] pub(crate) fn raw(&self) -> &lyon::path::Path { &self.raw |