Skip to content
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 corners on rectangles and images #672

Open
zaddok opened this issue Jun 24, 2024 · 4 comments
Open

Rounded corners on rectangles and images #672

zaddok opened this issue Jun 24, 2024 · 4 comments

Comments

@zaddok
Copy link

zaddok commented Jun 24, 2024

This library is awesome, thanks for all your work on this.

Is it correct to say it's not possible to create a "rounded rect" or "rounded image" (i.e. like CSS border-radius)? Or is it possible and I have missed it?

Can I put in a vote for this one.

@ripytide
Copy link
Member

ripytide commented Jun 24, 2024

Interesting, how would you expect this to work?

Perhaps a function taking a normal rectangular image and then giving it a background color or 0-opacity around the corners at a given radius?

Something like:

fn border_radius<P>(image: &Image<P>, border_radius: f32) -> Image<P> {
    ...
}

Or maybe an explicit background pixel:

fn border_radius<P>(image: &Image<P>, border_radius: f32, background_pixel: P) -> Image<P> {
    ...
}

Or if rgb v0.9 lands then maybe:

fn border_radius<P>(image: &Image<P>, border_radius: f32, background_pixel: P) -> Image<P> 
    where P: HasAlpha
{
    ...
}

@zaddok
Copy link
Author

zaddok commented Jun 24, 2024

Personally, in my opinion, one border_radius applied to all corners is enough. But css (and some other rust libraries) support border radius on individual corners, i.e.

https://docs.rs/kurbo/latest/kurbo/struct.RoundedRect.html

@ripytide
Copy link
Member

Yep that sounds reasonable, so something like:

//copied from kurbo
pub struct RoundedRectRadii {
    pub top_left: f64,
    pub top_right: f64,
    pub bottom_right: f64,
    pub bottom_left: f64,
}

pub fn rounded_corners<P>(image: &Image, rounded_rect_radii: RoundedRectRadii) -> Image<P>
    where P: HasAlpha
{
...
}

I must admit this kind of function isn't that high of a priority for me personally, but I have no problems with it being added to the library were someone to make a PR.

@zaddok
Copy link
Author

zaddok commented Jun 25, 2024

Thanks, for now I'll just get the task at hand done with a quick and dirty hack using a custom background png. I'll poke around in the code later and see how hard/easy it might be for me to look at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants