-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rounded rectangle graphics #2491
Conversation
I don't think this approach is flexible enough. For example, I would expect drawing a square with a very high border radius to result in a circle. This is what happens in For example, here's the result of drawing |
Hmm, so what should flexible solution do instead? |
It looks like, at the very least, you want something like: radius = min(radius, min(height / 2, width / 2)) See:
It would also be nice to be able to specify horizontal and vertical radius, and to specify individual radii for each of the 4 corners, by using or extending the existing |
One commit implement just min check, other use Radius as argument, so it is possible to specify different radius for each corner. |
core/src/border.rs
Outdated
@@ -54,7 +54,7 @@ impl Border { | |||
/// The border radii for the corners of a graphics primitive in the order: | |||
/// top-left, top-right, bottom-right, bottom-left. | |||
#[derive(Debug, Clone, Copy, PartialEq, Default)] | |||
pub struct Radius([f32; 4]); | |||
pub struct Radius(pub [f32; 4]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be pub
— the from()
methods can be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, you are right. Fixed.
graphics/src/geometry/path.rs
Outdated
@@ -47,6 +47,12 @@ impl Path { | |||
Self::new(|p| p.rectangle(top_left, size)) | |||
} | |||
|
|||
/// Creates a new [`Path`] representing a rounded rectangle given its top-left | |||
/// corner coordinate, its `Size` and radius. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
its [`Size`] and border [`Radius`]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -160,6 +161,51 @@ impl Builder { | |||
self.close(); | |||
} | |||
|
|||
/// Adds a rounded rectangle to the [`Path`] given its top-left | |||
/// corner coordinate its `Size` and curve radius. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
its [`Size`] and border [`Radius`]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
This looks okay to me right now, but I'm not a maintainer so you'll have to wait for one to look at this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I have removed the example since we already have too many.
This is my attempt to add functionality for additional canvas shape, rounded rectangle.