From c37f21788fcd8824d807c575947062223490b807 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 21 Jul 2019 11:23:15 -0700 Subject: [PATCH] Columns: Made GetColumnOffset() and GetColumnWidth() behave when there's no column set, consistently with other column functions + fixed Columns demo (#2683) --- docs/CHANGELOG.txt | 2 ++ imgui_demo.cpp | 4 +++- imgui_widgets.cpp | 9 ++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 93f7a7fcf..c06e2e572 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -64,6 +64,8 @@ Other Changes: - Columns: Improved honoring alignment with various values of ItemSpacing.x and WindowPadding.x. (#125, #2666) - Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d). +- Columns: Made GetColumnOffset() and GetColumnWidth() behave when there's no column set, consistently with + other column functions. (#2683) - Scrolling: Added SetScrollHereX(), SetScrollFromPosX() for completeness. (#1580) [@kevreco] - Style: Attenuated default opacity of ImGuiCol_Separator in Classic and Light styles. - Style: Added style.ColorButtonPosition (left/right, defaults to ImGuiDir_Right) to move the color button diff --git a/imgui_demo.cpp b/imgui_demo.cpp index b59fe6020..53e2bf1c4 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2593,7 +2593,9 @@ static void ShowDemoWindowColumns() 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::DragInt("##columns_count", &columns_count, 0.1f, 2, 10, "%d columns"); + if (columns_count < 2) + columns_count = 2; ImGui::SameLine(); ImGui::Checkbox("horizontal", &h_borders); ImGui::SameLine(); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 1373ea741..c42c518f0 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7152,7 +7152,8 @@ float ImGui::GetColumnOffset(int column_index) { ImGuiWindow* window = GetCurrentWindowRead(); ImGuiColumns* columns = window->DC.CurrentColumns; - IM_ASSERT(columns != NULL); + if (columns == NULL) + return 0.0f; if (column_index < 0) column_index = columns->Current; @@ -7178,9 +7179,11 @@ static float GetColumnWidthEx(ImGuiColumns* columns, int column_index, bool befo float ImGui::GetColumnWidth(int column_index) { - ImGuiWindow* window = GetCurrentWindowRead(); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; ImGuiColumns* columns = window->DC.CurrentColumns; - IM_ASSERT(columns != NULL); + if (columns == NULL) + return GetContentRegionAvail().x; if (column_index < 0) column_index = columns->Current;