Internal: FindWindowByName() faster and doesn't touch every windows

This commit is contained in:
omar 2017-11-07 13:59:55 +01:00
parent 8e6adc78af
commit 571b08f315
2 changed files with 4 additions and 7 deletions

View File

@ -3920,13 +3920,9 @@ static ImVec2 FindBestPopupWindowPos(const ImVec2& base_pos, const ImVec2& size,
ImGuiWindow* ImGui::FindWindowByName(const char* name) ImGuiWindow* ImGui::FindWindowByName(const char* name)
{ {
// FIXME-OPT: Store sorted hashes -> pointers so we can do a bissection in a contiguous block
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiID id = ImHash(name, 0); ImGuiID id = ImHash(name, 0);
for (int i = 0; i < g.Windows.Size; i++) return (ImGuiWindow*)g.WindowsById.GetVoidPtr(id);
if (g.Windows[i]->ID == id)
return g.Windows[i];
return NULL;
} }
static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags) static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags)
@ -3937,6 +3933,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow)); ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
IM_PLACEMENT_NEW(window) ImGuiWindow(name); IM_PLACEMENT_NEW(window) ImGuiWindow(name);
window->Flags = flags; window->Flags = flags;
g.WindowsById.SetVoidPtr(window->ID, window);
if (flags & ImGuiWindowFlags_NoSavedSettings) if (flags & ImGuiWindowFlags_NoSavedSettings)
{ {
@ -5280,8 +5277,7 @@ bool ImGui::IsWindowAppearing()
void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiCond cond) void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiCond cond)
{ {
ImGuiWindow* window = FindWindowByName(name); if (ImGuiWindow* window = FindWindowByName(name))
if (window)
SetWindowCollapsed(window, collapsed, cond); SetWindowCollapsed(window, collapsed, cond);
} }

View File

@ -422,6 +422,7 @@ struct ImGuiContext
ImVector<ImGuiWindow*> Windows; ImVector<ImGuiWindow*> Windows;
ImVector<ImGuiWindow*> WindowsSortBuffer; ImVector<ImGuiWindow*> WindowsSortBuffer;
ImVector<ImGuiWindow*> CurrentWindowStack; ImVector<ImGuiWindow*> CurrentWindowStack;
ImGuiStorage WindowsById;
ImGuiWindow* CurrentWindow; // Being drawn into ImGuiWindow* CurrentWindow; // Being drawn into
ImGuiWindow* NavWindow; // Nav/focused window for navigation ImGuiWindow* NavWindow; // Nav/focused window for navigation
ImGuiWindow* HoveredWindow; // Will catch mouse inputs ImGuiWindow* HoveredWindow; // Will catch mouse inputs