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

Expansion of the rounded buttons #401

Merged
merged 10 commits into from
May 21, 2024
Merged

Expansion of the rounded buttons #401

merged 10 commits into from
May 21, 2024

Conversation

klytje
Copy link
Contributor

@klytje klytje commented May 18, 2024

With this PR, we can now specify the 'roundedness' of each individual corner of a button.

There are now four ways to control them:

  1. Using the existing corner_radius(r) method to specify all corners at once,
  2. Using the new overloaded version corner_radius(r1, r2, r3, r4) to specify them indivdually,
  3. Using the new rounded_*(r) series of methods to specify a half-rounded side,
  4. Using the new rounded_corner_*(r) series of methods to specify individual corners.

I expanded the Buttons example to showcase this new functionality.

I also added a missing implementation of the gen_text_color text_color(color color_) method I discovered during my testing. Previously it could not compile code specifying the text color of buttons.

@klytje klytje marked this pull request as ready for review May 18, 2024 11:44
lib/src/support/canvas.cpp Outdated Show resolved Hide resolved
lib/include/elements/element/gallery/button.hpp Outdated Show resolved Hide resolved
@djowel
Copy link
Collaborator

djowel commented May 19, 2024

Looking good. Is this ready for merge? I see some commented out code.

lib/src/support/draw_utils.cpp Outdated Show resolved Hide resolved
lib/src/support/draw_utils.cpp Outdated Show resolved Hide resolved
lib/src/support/draw_utils.cpp Outdated Show resolved Hide resolved
lib/src/support/draw_utils.cpp Outdated Show resolved Hide resolved
@klytje
Copy link
Contributor Author

klytje commented May 20, 2024

@djowel I added a small corner_radii struct, with initialization order: bottom_right, bottom_left, top_left, top_right. Same as the API I believe.

@djowel
Copy link
Collaborator

djowel commented May 20, 2024

@djowel I added a small corner_radii struct, with initialization order: bottom_right, bottom_left, top_left, top_right. Same as the API I believe.

Hi @klytje I think the correct sequence is top_left, top_right, bottom_right, bottom_left :-)

Interestingly, if you ask ChatGPT to make an API for drawing a round rectangle with customizable corner radii, it's the one it will recommend:

void draw_round_rectangle(float x, float y, float width, float height,
                          float radius_tl, float radius_tr,
                          float radius_br, float radius_bl);

Then, I asked: "why did you specify the radii from top-left going clockwise?"

ChatGPT follows the large language model from a vast source of programming code, and its answer is:

"Specifying the radii from the top-left corner going clockwise is a common convention in graphics programming. It follows a logical order that aligns with how many people read and interpret shapes and diagrams."

It is indeed customary in computer graphics to give precedence to the top-left, and in general, the horizontal coordinate first (i.e. x, before y).

@klytje
Copy link
Contributor Author

klytje commented May 20, 2024

@djowel I implemented it according to the W3C docs:
image
"The points at startAngle and endAngle this circle's circumference, measured in radians clockwise from the positive x-axis, are the start and end points respectively."

Indeed, looking at the my implementation you'll see the angle going from 0 --> 90 --> 180 --> 270 --> 360 as it is now:
https://github.com/klytje/elements/blob/round_buttons/lib/src/support/draw_utils.cpp#L99-L104

Your order is what I meant as the third option, following the rect, though looking back it wasn't super clear that was what I meant.

@klytje
Copy link
Contributor Author

klytje commented May 20, 2024

Also I agree that starting from the top-left feels more natural for most objects, except circles :)

@djowel
Copy link
Collaborator

djowel commented May 20, 2024

@djowel I added a small corner_radii struct, with initialization order: bottom_right, bottom_left, top_left, top_right. Same as the API I believe.

Hi @klytje I think the correct sequence is top_left, top_right, bottom_right, bottom_left :-)

Interestingly, if you ask ChatGPT to make an API for drawing a round rectangle with customizable corner radii, it's the one it will recommend:

void draw_round_rectangle(float x, float y, float width, float height,
                          float radius_tl, float radius_tr,
                          float radius_br, float radius_bl);

Then, I asked: "why did you specify the radii from top-left going clockwise?"

ChatGPT follows the large language model from a vast source of programming code, and its answer is:

"Specifying the radii from the top-left corner going clockwise is a common convention in graphics programming. It follows a logical order that aligns with how many people read and interpret shapes and diagrams."

It is indeed customary in computer graphics to give precedence to the top-left, and in general, the horizontal coordinate first (i.e. x, before y).

BTW, skia goes so far as specify the horizontal and vertical radii for all corners:

https://api.skia.org/classSkRRect.html

But take note of the sequence:

image
enum Corner { kUpperLeft_Corner , kUpperRight_Corner , kLowerRight_Corner , kLowerLeft_Corner }

@klytje
Copy link
Contributor Author

klytje commented May 21, 2024

Changed initialization order to top_left, top_right, bottom_right, bottom_left.

@djowel
Copy link
Collaborator

djowel commented May 21, 2024

Changed initialization order to top_left, top_right, bottom_right, bottom_left.

Thanks for your patience! :-)

@djowel djowel self-assigned this May 21, 2024
@djowel
Copy link
Collaborator

djowel commented May 21, 2024

Ouch. I forgot. This should be against skia_2024 first. Anyway, I'll just do the cherry-pick dance again. No worries.

@djowel djowel merged commit 0bc67db into cycfi:master May 21, 2024
3 of 4 checks passed
@djowel
Copy link
Collaborator

djowel commented May 21, 2024

Oh gee... It seems Skia does arcs differently –not connecting the lines between the arcs!

@djowel
Copy link
Collaborator

djowel commented May 21, 2024

Oh gee... It seems Skia does arcs differently –not connecting the lines between the arcs!

At least Quartz2D is doing it correctly! I'll push to askia_2024_dev branch. See if you can fix the Artist's Skia implementation of arc to follow W3C's behavior.

@djowel
Copy link
Collaborator

djowel commented May 21, 2024

BTW, in the demo cpp, I think we should use grids to align the 3 R/G/B buttons properly.

@djowel
Copy link
Collaborator

djowel commented May 22, 2024

Oh gee... It seems Skia does arcs differently –not connecting the lines between the arcs!

At least Quartz2D is doing it correctly! I'll push to askia_2024_dev branch. See if you can fix the Artist's Skia implementation of arc to follow W3C's behavior.

FYI: I have a fix for skia now.

@klytje
Copy link
Contributor Author

klytje commented May 22, 2024

FYI: I have a fix for skia now.

Ah cool! I gave it a quick glance this morning but realized I'd have to dedicate more time than I had to fix it :)

@djowel
Copy link
Collaborator

djowel commented May 22, 2024

FYI: I have a fix for skia now.

Ah cool! I gave it a quick glance this morning but realized I'd have to dedicate more time than I had to fix it :)

Getting there...

image

LOL :-)

@djowel
Copy link
Collaborator

djowel commented May 22, 2024

OK fixed. I'll merge to skia_2024

@djowel
Copy link
Collaborator

djowel commented May 22, 2024

OK fixed. I'll merge to skia_2024

Merged

@djowel
Copy link
Collaborator

djowel commented May 22, 2024

@klytje... Reopening, I think rounded_left is wrong:

image

If you zoom in, the right-top and right-bottom corners are not sharp. It is fixed by using .corner_radius(10, 0, 0, 10)

Or is it intentional? Assuming the default radius when not specified? It does not seem right, no?

@djowel
Copy link
Collaborator

djowel commented May 22, 2024

#402

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

Successfully merging this pull request may close these issues.

None yet

2 participants