Skip to content

Commit

Permalink
Merge pull request #48 from aymey/rounded-rect
Browse files Browse the repository at this point in the history
rounded rectangle
  • Loading branch information
nixon-voxell authored May 28, 2024
2 parents 8df1ee3 + 701f299 commit c992078
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions crates/bevy_vello_graphics/src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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,
)
}
}
Expand All @@ -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),
}
}
}
2 changes: 1 addition & 1 deletion examples/vello_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down

0 comments on commit c992078

Please sign in to comment.