summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-14 06:49:15 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-14 06:49:15 +0200
commitc545af35773307d16eca7ec03ed4794f26491da2 (patch)
treec8bdb7f54cfbdaaeec079ade9c9ea991f38f0c20 /wgpu
parent5c923fce4866bcda0d2d2c1023bb046cd92038cc (diff)
downloadiced-c545af35773307d16eca7ec03ed4794f26491da2.tar.gz
iced-c545af35773307d16eca7ec03ed4794f26491da2.tar.bz2
iced-c545af35773307d16eca7ec03ed4794f26491da2.zip
Implement `canvas::Path::rectangle` helper method
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/widget/canvas/path.rs10
-rw-r--r--wgpu/src/widget/canvas/path/builder.rs13
2 files changed, 18 insertions, 5 deletions
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
diff --git a/wgpu/src/widget/canvas/path/builder.rs b/wgpu/src/widget/canvas/path/builder.rs
index a013149e..6511fa52 100644
--- a/wgpu/src/widget/canvas/path/builder.rs
+++ b/wgpu/src/widget/canvas/path/builder.rs
@@ -133,11 +133,14 @@ impl Builder {
///
/// [`Path`]: struct.Path.html
#[inline]
- pub fn rectangle(&mut self, p: Point, size: Size) {
- self.move_to(p);
- self.line_to(Point::new(p.x + size.width, p.y));
- self.line_to(Point::new(p.x + size.width, p.y + size.height));
- self.line_to(Point::new(p.x, p.y + size.height));
+ pub fn rectangle(&mut self, top_left: Point, size: Size) {
+ self.move_to(top_left);
+ self.line_to(Point::new(top_left.x + size.width, top_left.y));
+ self.line_to(Point::new(
+ top_left.x + size.width,
+ top_left.y + size.height,
+ ));
+ self.line_to(Point::new(top_left.x, top_left.y + size.height));
self.close();
}