Settings: fixed issues caliing ClearWindowSettings() followed by LoadIniSettingsFromMemory().

While not done with core, this would be useful to load .ini over a clean slate.
This commit is contained in:
ocornut
2026-07-10 16:32:07 +02:00
parent 0ff4a8a900
commit baeea39c1a

View File

@@ -6710,12 +6710,34 @@ ImGuiWindow* ImGui::FindWindowByName(const char* name)
static void ApplyWindowSettings(ImGuiWindow* window, ImGuiWindowSettings* settings)
{
window->Pos = ImTrunc(ImVec2(settings->Pos.x, settings->Pos.y));
if (settings->Size.x > 0 && settings->Size.y > 0)
window->Size = window->SizeFull = ImTrunc(ImVec2(settings->Size.x, settings->Size.y));
window->Collapsed = settings->Collapsed;
if (settings != NULL)
{
window->Pos = ImTrunc(ImVec2(settings->Pos.x, settings->Pos.y));
if (settings->Size.x > 0 && settings->Size.y > 0)
{
window->Size = window->SizeFull = ImTrunc(ImVec2(settings->Size.x, settings->Size.y));
window->AutoFitFramesX = window->AutoFitFramesY = 0;
}
window->Collapsed = settings->Collapsed;
SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false);
}
window->DC.CursorStartPos = window->DC.CursorMaxPos = window->DC.IdealMaxPos = window->Pos; // So first call to CalcWindowContentSizes() doesn't return crazy values
if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
{
window->AutoFitFramesX = window->AutoFitFramesY = 2;
window->AutoFitOnlyGrows = false;
}
else
{
window->AutoFitFramesX = (window->Size.x <= 0.0f) ? 2 : 0;
window->AutoFitFramesY = (window->Size.y <= 0.0f) ? 2 : 0;
window->AutoFitOnlyGrows = (window->AutoFitFramesX > 0) || (window->AutoFitFramesY > 0);
}
}
// Note that 'settings' may be NULL.
// Sets _Once, _Appearing, _FirstUseEver. _FirstUseEver will be cleared again if there are settings.
static void InitOrLoadWindowSettings(ImGuiWindow* window, ImGuiWindowSettings* settings)
{
// Initial window state with e.g. default/arbitrary window position
@@ -6725,28 +6747,9 @@ static void InitOrLoadWindowSettings(ImGuiWindow* window, ImGuiWindowSettings* s
window->Pos = main_viewport->Pos + ImVec2(60, 60);
window->Size = window->SizeFull = ImVec2(0, 0);
window->SetWindowPosAllowFlags = window->SetWindowSizeAllowFlags = window->SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing;
ApplyWindowSettings(window, settings);
if (settings != NULL)
{
settings->LastUsedDate = g.SessionDate;
SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false);
ApplyWindowSettings(window, settings);
}
window->DC.CursorStartPos = window->DC.CursorMaxPos = window->DC.IdealMaxPos = window->Pos; // So first call to CalcWindowContentSizes() doesn't return crazy values
if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
{
window->AutoFitFramesX = window->AutoFitFramesY = 2;
window->AutoFitOnlyGrows = false;
}
else
{
if (window->Size.x <= 0.0f)
window->AutoFitFramesX = 2;
if (window->Size.y <= 0.0f)
window->AutoFitFramesY = 2;
window->AutoFitOnlyGrows = (window->AutoFitFramesX > 0) || (window->AutoFitFramesY > 0);
}
}
static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags)