Skip to content

Instantly share code, notes, and snippets.

@therathatter
Last active July 5, 2026 21:13
Show Gist options
  • Select an option

  • Save therathatter/317e9bca057f550050108897df69cceb to your computer and use it in GitHub Desktop.

Select an option

Save therathatter/317e9bca057f550050108897df69cceb to your computer and use it in GitHub Desktop.
Gradients with ImGUI
void gradient_rect( ImDrawList* list, const ImVec2& p_min, const ImVec2& p_max,
ImU32 col_top, ImU32 col_bottom, float rounding,
ImDrawFlags flags )
{
/*
* "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."
* - ocornut
* (https://github.com/ocornut/imgui/issues/6652#issuecomment-1653173953)
*/
const ImRect bb( p_min, p_max );
int vert_start_idx = list->VtxBuffer.Size;
list->AddRectFilled( bb.Min, bb.Max, col_top, rounding, flags );
int vert_end_idx = list->VtxBuffer.Size;
ShadeVertsLinearColorGradientKeepAlpha( list, vert_start_idx, vert_end_idx,
bb.Min, bb.GetBL( ), col_top,
col_bottom );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment