From f130db51ae2b749219fe25ad0d8de6109cdb01cf Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 5 Mar 2020 14:31:13 +0100 Subject: [PATCH] Tables: Added TableSetColumnWidth() api variant aimed at becoming public facing. --- imgui_internal.h | 1 + imgui_tables.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index efb04012..21882beb 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2185,6 +2185,7 @@ namespace ImGui IMGUI_API void TableUpdateDrawChannels(ImGuiTable* table); IMGUI_API void TableUpdateLayout(ImGuiTable* table); IMGUI_API void TableUpdateBorders(ImGuiTable* table); + IMGUI_API void TableSetColumnWidth(int column_n, float width); IMGUI_API void TableSetColumnWidth(ImGuiTable* table, ImGuiTableColumn* column, float width); IMGUI_API void TableDrawBorders(ImGuiTable* table); IMGUI_API void TableDrawMergeChannels(ImGuiTable* table); diff --git a/imgui_tables.cpp b/imgui_tables.cpp index c2b219d9..2053c007 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -886,7 +886,7 @@ void ImGui::EndTable() { ImGuiContext& g = *GImGui; ImGuiTable* table = g.CurrentTable; - IM_ASSERT(table != NULL && "Only call EndTable() is BeginTable() returns true!"); + IM_ASSERT(table != NULL && "Only call EndTable() if BeginTable() returns true!"); // This assert would be very useful to catch a common error... unfortunately it would probably trigger in some cases, // and for consistency user may sometimes output empty tables (and still benefit from e.g. outer border) @@ -1134,6 +1134,18 @@ static void TableUpdateColumnsWeightFromWidth(ImGuiTable* table) } } +// Public wrapper +void ImGui::TableSetColumnWidth(int column_n, float width) +{ + ImGuiContext& g = *GImGui; + ImGuiTable* table = g.CurrentTable; + IM_ASSERT(table != NULL); + IM_ASSERT(table->IsLayoutLocked == false); + IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount); + TableSetColumnWidth(table, &table->Columns[column_n], width); +} + +// [Internal] void ImGui::TableSetColumnWidth(ImGuiTable* table, ImGuiTableColumn* column_0, float column_0_width) { // Constraints