nannou icon indicating copy to clipboard operation
nannou copied to clipboard

Rounded corners on rect Issue #849, absolute values on height and width

Open dwcarr opened this issue 2 years ago • 0 comments

Implemented rounded corners on rects with the addition of a corner_radius option attribute on the rect struct in rect.rs. If the corner_radius is None, this reduces to the same code as the base version.

Added the necessary boilerplate for mapping the corner_radius to the drawing attributes.

The approach for producing the rounded vertices used was similar to that employed in the ellipse primitive, where a SvgBuilder was implemented to construct the rectangle path.

In the course of this I found that the height and width properties on Dimensions were specified to be absolute values, but this was not being enforced, which led to unpredictable operation. (The example provided in draw.rs, link below, for instance, provides a negative value to the w function). I applied abs to each of these properties.

The draw.rs example was modified to demonstrate the new functionality, with the final rect demonstrating dynamic updates of the corner_radius, including setting radius to None (which produces results identical to the original behavior).

Project built and all examples ran successfully with 1.63.0 on Mac OS.

I am new to this library and to rust, so don't hesitate to give additional guidance.

dwcarr avatar Sep 07 '22 21:09 dwcarr