I extended my rounded corners implementation to add the ability enable/disable individual sides of the border, set in the new struct
BorderStyle
. The draw function isn't pretty but after several attempts this "manual" mapping method is the most efficient I could think of. On the plus side it simplifies the element code by automatically figuring out which corners need to be connected and rounded.https://git.sr.ht/~ap4sc/genpdf-rs/commit/fbf8656c3d2e25a8aab2f901f4f5bc92ff9b924a
One way to make it more modular in the future could be to move the rounded corners, LineStyle, [and fill color] into a separate RoundedRectangle shape struct for reuse in the shapes drawing feature
My idea for the API is:
- Create a new
RoundedCorners
struct similar toMargins
that can be constructed from a single value for all four corners, or from four different corners.- Change
FramedElement
so thatnew
is the only constructor and that there are these setters:
set_line_style
/with_line_style
set_rounded_corners
/with_rounded_corners
set_fill_color
/with_fill_color
(eventually)I see that you made it possible to select which borders to draw. This could be fitted in this model by creating a
Borders
struct with four boolean values (again similar toMargins
) andset_borders
/with_borders
setters inFramedElement
.If it makes sense for the implementation (for example to reduce the number of arguments in the draw methods), you can combine these settings in a
BorderStyle
orFrameStyle
struct. But this should be an implementation detail of theFramedElement
and not directly exposed to the user.Does that make sense to you? If yes, please submit the patches.
is set_fill_color / with_fill_color for FrameCellDecorator implemented? If yes, can you please share a sample