From c545af35773307d16eca7ec03ed4794f26491da2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Apr 2020 06:49:15 +0200 Subject: Implement `canvas::Path::rectangle` helper method --- wgpu/src/widget/canvas/path.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'wgpu/src/widget/canvas/path.rs') diff --git a/wgpu/src/widget/canvas/path.rs b/wgpu/src/widget/canvas/path.rs index e7ff47f3..d714ad05 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,14 @@ impl Path { builder.build() } + /// 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)) + } + #[inline] pub(crate) fn raw(&self) -> &lyon::path::Path { &self.raw -- cgit From 46cd0891d25c2dd48e182747d8c1f9579b066490 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Apr 2020 06:54:12 +0200 Subject: Implement `canvas::Path::circle` helper method --- wgpu/src/widget/canvas/path.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'wgpu/src/widget/canvas/path.rs') diff --git a/wgpu/src/widget/canvas/path.rs b/wgpu/src/widget/canvas/path.rs index d714ad05..19d8879a 100644 --- a/wgpu/src/widget/canvas/path.rs +++ b/wgpu/src/widget/canvas/path.rs @@ -43,6 +43,14 @@ impl Path { 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 -- cgit From 3df49bebd47e8ff7c54934d6474336b7439176f9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Apr 2020 07:08:12 +0200 Subject: Implement `canvas::Path::line` helper method --- wgpu/src/widget/canvas/path.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'wgpu/src/widget/canvas/path.rs') diff --git a/wgpu/src/widget/canvas/path.rs b/wgpu/src/widget/canvas/path.rs index 19d8879a..c26bf187 100644 --- a/wgpu/src/widget/canvas/path.rs +++ b/wgpu/src/widget/canvas/path.rs @@ -35,6 +35,17 @@ 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`. /// -- cgit