Tables: fixed propagation of line height from outside the table. Added outer-width demo.
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index ad26da0..c332183 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -4215,6 +4215,41 @@
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 6b20822..fda7b3c 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -2019,6 +2019,8 @@
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 dfa30e0..24653cd 100644
--- a/imgui_tables.cpp
+++ b/imgui_tables.cpp
@@ -240,6 +240,7 @@
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 @@
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 @@
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)
{