mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 13:11:05 +01:00 
			
		
		
		
	AddCircle, AddCircleFilled: Add auto-calculation of circle segment counts (amends)
Tweak default max error value, Changelog, comments, path-fast for 12 segments circles, made LUT store ImU8
This commit is contained in:
		| @@ -3500,9 +3500,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) | ||||
|             ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines); ImGui::SameLine(); HelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well."); | ||||
|             ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill); | ||||
|             ImGui::PushItemWidth(100); | ||||
|             ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, FLT_MAX, "%.2f", 2.0f); | ||||
|             ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f, "%.2f"); | ||||
|             if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f; | ||||
|             ImGui::DragFloat("Max circle segment error", &style.CircleSegmentMaxError, 0.01f, 0.1f, 10.0f, "%.2f", 1.0f); | ||||
|             ImGui::DragFloat("Circle segment Max Error", &style.CircleSegmentMaxError, 0.01f, 0.10f, 10.0f, "%.2f"); | ||||
|             ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero. | ||||
|             ImGui::PopItemWidth(); | ||||
|  | ||||
| @@ -4455,24 +4455,33 @@ static void ShowExampleAppCustomRendering(bool* p_open) | ||||
|             static float sz = 36.0f; | ||||
|             static float thickness = 3.0f; | ||||
|             static int ngon_sides = 6; | ||||
|             static bool circle_segments_override = false; | ||||
|             static int circle_segments_override_v = 12; | ||||
|             static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f); | ||||
|             ImGui::PushItemWidth(-ImGui::GetFontSize() * 10); | ||||
|             ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 72.0f, "%.0f"); | ||||
|             ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f"); | ||||
|             ImGui::SliderInt("n-gon sides", &ngon_sides, 3, 12); | ||||
|             ImGui::SliderInt("N-gon sides", &ngon_sides, 3, 12); | ||||
|             ImGui::Checkbox("##circlesegmentoverride", &circle_segments_override); | ||||
|             ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); | ||||
|             if (ImGui::SliderInt("Circle segments", &circle_segments_override_v, 3, 40)) | ||||
|                 circle_segments_override = true; | ||||
|             ImGui::ColorEdit4("Color", &colf.x); | ||||
|             ImGui::PopItemWidth(); | ||||
|             const ImVec2 p = ImGui::GetCursorScreenPos(); | ||||
|             const ImU32 col = ImColor(colf); | ||||
|             const float spacing = 10.0f; | ||||
|             const ImDrawCornerFlags corners_none = 0; | ||||
|             const ImDrawCornerFlags corners_all = ImDrawCornerFlags_All; | ||||
|             const ImDrawCornerFlags corners_tl_br = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight; | ||||
|             const int circle_segments = circle_segments_override ? circle_segments_override_v : 0; | ||||
|             float x = p.x + 4.0f, y = p.y + 4.0f; | ||||
|             float spacing = 10.0f; | ||||
|             ImDrawCornerFlags corners_none = 0; | ||||
|             ImDrawCornerFlags corners_all = ImDrawCornerFlags_All; | ||||
|             ImDrawCornerFlags corners_tl_br = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight; | ||||
|             for (int n = 0; n < 2; n++) | ||||
|             { | ||||
|                 // First line uses a thickness of 1.0f, second line uses the configurable thickness | ||||
|                 float th = (n == 0) ? 1.0f : thickness; | ||||
|                 draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th);         x += sz + spacing;  // n-gon | ||||
|                 draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 0, th);                x += sz + spacing;  // Circle | ||||
|                 draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th);         x += sz + spacing;  // N-gon | ||||
|                 draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments, th);  x += sz + spacing;  // Circle | ||||
|                 draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f,  corners_none, th);     x += sz + spacing;  // Square | ||||
|                 draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th);      x += sz + spacing;  // Square with all rounded corners | ||||
|                 draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br, th);    x += sz + spacing;  // Square with two rounded corners | ||||
| @@ -4485,8 +4494,8 @@ static void ShowExampleAppCustomRendering(bool* p_open) | ||||
|                 x = p.x + 4; | ||||
|                 y += sz + spacing; | ||||
|             } | ||||
|             draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides);   x += sz + spacing;  // n-gon | ||||
|             draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 0);              x += sz + spacing;  // Circle | ||||
|             draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides);   x += sz + spacing;  // N-gon | ||||
|             draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments);x += sz + spacing;  // Circle | ||||
|             draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col);                        x += sz + spacing;  // Square | ||||
|             draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f);                 x += sz + spacing;  // Square with all rounded corners | ||||
|             draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br);  x += sz + spacing;  // Square with two rounded corners | ||||
|   | ||||
		Reference in New Issue
	
	Block a user