diff --git a/imgui.cpp b/imgui.cpp index f08c73ef7..60b601494 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2085,6 +2085,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) LastFrameActive = -1; ItemWidthDefault = 0.0f; FontWindowScale = 1.0f; + SettingsIdx = -1; DrawList = &DrawListInst; DrawList->_OwnerName = Name; @@ -3876,9 +3877,14 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* imgui_ctx, ImGuiSetting ImGuiWindow* window = g.Windows[i]; if (window->Flags & ImGuiWindowFlags_NoSavedSettings) continue; - ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID); + + ImGuiWindowSettings* settings = (window->SettingsIdx != -1) ? &g.SettingsWindows[window->SettingsIdx] : ImGui::FindWindowSettings(window->ID); if (!settings) + { settings = AddWindowSettings(window->Name); + window->SettingsIdx = g.SettingsWindows.index_from_pointer(settings); + } + IM_ASSERT(settings->ID == window->ID); settings->Pos = window->Pos; settings->Size = window->SizeFull; settings->Collapsed = window->Collapsed; @@ -3981,7 +3987,7 @@ ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id) { ImGuiContext& g = *GImGui; for (int i = 0; i != g.SettingsWindows.Size; i++) - if (g.SettingsWindows[i].Id == id) + if (g.SettingsWindows[i].ID == id) return &g.SettingsWindows[i]; return NULL; } @@ -3992,7 +3998,7 @@ static ImGuiWindowSettings* AddWindowSettings(const char* name) g.SettingsWindows.push_back(ImGuiWindowSettings()); ImGuiWindowSettings* settings = &g.SettingsWindows.back(); settings->Name = ImStrdup(name); - settings->Id = ImHash(name, 0); + settings->ID = ImHash(name, 0); return settings; } @@ -5695,6 +5701,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl // Retrieve settings from .ini file if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings(window->ID)) { + window->SettingsIdx = g.SettingsWindows.index_from_pointer(settings); SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); window->Pos = ImFloor(settings->Pos); window->Collapsed = settings->Collapsed; diff --git a/imgui_internal.h b/imgui_internal.h index 049851436..cc5c77c0a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -440,12 +440,12 @@ struct IMGUI_API ImGuiTextEditState struct ImGuiWindowSettings { char* Name; - ImGuiID Id; + ImGuiID ID; ImVec2 Pos; ImVec2 Size; bool Collapsed; - ImGuiWindowSettings() { Name = NULL; Id = 0; Pos = Size = ImVec2(0,0); Collapsed = false; } + ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2(0,0); Collapsed = false; } }; struct ImGuiSettingsHandler @@ -994,6 +994,7 @@ struct IMGUI_API ImGuiWindow ImGuiStorage StateStorage; ImVector ColumnsStorage; float FontWindowScale; // User scale multiplier per-window + int SettingsIdx; // Index into SettingsWindow[] (indices are always valid as we only grow the array from the back) ImDrawList* DrawList; // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer) ImDrawList DrawListInst;