Skip to content

Commit 0b14dd9

Browse files
committed
Tables: fixed propagation of line height from outside the table. Added outer-width demo.
1 parent 6e38026 commit 0b14dd9

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

imgui_demo.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,6 +4215,41 @@ static void ShowDemoWindowTables()
42154215
ImGui::TreePop();
42164216
}
42174217

4218+
4219+
if (open_action != -1)
4220+
ImGui::SetNextItemOpen(open_action != 0);
4221+
if (ImGui::TreeNode("Outer size"))
4222+
{
4223+
if (ImGui::BeginTable("##table1", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(TEXT_BASE_WIDTH * 30, 0.0f)))
4224+
{
4225+
for (int row = 0; row < 5; row++)
4226+
{
4227+
ImGui::TableNextRow();
4228+
for (int column = 0; column < 3; column++)
4229+
{
4230+
ImGui::TableNextColumn();
4231+
ImGui::Text("Cell %d,%d", column, row);
4232+
}
4233+
}
4234+
ImGui::EndTable();
4235+
}
4236+
ImGui::SameLine();
4237+
if (ImGui::BeginTable("##table2", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, ImVec2(TEXT_BASE_WIDTH * 30, 0.0f)))
4238+
{
4239+
for (int row = 0; row < 3; row++)
4240+
{
4241+
ImGui::TableNextRow(0, TEXT_BASE_HEIGHT * 1.5f);
4242+
for (int column = 0; column < 3; column++)
4243+
{
4244+
ImGui::TableNextColumn();
4245+
ImGui::Text("Cell %d,%d", column, row);
4246+
}
4247+
}
4248+
ImGui::EndTable();
4249+
}
4250+
ImGui::TreePop();
4251+
}
4252+
42184253
if (open_action != -1)
42194254
ImGui::SetNextItemOpen(open_action != 0);
42204255
if (ImGui::TreeNode("Background color"))

imgui_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,8 @@ struct ImGuiTable
20192019
ImRect HostBackupWorkRect; // Backup of InnerWindow->WorkRect at the end of BeginTable()
20202020
ImRect HostBackupParentWorkRect; // Backup of InnerWindow->ParentWorkRect at the end of BeginTable()
20212021
ImRect HostBackupClipRect; // Backup of InnerWindow->ClipRect during PushTableBackground()/PopTableBackground()
2022+
ImVec2 HostBackupPrevLineSize; // Backup of InnerWindow->DC.PrevLineSize at the end of BeginTable()
2023+
ImVec2 HostBackupCurrLineSize; // Backup of InnerWindow->DC.CurrLineSize at the end of BeginTable()
20222024
ImVec2 HostBackupCursorMaxPos; // Backup of InnerWindow->DC.CursorMaxPos at the end of BeginTable()
20232025
ImVec1 HostBackupColumnsOffset; // Backup of OuterWindow->DC.ColumnsOffset at the end of BeginTable()
20242026
float HostBackupItemWidth; // Backup of OuterWindow->DC.ItemWidth at the end of BeginTable()

imgui_tables.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ ImGuiTable* ImGui::TableFindByID(ImGuiID id)
240240
return g.Tables.GetByKey(id);
241241
}
242242

243+
// Read about "TABLE SIZING" at the top of this file.
243244
bool ImGui::BeginTable(const char* str_id, int columns_count, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width)
244245
{
245246
ImGuiID id = GetID(str_id);
@@ -331,10 +332,13 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
331332
table->HostBackupWorkRect = inner_window->WorkRect;
332333
table->HostBackupParentWorkRect = inner_window->ParentWorkRect;
333334
table->HostBackupColumnsOffset = outer_window->DC.ColumnsOffset;
335+
table->HostBackupPrevLineSize = inner_window->DC.PrevLineSize;
336+
table->HostBackupCurrLineSize = inner_window->DC.CurrLineSize;
334337
table->HostBackupCursorMaxPos = inner_window->DC.CursorMaxPos;
335338
table->HostBackupItemWidth = outer_window->DC.ItemWidth;
336339
table->HostBackupItemWidthStackSize = outer_window->DC.ItemWidthStack.Size;
337340
inner_window->ParentWorkRect = table->WorkRect;
341+
inner_window->DC.PrevLineSize = inner_window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
338342

339343
// Padding and Spacing
340344
// - None ........Content..... Pad .....Content........
@@ -1137,6 +1141,8 @@ void ImGui::EndTable()
11371141
TableOpenContextMenu((int)table->HoveredColumnBody);
11381142

11391143
// Finalize table height
1144+
inner_window->DC.PrevLineSize = table->HostBackupPrevLineSize;
1145+
inner_window->DC.CurrLineSize = table->HostBackupCurrLineSize;
11401146
inner_window->DC.CursorMaxPos = table->HostBackupCursorMaxPos;
11411147
if (inner_window != outer_window)
11421148
{

0 commit comments

Comments
 (0)