From 0b14dd9e55918a01a78fb4b22b2d5d3fafc93d27 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 4 Dec 2020 19:02:35 +0100 Subject: [PATCH] Tables: fixed propagation of line height from outside the table. Added outer-width demo. --- imgui_demo.cpp | 35 +++++++++++++++++++++++++++++++++++ imgui_internal.h | 2 ++ imgui_tables.cpp | 6 ++++++ 3 files changed, 43 insertions(+) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index ad26da0f5..c3321834a 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -4215,6 +4215,41 @@ static void ShowDemoWindowTables() ImGui::TreePop(); } + + if (open_action != -1) + ImGui::SetNextItemOpen(open_action != 0); + if (ImGui::TreeNode("Outer size")) + { + if (ImGui::BeginTable("##table1", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(TEXT_BASE_WIDTH * 30, 0.0f))) + { + for (int row = 0; row < 5; row++) + { + ImGui::TableNextRow(); + for (int column = 0; column < 3; column++) + { + ImGui::TableNextColumn(); + ImGui::Text("Cell %d,%d", column, row); + } + } + ImGui::EndTable(); + } + ImGui::SameLine(); + if (ImGui::BeginTable("##table2", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(TEXT_BASE_WIDTH * 30, 0.0f))) + { + for (int row = 0; row < 3; row++) + { + ImGui::TableNextRow(0, TEXT_BASE_HEIGHT * 1.5f); + for (int column = 0; column < 3; column++) + { + ImGui::TableNextColumn(); + ImGui::Text("Cell %d,%d", column, row); + } + } + ImGui::EndTable(); + } + ImGui::TreePop(); + } + if (open_action != -1) ImGui::SetNextItemOpen(open_action != 0); if (ImGui::TreeNode("Background color")) diff --git a/imgui_internal.h b/imgui_internal.h index 6b20822ea..fda7b3c23 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2019,6 +2019,8 @@ struct ImGuiTable ImRect HostBackupWorkRect; // Backup of InnerWindow->WorkRect at the end of BeginTable() ImRect HostBackupParentWorkRect; // Backup of InnerWindow->ParentWorkRect at the end of BeginTable() ImRect HostBackupClipRect; // Backup of InnerWindow->ClipRect during PushTableBackground()/PopTableBackground() + ImVec2 HostBackupPrevLineSize; // Backup of InnerWindow->DC.PrevLineSize at the end of BeginTable() + ImVec2 HostBackupCurrLineSize; // Backup of InnerWindow->DC.CurrLineSize at the end of BeginTable() ImVec2 HostBackupCursorMaxPos; // Backup of InnerWindow->DC.CursorMaxPos at the end of BeginTable() ImVec1 HostBackupColumnsOffset; // Backup of OuterWindow->DC.ColumnsOffset at the end of BeginTable() float HostBackupItemWidth; // Backup of OuterWindow->DC.ItemWidth at the end of BeginTable() diff --git a/imgui_tables.cpp b/imgui_tables.cpp index dfa30e0ef..24653cd82 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -240,6 +240,7 @@ ImGuiTable* ImGui::TableFindByID(ImGuiID id) return g.Tables.GetByKey(id); } +// Read about "TABLE SIZING" at the top of this file. bool ImGui::BeginTable(const char* str_id, int columns_count, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width) { ImGuiID id = GetID(str_id); @@ -331,10 +332,13 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG table->HostBackupWorkRect = inner_window->WorkRect; table->HostBackupParentWorkRect = inner_window->ParentWorkRect; table->HostBackupColumnsOffset = outer_window->DC.ColumnsOffset; + table->HostBackupPrevLineSize = inner_window->DC.PrevLineSize; + table->HostBackupCurrLineSize = inner_window->DC.CurrLineSize; table->HostBackupCursorMaxPos = inner_window->DC.CursorMaxPos; table->HostBackupItemWidth = outer_window->DC.ItemWidth; table->HostBackupItemWidthStackSize = outer_window->DC.ItemWidthStack.Size; inner_window->ParentWorkRect = table->WorkRect; + inner_window->DC.PrevLineSize = inner_window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); // Padding and Spacing // - None ........Content..... Pad .....Content........ @@ -1137,6 +1141,8 @@ void ImGui::EndTable() TableOpenContextMenu((int)table->HoveredColumnBody); // Finalize table height + inner_window->DC.PrevLineSize = table->HostBackupPrevLineSize; + inner_window->DC.CurrLineSize = table->HostBackupCurrLineSize; inner_window->DC.CursorMaxPos = table->HostBackupCursorMaxPos; if (inner_window != outer_window) {