DrawList: ImDrawFlags_AALineEnds also requires ImDrawFlags_AALine, which makes it easier for widgets to opt-in AAEnds.

This commit is contained in:
ocornut 2026-07-30 15:02:53 +02:00
parent 20f17eeb6f
commit deb9c70ace
3 changed files with 10 additions and 7 deletions

View File

@ -3343,7 +3343,7 @@ enum ImDrawFlags_
// Stroke/Fill Anti-aliasing ------------------ // Prim/Scope?
ImDrawFlags_AAFill = 1 << 12, // OK* OK(1) // Enable anti-aliasing for Filled shapes.
ImDrawFlags_AALines = 1 << 13, // OK* OK(1) // Enable anti-aliasing for Strokes (lines, borders).
ImDrawFlags_AALineEnds = 1 << 14, // OK OK(0) // Enable anti-aliasing for Strokes Ends. Useful on thick strokes or for precise continuity of multiple lines. A little more costly.
ImDrawFlags_AALineEnds = 1 << 14, // OK OK(0) // Enable anti-aliasing for Strokes Ends. Requires AALines to also be enabled. Useful on thick strokes or for precise continuity of multiple lines. A little more costly.
//ImDrawFlags_NoAA = 1 << 15, // OK -- // Disable anti-aliasing for a given primitive.
//ImDrawFlags_NoAALineEnds = 1 << 16, // OK -- // Disable anti-aliasing ends for a given primitive.

View File

@ -8911,8 +8911,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
Checkbox("Anti-aliased lines", &style.AntiAliasedLines);
SameLine();
HelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well.");
BeginDisabled(style.AntiAliasedLines == false);
Checkbox("Anti-aliased line ends", &style.AntiAliasedLineEnds);
EndDisabled();
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
BeginDisabled();

View File

@ -1045,6 +1045,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
const float half_aa = _FringeScale * 0.5f; // Used for end caps, does not use "fringe" since end cap AA is not using the texture.
const float half_thickness = thickness * 0.5f;
const bool use_aa_ends = (flags & (ImDrawFlags_AALines | ImDrawFlags_AALineEnds)) == (ImDrawFlags_AALines | ImDrawFlags_AALineEnds);
const int first_vtx_offset = (int)(_VtxWritePtr - VtxBuffer.Data);
int base_idx = (int)_VtxCurrentIdx;
@ -1073,7 +1074,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
p1.y -= dir.y * half_thickness;
}
if ((flags & ImDrawFlags_AALineEnds) == 0)
if (!use_aa_ends)
{
base_idx = (int)_VtxCurrentIdx;
IM_APPEND_VTX(p1.x - n1.x * thickness0, p1.y - n1.y * thickness0, uv0, col);
@ -1259,7 +1260,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
p1.y += dir.y * half_thickness;
}
if ((flags & ImDrawFlags_AALineEnds) == 0)
if (!use_aa_ends)
{
IM_APPEND_VTX(p1.x - n1.x * thickness0, p1.y - n1.y * thickness0, uv0, col);
IM_APPEND_VTX(p1.x + n1.x * thickness1, p1.y + n1.y * thickness1, uv1, col);
@ -1889,8 +1890,9 @@ void ImDrawList::_AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float t
const float half_aa = _FringeScale * 0.5f; // Used for end caps, does not use "fringe" since end cap AA is not using the texture.
const float half_thickness = thickness * 0.5f;
const bool use_aa_ends = (flags & (ImDrawFlags_AALines | ImDrawFlags_AALineEnds)) == (ImDrawFlags_AALines | ImDrawFlags_AALineEnds);
if ((flags & ImDrawFlags_AALineEnds) == 0)
if (!use_aa_ends)
PrimReserve(2*3, 4);
else
PrimReserve(6*3, 8);
@ -1910,7 +1912,7 @@ void ImDrawList::_AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float t
}
// Start cap
if ((flags & ImDrawFlags_AALineEnds) == 0)
if (!use_aa_ends)
{
base_idx = (int)_VtxCurrentIdx;
IM_APPEND_VTX(p1_x - norm_x * thickness0, p1_y - norm_y * thickness0, uv0, col);
@ -7622,7 +7624,7 @@ void ImGui::RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float
draw_list->PathLineTo(ImVec2(bx - third, by - third));
draw_list->PathLineTo(ImVec2(bx, by));
draw_list->PathLineTo(ImVec2(bx + third * 2.0f, by - third * 2.0f));
draw_list->PathStroke(col, thickness, (draw_list->Flags & ImDrawFlags_AALines) ? ImDrawFlags_AALineEnds : 0); // FIXME: Design idiomatic selection/threshold for this?
draw_list->PathStroke(col, thickness, ImDrawFlags_AALineEnds);
}
// Render an arrow. 'pos' is position of the arrow tip. half_sz.x is length from base to tip. half_sz.y is length on each side.