mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-27 16:29:02 +08:00
Internals: ImPool: Renaming.
This commit is contained in:
parent
28f1d60de1
commit
a337e219b6
@ -9830,9 +9830,9 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
if (ImGui::TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.Data.Size))
|
||||
if (ImGui::TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.GetSize()))
|
||||
{
|
||||
for (int n = 0; n < g.TabBars.Data.Size; n++)
|
||||
for (int n = 0; n < g.TabBars.GetSize(); n++)
|
||||
Funcs::NodeTabBar(g.TabBars.GetByIndex(n));
|
||||
ImGui::TreePop();
|
||||
}
|
||||
@ -9845,7 +9845,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.Data.Size))
|
||||
if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.GetSize()))
|
||||
{
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
@ -307,23 +307,23 @@ typedef int ImPoolIdx;
|
||||
template<typename T>
|
||||
struct IMGUI_API ImPool
|
||||
{
|
||||
ImVector<T> Data; // Contiguous data
|
||||
ImVector<T> Buf; // Contiguous data
|
||||
ImGuiStorage Map; // ID->Index
|
||||
ImPoolIdx FreeIdx; // Next free idx to use
|
||||
|
||||
ImPool() { FreeIdx = 0; }
|
||||
~ImPool() { Clear(); }
|
||||
T* GetByKey(ImGuiID key) { int idx = Map.GetInt(key, -1); return (idx != -1) ? &Data[idx] : NULL; }
|
||||
T* GetByIndex(ImPoolIdx n) { return &Data[n]; }
|
||||
ImPoolIdx GetIndex(const T* p) const { IM_ASSERT(p >= Data.Data && p < Data.Data + Data.Size); return (ImPoolIdx)(p - Data.Data); }
|
||||
T* GetOrAddByKey(ImGuiID key) { int* p_idx = Map.GetIntRef(key, -1); if (*p_idx != -1) return &Data[*p_idx]; *p_idx = FreeIdx; return Add(); }
|
||||
bool Contains(const T* p) const { return (p >= Data.Data && p < Data.Data + Data.Size); }
|
||||
void Clear() { for (int n = 0; n < Map.Data.Size; n++) { int idx = Map.Data[n].val_i; if (idx != -1) Data[idx].~T(); } Map.Clear(); Data.clear(); FreeIdx = 0; }
|
||||
T* Add() { int idx = FreeIdx; if (idx == Data.Size) { Data.resize(Data.Size + 1); FreeIdx++; } else { FreeIdx = *(int*)&Data[idx]; } IM_PLACEMENT_NEW(&Data[idx]) T(); return &Data[idx]; }
|
||||
T* GetByKey(ImGuiID key) { int idx = Map.GetInt(key, -1); return (idx != -1) ? &Buf[idx] : NULL; }
|
||||
T* GetByIndex(ImPoolIdx n) { return &Buf[n]; }
|
||||
ImPoolIdx GetIndex(const T* p) const { IM_ASSERT(p >= Buf.Data && p < Buf.Data + Buf.Size); return (ImPoolIdx)(p - Buf.Data); }
|
||||
T* GetOrAddByKey(ImGuiID key) { int* p_idx = Map.GetIntRef(key, -1); if (*p_idx != -1) return &Buf[*p_idx]; *p_idx = FreeIdx; return Add(); }
|
||||
bool Contains(const T* p) const { return (p >= Buf.Data && p < Buf.Data + Buf.Size); }
|
||||
void Clear() { for (int n = 0; n < Map.Data.Size; n++) { int idx = Map.Data[n].val_i; if (idx != -1) Buf[idx].~T(); } Map.Clear(); Buf.clear(); FreeIdx = 0; }
|
||||
T* Add() { int idx = FreeIdx; if (idx == Buf.Size) { Buf.resize(Buf.Size + 1); FreeIdx++; } else { FreeIdx = *(int*)&Buf[idx]; } IM_PLACEMENT_NEW(&Buf[idx]) T(); return &Buf[idx]; }
|
||||
void Remove(ImGuiID key, const T* p) { Remove(key, GetIndex(p)); }
|
||||
void Remove(ImGuiID key, ImPoolIdx idx) { Data[idx].~T(); *(int*)&Data[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); }
|
||||
void Reserve(int capacity) { Data.reserve(capacity); Map.Data.reserve(capacity); }
|
||||
int GetSize() const { return Data.Size; }
|
||||
void Remove(ImGuiID key, ImPoolIdx idx) { Buf[idx].~T(); *(int*)&Buf[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); }
|
||||
void Reserve(int capacity) { Buf.reserve(capacity); Map.Data.reserve(capacity); }
|
||||
int GetSize() const { return Buf.Size; }
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user