Tables: Using same seed ID regardless of when using a child window or not.

This commit is contained in:
ocornut 2020-06-17 15:27:17 +02:00
parent 798aed729a
commit 7ca70dcb81

View File

@ -216,6 +216,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
table->OuterRect = outer_rect; table->OuterRect = outer_rect;
table->WorkRect = outer_rect; table->WorkRect = outer_rect;
// When not using a child window, WorkRect.Max will grow as we append contents.
if (use_child_window) if (use_child_window)
{ {
// Ensure no vertical scrollbar appears if we only want horizontal one, to make flag consistent // Ensure no vertical scrollbar appears if we only want horizontal one, to make flag consistent
@ -241,11 +242,9 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
table->WorkRect = table->InnerWindow->WorkRect; table->WorkRect = table->InnerWindow->WorkRect;
table->OuterRect = table->InnerWindow->Rect(); table->OuterRect = table->InnerWindow->Rect();
} }
else
{ // Push a standardized ID for both child and not-child using tables, equivalent to BeginTable() doing PushID(label) matching
// WorkRect.Max will grow as we append contents. PushOverrideID(instance_id);
PushID(instance_id);
}
// Backup a copy of host window members we will modify // Backup a copy of host window members we will modify
ImGuiWindow* inner_window = table->InnerWindow; ImGuiWindow* inner_window = table->InnerWindow;
@ -1057,6 +1056,8 @@ void ImGui::EndTable()
} }
// Layout in outer window // Layout in outer window
IM_ASSERT_USER_ERROR(inner_window->IDStack.back() == table->ID + table->InstanceCurrent, "Mismatching PushID/PopID!");
PopID();
inner_window->WorkRect = table->HostWorkRect; inner_window->WorkRect = table->HostWorkRect;
inner_window->SkipItems = table->HostSkipItems; inner_window->SkipItems = table->HostSkipItems;
outer_window->DC.CursorPos = table->OuterRect.Min; outer_window->DC.CursorPos = table->OuterRect.Min;
@ -1067,7 +1068,6 @@ void ImGui::EndTable()
} }
else else
{ {
PopID();
ImVec2 item_size = table->OuterRect.GetSize(); ImVec2 item_size = table->OuterRect.GetSize();
item_size.x = table->ColumnsTotalWidth; item_size.x = table->ColumnsTotalWidth;
ItemSize(item_size); ItemSize(item_size);