iced icon indicating copy to clipboard operation
iced copied to clipboard

rounded rectangle graphics

Open gintsgints opened this issue 1 year ago • 5 comments

This is my attempt to add functionality for additional canvas shape, rounded rectangle.

gintsgints avatar Jul 02 '24 21:07 gintsgints

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 iced::Border::rounded and also in CSS. However, in your implementation, a buggy shape is drawn.

For example, here's the result of drawing examples/graphics with a radius of 80:

2024-07-04-12-16-51

vladh avatar Jul 04 '24 11:07 vladh

Hmm, so what should flexible solution do instead? I can make radius relative to the width of the rectangle or disallow too big radius.

gintsgints avatar Jul 04 '24 14:07 gintsgints

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:

  • https://www.w3.org/TR/css-backgrounds-3/#the-border-radius
  • https://www.w3.org/Style/CSS/Tracker/issues/29

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 iced::Border::Radius.

vladh avatar Jul 04 '24 15:07 vladh

One commit implement just min check, other use Radius as argument, so it is possible to specify different radius for each corner.

gintsgints avatar Jul 05 '24 06:07 gintsgints

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.

vladh avatar Jul 05 '24 12:07 vladh