C/C++ AddRectMultiColorRounded ImGui

Snow

Moderator
Apr 14, 2022
35
4
5454.png
AddRectMultiColorRounded is an ImGui function that allows you to draw a rectangle with multiple colors and rounded corners. Here's an example of how to use it:
C++:
ImGui::GetWindowDrawList()->AddRectMultiColor(
    ImVec2(100, 100), // top-left corner
    ImVec2(200, 200), // bottom-right corner
    IM_COL32(255, 0, 0, 255), // top-left color (red)
    IM_COL32(0, 255, 0, 255), // top-right color (green)
    IM_COL32(0, 0, 255, 255), // bottom-right color (blue)
    IM_COL32(255, 255, 0, 255), // bottom-left color (yellow)
    10.0f // corner radius
);

In this example, AddRectMultiColor is called on the current window's draw list (which can be obtained with ImGui::GetWindowDrawList()). The function takes in six arguments:
  1. ImVec2 for the top-left corner of the rectangle.
  2. ImVec2 for the bottom-right corner of the rectangle.
  3. ImU32 for the color of the top-left corner.
  4. ImU32 for the color of the top-right corner.
  5. ImU32 for the color of the bottom-right corner.
  6. ImU32 for the color of the bottom-left corner.
  7. float for the corner radius (for rounded corners).
This function allows you to create a rectangle with a gradient effect by specifying different colors for each corner. You can also adjust the corner radius to create a rounded rectangle.
 
Top