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

Gradient filled rectangle not rounding #6652

Closed
ElectroidDes opened this issue Jul 26, 2023 · 3 comments
Closed

Gradient filled rectangle not rounding #6652

ElectroidDes opened this issue Jul 26, 2023 · 3 comments

Comments

@ElectroidDes
Copy link

Imgui Version: 1.89.6

Using the following code to draw a rectangle with a gradient fill in the window:


    ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 60);
    ImGui::Begin("Window Rounding");

    ImVec2 top_left_corner = { ImGui::GetWindowPos().x , ImGui::GetWindowPos().y };
    ImVec2 lower_right_corner = { ImGui::GetWindowPos().x + ImGui::GetWindowSize().x, ImGui::GetWindowPos().y + ImGui::GetWindowSize().y };

    ImDrawList* draw_list = ImGui::GetWindowDrawList();    
    (*draw_list).AddRectFilledMultiColor(top_left_corner, lower_right_corner, IM_COL32(50, 100, 0, 255), IM_COL32(40, 255, 50, 255), IM_COL32(100, 0, 255, 255), IM_COL32(0, 0, 0, 0) );

    ImGui::End();
    ImGui::PopStyleVar();

As you can see, the top left and right corners and the bottom left corners round the corners correctly.
The lower right corner of the rectangle a gradient fill is not cut and it "climbs out".
Is this the correct behavior of Imgui ? Is that how it should be?

Imgui_round

@GamingMinds-DanielC
Copy link
Contributor

GamingMinds-DanielC commented Jul 27, 2023

Your assumption that the bottom left corner is rounding correctly is wrong. You just can't see it since it is a transparent black (alpha 0), not a solid one.

So basically, your problem is that you have rather extreme rounding values and rectangular clipping can't accommodate this. Normally rounding is much smaller and a margin ensures that the content doesn't get into those rounded corners. Fixing this the way you want is out of the scope of ImGui, but you can accomplish this if you render into a texture with alpha channel and mask it yourself, then draw that texture as an image.

@ocornut
Copy link
Owner

ocornut commented Jul 27, 2023

It’s also that AddRectFilledMultiColor() doesn’t even support rounding. In the event your shape could fill the window without requiring clipping (which is always rectangular) you could use AddRectFilled() with rounding and white color + the ShadeVertsLinearColorGradientKeepAlpha() function.

See the code in #4722

@ElectroidDes
Copy link
Author

It’s also that AddRectFilledMultiColor() doesn’t even support rounding. In the event your shape could fill the window without requiring clipping (which is always rectangular) you could use AddRectFilled() with rounding and white color + the ShadeVertsLinearColorGradientKeepAlpha() function.

See the code in #4722

Thank you very much!
Function "ShadeVertsLinearColorGradientKeepAlpha" - works.

@ocornut ocornut closed this as completed Jul 29, 2023
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

3 participants