diff options
author | 2020-04-14 06:54:12 +0200 | |
---|---|---|
committer | 2020-04-14 06:54:12 +0200 | |
commit | 46cd0891d25c2dd48e182747d8c1f9579b066490 (patch) | |
tree | 0ab07cb96727530b4ea5298d5a22a6a883c25568 | |
parent | c545af35773307d16eca7ec03ed4794f26491da2 (diff) | |
download | iced-46cd0891d25c2dd48e182747d8c1f9579b066490.tar.gz iced-46cd0891d25c2dd48e182747d8c1f9579b066490.tar.bz2 iced-46cd0891d25c2dd48e182747d8c1f9579b066490.zip |
Implement `canvas::Path::circle` helper method
-rw-r--r-- | examples/clock/src/main.rs | 4 | ||||
-rw-r--r-- | examples/solar_system/src/main.rs | 14 | ||||
-rw-r--r-- | wgpu/src/widget/canvas/path.rs | 8 |
3 files changed, 15 insertions, 11 deletions
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs index 1379d3a6..dab91eab 100644 --- a/examples/clock/src/main.rs +++ b/examples/clock/src/main.rs @@ -95,11 +95,13 @@ impl From<chrono::DateTime<chrono::Local>> for LocalTime { impl canvas::Drawable for LocalTime { fn draw(&self, frame: &mut canvas::Frame) { + use canvas::Path; + let center = frame.center(); let radius = frame.width().min(frame.height()) / 2.0; let offset = Vector::new(center.x, center.y); - let clock = canvas::Path::new(|path| path.circle(center, radius)); + let clock = Path::circle(center, radius); frame.fill(&clock, Color::from_rgb8(0x12, 0x93, 0xD8)); diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 067f8ff2..bcd1dc71 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -141,8 +141,8 @@ impl canvas::Drawable for State { } }); - let sun = Path::new(|path| path.circle(center, Self::SUN_RADIUS)); - let orbit = Path::new(|path| path.circle(center, Self::ORBIT_RADIUS)); + let sun = Path::circle(center, Self::SUN_RADIUS); + let orbit = Path::circle(center, Self::ORBIT_RADIUS); frame.fill(&space, Color::BLACK); frame.fill(&stars, Color::WHITE); @@ -168,10 +168,7 @@ impl canvas::Drawable for State { ); frame.translate(Vector::new(Self::ORBIT_RADIUS, 0.0)); - let earth = Path::new(|path| { - path.circle(Point::ORIGIN, Self::EARTH_RADIUS) - }); - + let earth = Path::circle(Point::ORIGIN, Self::EARTH_RADIUS); let shadow = Path::rectangle( Point::new(0.0, -Self::EARTH_RADIUS), Size::new(Self::EARTH_RADIUS * 4.0, Self::EARTH_RADIUS * 2.0), @@ -186,10 +183,7 @@ impl canvas::Drawable for State { ); frame.translate(Vector::new(0.0, Self::MOON_DISTANCE)); - let moon = Path::new(|path| { - path.circle(Point::ORIGIN, Self::MOON_RADIUS) - }); - + let moon = Path::circle(Point::ORIGIN, Self::MOON_RADIUS); frame.fill(&moon, Color::WHITE); }); 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 |