Internals: fixed ImPool:: iteration, rename GetBufSize to GetMapSize. Amend c6c82b9f
diff --git a/imgui.cpp b/imgui.cpp
index 1d52722..25c779f 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -11023,9 +11023,9 @@
cfg->ShowTablesRects |= Combo("##show_table_rects_type", &cfg->ShowTablesRectsType, trt_rects_names, TRT_Count, TRT_Count);
if (cfg->ShowTablesRects && g.NavWindow != NULL)
{
- for (int table_n = 0; table_n < g.Tables.GetBufSize(); table_n++)
+ for (int table_n = 0; table_n < g.Tables.GetMapSize(); table_n++)
{
- ImGuiTable* table = g.Tables.TryGetBufData(table_n);
+ ImGuiTable* table = g.Tables.TryGetMapData(table_n);
if (table == NULL || table->LastFrameActive < g.FrameCount - 1 || (table->OuterWindow != g.NavWindow && table->InnerWindow != g.NavWindow))
continue;
@@ -11110,8 +11110,8 @@
// Details for TabBars
if (TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.GetAliveCount()))
{
- for (int n = 0; n < g.TabBars.GetBufSize(); n++)
- if (ImGuiTabBar* tab_bar = g.TabBars.TryGetBufData(n))
+ for (int n = 0; n < g.TabBars.GetMapSize(); n++)
+ if (ImGuiTabBar* tab_bar = g.TabBars.TryGetMapData(n))
{
PushID(tab_bar);
DebugNodeTabBar(tab_bar, "TabBar");
@@ -11123,8 +11123,8 @@
// Details for Tables
if (TreeNode("Tables", "Tables (%d)", g.Tables.GetAliveCount()))
{
- for (int n = 0; n < g.Tables.GetBufSize(); n++)
- if (ImGuiTable* table = g.Tables.TryGetBufData(n))
+ for (int n = 0; n < g.Tables.GetMapSize(); n++)
+ if (ImGuiTable* table = g.Tables.TryGetMapData(n))
DebugNodeTable(table);
TreePop();
}
@@ -11259,9 +11259,9 @@
// Overlay: Display Tables Rectangles
if (cfg->ShowTablesRects)
{
- for (int table_n = 0; table_n < g.Tables.GetBufSize(); table_n++)
+ for (int table_n = 0; table_n < g.Tables.GetMapSize(); table_n++)
{
- ImGuiTable* table = g.Tables.TryGetBufData(table_n);
+ ImGuiTable* table = g.Tables.TryGetMapData(table_n);
if (table == NULL || table->LastFrameActive < g.FrameCount - 1)
continue;
ImDrawList* draw_list = GetForegroundDrawList(table->OuterWindow);
diff --git a/imgui.h b/imgui.h
index 50d9585..275f6c8 100644
--- a/imgui.h
+++ b/imgui.h
@@ -61,7 +61,7 @@
// Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
#define IMGUI_VERSION "1.84 WIP"
-#define IMGUI_VERSION_NUM 18303
+#define IMGUI_VERSION_NUM 18304
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_TABLE
diff --git a/imgui_internal.h b/imgui_internal.h
index a34c710..9d03758 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -612,7 +612,7 @@
ImVector<T> Buf; // Contiguous data
ImGuiStorage Map; // ID->Index
ImPoolIdx FreeIdx; // Next free idx to use
- ImPoolIdx AliveCount; // Number of active/alive items (for display purpose only)
+ ImPoolIdx AliveCount; // Number of active/alive items (for display purpose)
ImPool() { FreeIdx = AliveCount = 0; }
~ImPool() { Clear(); }
@@ -627,13 +627,14 @@
void Remove(ImGuiID key, ImPoolIdx idx) { Buf[idx].~T(); *(int*)&Buf[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); AliveCount--; }
void Reserve(int capacity) { Buf.reserve(capacity); Map.Data.reserve(capacity); }
- // To iterate a ImPool: for (int n = 0; n < pool.GetBufSize(); n++) if (T* t = pool.TryGetBufData(n)) { ... }
- // Can be avoided if you know .Remove() has never been called on the pool, or AliveCount == GetBufSize()
- int GetAliveCount() const { return AliveCount; } // Number of active/alive items in the pool (for display purpose only)
- int GetBufSize() const { IM_ASSERT(Buf.Size == Map.Data.Size); return Buf.Size; }
- T* TryGetBufData(ImPoolIdx n) { int idx = Map.Data[n].val_i; if (idx == -1) return NULL; return GetByIndex(idx); }
+ // To iterate a ImPool: for (int n = 0; n < pool.GetMapSize(); n++) if (T* t = pool.TryGetMapData(n)) { ... }
+ // Can be avoided if you know .Remove() has never been called on the pool, or AliveCount == GetMapSize()
+ int GetAliveCount() const { return AliveCount; } // Number of active/alive items in the pool (for display purpose)
+ int GetBufSize() const { return Buf.Size; }
+ int GetMapSize() const { return Map.Data.Size; } // It is the map we need iterate to find valid items, since we don't have "alive" storage anywhere
+ T* TryGetMapData(ImPoolIdx n) { int idx = Map.Data[n].val_i; if (idx == -1) return NULL; return GetByIndex(idx); }
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
- int GetSize() { return GetBufSize(); } // For ImPlot: should use GetMapSize() from (IMGUI_VERSION_NUM >= 18303)
+ int GetSize() { return GetMapSize(); } // For ImPlot: should use GetMapSize() from (IMGUI_VERSION_NUM >= 18304)
#endif
};
diff --git a/imgui_tables.cpp b/imgui_tables.cpp
index 47783e5..971dce3 100644
--- a/imgui_tables.cpp
+++ b/imgui_tables.cpp
@@ -3298,8 +3298,8 @@
static void TableSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
{
ImGuiContext& g = *ctx;
- for (int i = 0; i != g.Tables.GetBufSize(); i++)
- if (ImGuiTable* table = g.Tables.TryGetBufData(i))
+ for (int i = 0; i != g.Tables.GetMapSize(); i++)
+ if (ImGuiTable* table = g.Tables.TryGetMapData(i))
table->SettingsOffset = -1;
g.SettingsTables.clear();
}
@@ -3308,8 +3308,8 @@
static void TableSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
{
ImGuiContext& g = *ctx;
- for (int i = 0; i != g.Tables.GetBufSize(); i++)
- if (ImGuiTable* table = g.Tables.TryGetBufData(i))
+ for (int i = 0; i != g.Tables.GetMapSize(); i++)
+ if (ImGuiTable* table = g.Tables.TryGetMapData(i))
{
table->IsSettingsRequestLoad = true;
table->SettingsOffset = -1;