From 1f7f37e93cbc7d1e9f43911bab847a4748ab1f93 Mon Sep 17 00:00:00 2001 From: amy Date: Mon, 27 May 2024 18:21:43 +1000 Subject: [PATCH 1/2] static rounded rect --- crates/bevy_vello_graphics/src/rect.rs | 13 +++++++++++-- examples/vello_basic.rs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/bevy_vello_graphics/src/rect.rs b/crates/bevy_vello_graphics/src/rect.rs index 93eaaca..b8d20d3 100644 --- a/crates/bevy_vello_graphics/src/rect.rs +++ b/crates/bevy_vello_graphics/src/rect.rs @@ -9,13 +9,15 @@ use super::VelloVector; pub struct VelloRect { pub size: DVec2, pub anchor: DVec2, + pub radius: f64 } impl VelloRect { - pub fn new(width: f64, height: f64) -> Self { + pub fn new(width: f64, height: f64, radius: f64) -> Self { Self { size: DVec2::new(width, height), anchor: DVec2::splat(0.5), + radius, } } @@ -28,15 +30,21 @@ impl VelloRect { self.anchor = DVec2::new(x, y); self } + + pub fn with_radius(mut self, radius: f64) -> Self { + self.radius = radius; + self + } } impl VelloVector for VelloRect { fn shape(&self) -> impl kurbo::Shape { - kurbo::Rect::new( + kurbo::RoundedRect::new( -self.size.x * self.anchor.x, -self.size.y * self.anchor.y, self.size.x * (1.0 - self.anchor.x), self.size.y * (1.0 - self.anchor.y), + self.radius, ) } } @@ -47,6 +55,7 @@ impl F32Lerp for VelloRect { Self { size: DVec2::lerp(self.size, rhs.size, t as f64), anchor: DVec2::lerp(self.anchor, rhs.anchor, t as f64), + radius: self.radius.f32lerp(&rhs.radius, t), } } } diff --git a/examples/vello_basic.rs b/examples/vello_basic.rs index b900cbc..ac6b5d7 100644 --- a/examples/vello_basic.rs +++ b/examples/vello_basic.rs @@ -25,7 +25,7 @@ fn vello_basic(mut commands: Commands) { let mut rect = commands.build_fsvector( Transform::from_xyz(-200.0, 0.0, 0.0), - VelloRect::new(100.0, 100.0), + VelloRect::new(100.0, 100.0, 0.0), Fill::new().with_color(palette.get(ColorKey::Blue)), Stroke::new(4.0).with_color(palette.get(ColorKey::Blue) * 1.5), ); From 701f299788074cee4bca5561d3ecf5bd912483ff Mon Sep 17 00:00:00 2001 From: Nixon <43715558+nixon-voxell@users.noreply.github.com> Date: Tue, 28 May 2024 10:38:38 +0800 Subject: [PATCH 2/2] chore: fix rust fmt --- crates/bevy_vello_graphics/src/rect.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_vello_graphics/src/rect.rs b/crates/bevy_vello_graphics/src/rect.rs index b8d20d3..a9ae59c 100644 --- a/crates/bevy_vello_graphics/src/rect.rs +++ b/crates/bevy_vello_graphics/src/rect.rs @@ -9,7 +9,7 @@ use super::VelloVector; pub struct VelloRect { pub size: DVec2, pub anchor: DVec2, - pub radius: f64 + pub radius: f64, } impl VelloRect {