From 6001d9c7a46f70bb029aa779c42fafd3c2b22652 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 14 Nov 2017 22:40:57 +0100 Subject: [PATCH] Columns: Clipping columns borders on Y axis on CPU because some GPU drivers appears to be unhappy with triangle spanning large regions (not sure why tbh). (#125) Demo: Columns: Adding a billion of extra lines and using clipper. --- imgui.cpp | 3 ++- imgui_demo.cpp | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b085efe1c..b828d0e90 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10511,9 +10511,10 @@ void ImGui::EndColumns() } // Draw column + // We clip the Y boundaries CPU side because very long triangles are mishandled by some GPU drivers. const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator); const float xi = (float)(int)x; - window->DrawList->AddLine(ImVec2(xi, y1 + 1.0f), ImVec2(xi, y2), col); + window->DrawList->AddLine(ImVec2(xi, ImMax(y1 + 1.0f, window->ClipRect.Min.y)), ImVec2(xi, ImMin(y2, window->ClipRect.Max.y)), col); } // Apply dragging after drawing the column lines, so our rendered lines are in sync with how items were displayed during the frame. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index f6918f578..d9ccad31d 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1652,14 +1652,19 @@ void ImGui::ShowTestWindow(bool* p_open) if (ImGui::TreeNode("Horizontal Scrolling")) { ImGui::SetNextWindowContentWidth(1500); - ImGui::BeginChild("##scrollingregion", ImVec2(0, 120), false, ImGuiWindowFlags_HorizontalScrollbar); + ImGui::BeginChild("##ScrollingRegion", ImVec2(0, ImGui::GetFontSize() * 20), false, ImGuiWindowFlags_HorizontalScrollbar); ImGui::Columns(10); - for (int i = 0; i < 20; i++) - for (int j = 0; j < 10; j++) - { - ImGui::Text("Line %d Column %d...", i, j); - ImGui::NextColumn(); - } + int ITEMS_COUNT = 2000; + ImGuiListClipper clipper(ITEMS_COUNT); // Also demonstrate using the clipper for large list + while (clipper.Step()) + { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) + for (int j = 0; j < 10; j++) + { + ImGui::Text("Line %d Column %d...", i, j); + ImGui::NextColumn(); + } + } ImGui::Columns(1); ImGui::EndChild(); ImGui::TreePop();