mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Internal: FindWindowByName() faster and doesn't touch every windows
This commit is contained in:
parent
8e6adc78af
commit
571b08f315
10
imgui.cpp
10
imgui.cpp
@ -3920,13 +3920,9 @@ static ImVec2 FindBestPopupWindowPos(const ImVec2& base_pos, const ImVec2& size,
|
||||
|
||||
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;
|
||||
ImGuiID id = ImHash(name, 0);
|
||||
for (int i = 0; i < g.Windows.Size; i++)
|
||||
if (g.Windows[i]->ID == id)
|
||||
return g.Windows[i];
|
||||
return NULL;
|
||||
return (ImGuiWindow*)g.WindowsById.GetVoidPtr(id);
|
||||
}
|
||||
|
||||
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));
|
||||
IM_PLACEMENT_NEW(window) ImGuiWindow(name);
|
||||
window->Flags = flags;
|
||||
g.WindowsById.SetVoidPtr(window->ID, window);
|
||||
|
||||
if (flags & ImGuiWindowFlags_NoSavedSettings)
|
||||
{
|
||||
@ -5280,8 +5277,7 @@ bool ImGui::IsWindowAppearing()
|
||||
|
||||
void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiCond cond)
|
||||
{
|
||||
ImGuiWindow* window = FindWindowByName(name);
|
||||
if (window)
|
||||
if (ImGuiWindow* window = FindWindowByName(name))
|
||||
SetWindowCollapsed(window, collapsed, cond);
|
||||
}
|
||||
|
||||
|
@ -422,6 +422,7 @@ struct ImGuiContext
|
||||
ImVector<ImGuiWindow*> Windows;
|
||||
ImVector<ImGuiWindow*> WindowsSortBuffer;
|
||||
ImVector<ImGuiWindow*> CurrentWindowStack;
|
||||
ImGuiStorage WindowsById;
|
||||
ImGuiWindow* CurrentWindow; // Being drawn into
|
||||
ImGuiWindow* NavWindow; // Nav/focused window for navigation
|
||||
ImGuiWindow* HoveredWindow; // Will catch mouse inputs
|
||||
|
Loading…
Reference in New Issue
Block a user