Skip to content

Commit a70c6aa

Browse files
committed
Tables: demo synced tables + fix resizing indented synced tables.
1 parent 0c9ab0a commit a70c6aa

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

imgui_demo.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4456,14 +4456,42 @@ static void ShowDemoWindowTables()
44564456
ImGui::TreePop();
44574457
}
44584458

4459+
// Demonstrate creating multiple tables with the same ID
4460+
if (open_action != -1)
4461+
ImGui::SetNextItemOpen(open_action != 0);
4462+
if (ImGui::TreeNode("Synced instances"))
4463+
{
4464+
HelpMarker("Multiple tables with the same identifier will share their settings, width, visibility, order etc.");
4465+
for (int n = 0; n < 3; n++)
4466+
{
4467+
char buf[32];
4468+
sprintf(buf, "Synced Table %d", n);
4469+
bool open = ImGui::CollapsingHeader(buf, ImGuiTreeNodeFlags_DefaultOpen);
4470+
if (open && ImGui::BeginTable("Table", 3, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_ColumnsWidthFixed | ImGuiTableFlags_NoSavedSettings))
4471+
{
4472+
ImGui::TableSetupColumn("One");
4473+
ImGui::TableSetupColumn("Two");
4474+
ImGui::TableSetupColumn("Three");
4475+
ImGui::TableHeadersRow();
4476+
for (int cell = 0; cell < 9; cell++)
4477+
{
4478+
ImGui::TableNextColumn();
4479+
ImGui::Text("this cell %d", cell);
4480+
}
4481+
ImGui::EndTable();
4482+
}
4483+
}
4484+
ImGui::TreePop();
4485+
}
4486+
4487+
// Demonstrate using Sorting facilities
4488+
// This is a simplified version of the "Advanced" example, where we mostly focus on the code necessary to handle sorting.
4489+
// Note that the "Advanced" example also showcase manually triggering a sort (e.g. if item quantities have been modified)
44594490
static const char* template_items_names[] =
44604491
{
44614492
"Banana", "Apple", "Cherry", "Watermelon", "Grapefruit", "Strawberry", "Mango",
44624493
"Kiwi", "Orange", "Pineapple", "Blueberry", "Plum", "Coconut", "Pear", "Apricot"
44634494
};
4464-
4465-
// This is a simplified version of the "Advanced" example, where we mostly focus on the code necessary to handle sorting.
4466-
// Note that the "Advanced" example also showcase manually triggering a sort (e.g. if item quantities have been modified)
44674495
if (open_action != -1)
44684496
ImGui::SetNextItemOpen(open_action != 0);
44694497
if (ImGui::TreeNode("Sorting"))

imgui_tables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ void ImGui::EndTable()
11221122
}
11231123

11241124
// Apply resizing/dragging at the end of the frame
1125-
if (table->ResizedColumn != -1)
1125+
if (table->ResizedColumn != -1 && table->InstanceCurrent == table->InstanceInteracted)
11261126
{
11271127
ImGuiTableColumn* column = &table->Columns[table->ResizedColumn];
11281128
const float new_x2 = (g.IO.MousePos.x - g.ActiveIdClickOffset.x + TABLE_RESIZE_SEPARATOR_HALF_THICKNESS);

0 commit comments

Comments
 (0)