Internals: fixed ImPool:: iteration, rename GetBufSize to GetMapSize. Amend c6c82b9f

This commit is contained in:
ocornut 2021-06-04 17:21:59 +02:00
parent c6c82b9f1d
commit 94b680e830
4 changed files with 21 additions and 20 deletions

View File

@ -11023,9 +11023,9 @@ void ImGui::ShowMetricsWindow(bool* p_open)
cfg->ShowTablesRects |= Combo("##show_table_rects_type", &cfg->ShowTablesRectsType, trt_rects_names, TRT_Count, TRT_Count); cfg->ShowTablesRects |= Combo("##show_table_rects_type", &cfg->ShowTablesRectsType, trt_rects_names, TRT_Count, TRT_Count);
if (cfg->ShowTablesRects && g.NavWindow != NULL) 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)) if (table == NULL || table->LastFrameActive < g.FrameCount - 1 || (table->OuterWindow != g.NavWindow && table->InnerWindow != g.NavWindow))
continue; continue;
@ -11110,8 +11110,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
// Details for TabBars // Details for TabBars
if (TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.GetAliveCount())) if (TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.GetAliveCount()))
{ {
for (int n = 0; n < g.TabBars.GetBufSize(); n++) for (int n = 0; n < g.TabBars.GetMapSize(); n++)
if (ImGuiTabBar* tab_bar = g.TabBars.TryGetBufData(n)) if (ImGuiTabBar* tab_bar = g.TabBars.TryGetMapData(n))
{ {
PushID(tab_bar); PushID(tab_bar);
DebugNodeTabBar(tab_bar, "TabBar"); DebugNodeTabBar(tab_bar, "TabBar");
@ -11123,8 +11123,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
// Details for Tables // Details for Tables
if (TreeNode("Tables", "Tables (%d)", g.Tables.GetAliveCount())) if (TreeNode("Tables", "Tables (%d)", g.Tables.GetAliveCount()))
{ {
for (int n = 0; n < g.Tables.GetBufSize(); n++) for (int n = 0; n < g.Tables.GetMapSize(); n++)
if (ImGuiTable* table = g.Tables.TryGetBufData(n)) if (ImGuiTable* table = g.Tables.TryGetMapData(n))
DebugNodeTable(table); DebugNodeTable(table);
TreePop(); TreePop();
} }
@ -11259,9 +11259,9 @@ void ImGui::ShowMetricsWindow(bool* p_open)
// Overlay: Display Tables Rectangles // Overlay: Display Tables Rectangles
if (cfg->ShowTablesRects) 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) if (table == NULL || table->LastFrameActive < g.FrameCount - 1)
continue; continue;
ImDrawList* draw_list = GetForegroundDrawList(table->OuterWindow); ImDrawList* draw_list = GetForegroundDrawList(table->OuterWindow);

View File

@ -61,7 +61,7 @@ Index of this file:
// Version // 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) // (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 "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_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_TABLE #define IMGUI_HAS_TABLE

View File

@ -612,7 +612,7 @@ struct IMGUI_API ImPool
ImVector<T> Buf; // Contiguous data ImVector<T> Buf; // Contiguous data
ImGuiStorage Map; // ID->Index ImGuiStorage Map; // ID->Index
ImPoolIdx FreeIdx; // Next free idx to use 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() { FreeIdx = AliveCount = 0; }
~ImPool() { Clear(); } ~ImPool() { Clear(); }
@ -627,13 +627,14 @@ struct IMGUI_API ImPool
void Remove(ImGuiID key, ImPoolIdx idx) { Buf[idx].~T(); *(int*)&Buf[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); AliveCount--; } 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); } 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)) { ... } // 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 == GetBufSize() // 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 only) int GetAliveCount() const { return AliveCount; } // Number of active/alive items in the pool (for display purpose)
int GetBufSize() const { IM_ASSERT(Buf.Size == Map.Data.Size); return Buf.Size; } int GetBufSize() const { return Buf.Size; }
T* TryGetBufData(ImPoolIdx n) { int idx = Map.Data[n].val_i; if (idx == -1) return NULL; return GetByIndex(idx); } 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 #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 #endif
}; };

View File

@ -3298,8 +3298,8 @@ void ImGui::TableLoadSettings(ImGuiTable* table)
static void TableSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*) static void TableSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
{ {
ImGuiContext& g = *ctx; ImGuiContext& g = *ctx;
for (int i = 0; i != g.Tables.GetBufSize(); i++) for (int i = 0; i != g.Tables.GetMapSize(); i++)
if (ImGuiTable* table = g.Tables.TryGetBufData(i)) if (ImGuiTable* table = g.Tables.TryGetMapData(i))
table->SettingsOffset = -1; table->SettingsOffset = -1;
g.SettingsTables.clear(); g.SettingsTables.clear();
} }
@ -3308,8 +3308,8 @@ static void TableSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandle
static void TableSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*) static void TableSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
{ {
ImGuiContext& g = *ctx; ImGuiContext& g = *ctx;
for (int i = 0; i != g.Tables.GetBufSize(); i++) for (int i = 0; i != g.Tables.GetMapSize(); i++)
if (ImGuiTable* table = g.Tables.TryGetBufData(i)) if (ImGuiTable* table = g.Tables.TryGetMapData(i))
{ {
table->IsSettingsRequestLoad = true; table->IsSettingsRequestLoad = true;
table->SettingsOffset = -1; table->SettingsOffset = -1;