From 493795cdd1890d9cf1b2648c3e7ca9993f1d8971 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 19 Jul 2019 12:11:00 -0700 Subject: [PATCH] Columns: Fix support for BeginColumns() with a count of 1 (not that this isn't available via the old Columns() api). Tweaked Demo to facilitate testing for it. --- imgui_demo.cpp | 9 +++++++-- imgui_widgets.cpp | 13 +++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 756f8ada..b59fe602 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2590,11 +2590,16 @@ static void ShowDemoWindowColumns() // NB: Future columns API should allow automatic horizontal borders. static bool h_borders = true; static bool v_borders = true; + static int columns_count = 4; + const int lines_count = 3; + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); + ImGui::DragInt("##columns_count", &columns_count, 0.1f, 1, 10, "%d columns"); + ImGui::SameLine(); ImGui::Checkbox("horizontal", &h_borders); ImGui::SameLine(); ImGui::Checkbox("vertical", &v_borders); - ImGui::Columns(4, NULL, v_borders); - for (int i = 0; i < 4 * 3; i++) + ImGui::Columns(columns_count, NULL, v_borders); + for (int i = 0; i < columns_count * lines_count; i++) { if (h_borders && ImGui::GetColumnIndex() == 0) ImGui::Separator(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 25057426..0878b46c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7236,6 +7236,8 @@ void ImGui::PushColumnsBackground() { ImGuiWindow* window = GetCurrentWindowRead(); ImGuiColumns* columns = window->DC.CurrentColumns; + if (columns->Count == 1) + return; window->DrawList->ChannelsSetCurrent(0); int cmd_size = window->DrawList->CmdBuffer.Size; PushClipRect(columns->HostClipRect.Min, columns->HostClipRect.Max, false); @@ -7247,6 +7249,8 @@ void ImGui::PopColumnsBackground() { ImGuiWindow* window = GetCurrentWindowRead(); ImGuiColumns* columns = window->DC.CurrentColumns; + if (columns->Count == 1) + return; window->DrawList->ChannelsSetCurrent(columns->Current + 1); PopClipRect(); } @@ -7294,15 +7298,16 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag columns->Flags = flags; window->DC.CurrentColumns = columns; + columns->HostCursorPosY = window->DC.CursorPos.y; + columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x; + columns->HostClipRect = window->ClipRect; + columns->HostWorkRect = window->WorkRect; + // Set state for first column const float column_padding = g.Style.ItemSpacing.x; columns->OffMinX = window->DC.Indent.x - column_padding; columns->OffMaxX = window->WorkRect.Max.x - window->Pos.x; columns->OffMaxX = ImMax(columns->OffMaxX, columns->OffMinX + 1.0f); - columns->HostCursorPosY = window->DC.CursorPos.y; - columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x; - columns->HostClipRect = window->ClipRect; - columns->HostWorkRect = window->WorkRect; columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y; window->DC.ColumnsOffset.x = 0.0f; window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);