DrawList: added square cap rendering.

- Added square cap rendering to the DrawPolyline, which can be turned on by ImDrawFlags_SquareCap
- Added draw flags to AddBezierCubic() and AddBezierQuadratic()
This commit is contained in:
Mikko Mononen
2026-04-27 08:36:18 +03:00
committed by ocornut
parent a1d903c743
commit 08e5215737
3 changed files with 24 additions and 13 deletions

View File

@@ -10418,6 +10418,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
static bool curve_segments_override = false;
static int curve_segments_override_v = 8;
static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f);
static bool square_caps = false;
ImGui::DragFloat("Size", &sz, 0.2f, 0.2f, 100.0f, "%.0f");
ImGui::DragFloat("Thickness", &thickness, 0.05f, 0.0f, 32.0f, "%.02f");
ImGui::SliderInt("N-gon sides", &ngon_sides, 3, 12);
@@ -10428,6 +10429,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
curve_segments_override |= ImGui::SliderInt("Curves segments override", &curve_segments_override_v, 3, 40);
ImGui::ColorEdit4("Color", &colf.x);
ImGui::Checkbox("Square caps", &square_caps);
static ImDrawFlags flags = ImDrawFlags_None;
ImGui::AlignTextToFramePadding();
@@ -10443,6 +10445,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
const ImU32 col = ImColor(colf);
const float spacing = 10.0f;
const ImDrawFlags corners_tl_br = ImDrawFlags_RoundCornersTopLeft | ImDrawFlags_RoundCornersBottomRight;
const ImDrawFlags stroke_flags = square_caps ? ImDrawFlags_SquareCap : ImDrawFlags_None;
const float rounding = sz / 5.0f;
const int circle_segments = circle_segments_override ? circle_segments_override_v : 0;
const int curve_segments = curve_segments_override ? curve_segments_override_v : 0;
@@ -10467,7 +10470,6 @@ static void ShowExampleAppCustomRendering(bool* p_open)
//draw_list->AddPolyline(concave_shape, IM_COUNTOF(concave_shape), col, ImDrawFlags_Closed, th);
draw_list->AddLineH(x, x + sz, y, col, th, flags); x += sz + spacing; // Horizontal line (note: drawing a filled rectangle will be faster!)
draw_list->AddLineV(x, y, y + sz, col, th, flags); x += spacing; // Vertical line (note: drawing a filled rectangle will be faster!)
draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y), col, th, flags); x += sz + spacing;
draw_list->AddLine(ImVec2(x, y + sz), ImVec2(x, y), col, th, flags); x += spacing;
@@ -10479,11 +10481,11 @@ static void ShowExampleAppCustomRendering(bool* p_open)
x += sz + spacing;
// Quadratic Bezier Curve (3 control points)
draw_list->AddBezierQuadratic(ImVec2(x + cp3[0].x, y + cp3[0].y), ImVec2(x + cp3[1].x, y + cp3[1].y), ImVec2(x + cp3[2].x, y + cp3[2].y), col, th, curve_segments);
draw_list->AddBezierQuadratic(ImVec2(x + cp3[0].x, y + cp3[0].y), ImVec2(x + cp3[1].x, y + cp3[1].y), ImVec2(x + cp3[2].x, y + cp3[2].y), col, th, curve_segments, stroke_flags);
x += sz + spacing;
// Cubic Bezier Curve (4 control points)
draw_list->AddBezierCubic(ImVec2(x + cp4[0].x, y + cp4[0].y), ImVec2(x + cp4[1].x, y + cp4[1].y), ImVec2(x + cp4[2].x, y + cp4[2].y), ImVec2(x + cp4[3].x, y + cp4[3].y), col, th, curve_segments);
draw_list->AddBezierCubic(ImVec2(x + cp4[0].x, y + cp4[0].y), ImVec2(x + cp4[1].x, y + cp4[1].y), ImVec2(x + cp4[2].x, y + cp4[2].y), ImVec2(x + cp4[3].x, y + cp4[3].y), col, th, curve_segments, stroke_flags);
x = p.x + 4;
y += sz + spacing;