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

Drawing rounded rects with individual corner radii #7751

Closed
pixtur opened this issue Jun 28, 2024 · 3 comments
Closed

Drawing rounded rects with individual corner radii #7751

pixtur opened this issue Jun 28, 2024 · 3 comments

Comments

@pixtur
Copy link

pixtur commented Jun 28, 2024

Version/Branch of Dear ImGui:

Version 1.78, master

Back-ends:

imgui.net

Compiler, OS:

windows 10

Full config/build information:

No response

Details:

My Issue/Question:

Would it be possible to draw a rectangle with a different corner radius for each corner?

I'm frequently using...

IMGUI_API void AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawFlags flags = 0);

... but I would love to implement a segmented button that has no rounded corners at the joint. Something like this:

image

I’m aware that extensive styling is probably outside the scope of the master branch. However, there is...

IMGUI_API void AddRectFilledMultiColor(const ImVec2& p_min, const ImVec2& p_max, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left);

... so adding an override for AddRectFilled with four different corner radii wouldn't be too much of a feature creep.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

@ocornut
Copy link
Owner

ocornut commented Jun 28, 2024

AddRectFilled() with rounding is simply PathRect() + PathFillConvex(), and PathRect() is simply 4 calls to PathArcToFast().
So you can easily implement your own in 5 lines of code:

PathArcToFast(...)
PathArcToFast(...)
PathArcToFast(...)
PathArcToFast(...)
PathFillConvex(col);

And then you can adjust the radius however you want.
It doesn't need a new function for this.....

However if you need to DISABLE rounding for certain corners we already have flags for this too and you can use e.g. ImDrawFlags_RoundCornersAll & ~ImDrawFlags_RoundCornersRight to disable rounding on the two right corners.

@ocornut
Copy link
Owner

ocornut commented Jun 28, 2024

I think the flags in the API in 1.76 were a little different ImDrawCornerFlags_xxx but same feature.

(1.76 is more than four years old please don't use it. :)

@pixtur
Copy link
Author

pixtur commented Jul 1, 2024

Wow! Thanks a lot. That was was I was looking for.

(1.76 is more than four years old please don't use it. :)

I checked, and we're using 1.87.3. Sadly there was a minor breaking change in ImGui.net v1.88.
But I really need to update to the latest release.

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

No branches or pull requests

2 participants