Renaming and massaging internal Settings/Ini functions (#923)

docking
ocornut 8 years ago
parent 0b6211f907
commit 55d651812d

@ -684,9 +684,9 @@ static void AddWindowToSortedBuffer(ImVector<ImGuiWindow*>& out_sort
static ImGuiIniData* FindWindowSettings(const char* name); static ImGuiIniData* FindWindowSettings(const char* name);
static ImGuiIniData* AddWindowSettings(const char* name); static ImGuiIniData* AddWindowSettings(const char* name);
static void LoadSettings(); static void LoadIniSettingsFromDisk(const char* ini_filename);
static void SaveSettings(); static void SaveIniSettingsToDisk(const char* ini_filename);
static void MarkSettingsDirty(); static void MarkIniSettingsDirty();
static void PushColumnClipRect(int column_index = -1); static void PushColumnClipRect(int column_index = -1);
static ImRect GetVisibleRect(); static ImRect GetVisibleRect();
@ -2135,7 +2135,7 @@ void ImGui::NewFrame()
IM_PLACEMENT_NEW(g.LogClipboard) ImGuiTextBuffer(); IM_PLACEMENT_NEW(g.LogClipboard) ImGuiTextBuffer();
IM_ASSERT(g.Settings.empty()); IM_ASSERT(g.Settings.empty());
LoadSettings(); LoadIniSettingsFromDisk(g.IO.IniFilename);
g.Initialized = true; g.Initialized = true;
} }
@ -2221,7 +2221,7 @@ void ImGui::NewFrame()
{ {
g.MovedWindow->PosFloat += g.IO.MouseDelta; g.MovedWindow->PosFloat += g.IO.MouseDelta;
if (!(g.MovedWindow->Flags & ImGuiWindowFlags_NoSavedSettings) && (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)) if (!(g.MovedWindow->Flags & ImGuiWindowFlags_NoSavedSettings) && (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f))
MarkSettingsDirty(); MarkIniSettingsDirty();
} }
FocusWindow(g.MovedWindow); FocusWindow(g.MovedWindow);
} }
@ -2243,7 +2243,7 @@ void ImGui::NewFrame()
{ {
g.SettingsDirtyTimer -= g.IO.DeltaTime; g.SettingsDirtyTimer -= g.IO.DeltaTime;
if (g.SettingsDirtyTimer <= 0.0f) if (g.SettingsDirtyTimer <= 0.0f)
SaveSettings(); SaveIniSettingsToDisk(g.IO.IniFilename);
} }
// Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow // Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow
@ -2370,7 +2370,7 @@ void ImGui::Shutdown()
if (!g.Initialized) if (!g.Initialized)
return; return;
SaveSettings(); SaveIniSettingsToDisk(g.IO.IniFilename);
for (int i = 0; i < g.Windows.Size; i++) for (int i = 0; i < g.Windows.Size; i++)
{ {
@ -2450,15 +2450,14 @@ static ImGuiIniData* AddWindowSettings(const char* name)
// Zero-tolerance, poor-man .ini parsing // Zero-tolerance, poor-man .ini parsing
// FIXME: Write something less rubbish // FIXME: Write something less rubbish
static void LoadSettings() static void LoadIniSettingsFromDisk(const char* ini_filename)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
const char* filename = g.IO.IniFilename; if (!ini_filename)
if (!filename)
return; return;
int file_size; int file_size;
char* file_data = (char*)ImLoadFileToMemory(filename, "rb", &file_size, 1); char* file_data = (char*)ImLoadFileToMemory(ini_filename, "rb", &file_size, 1);
if (!file_data) if (!file_data)
return; return;
@ -2496,11 +2495,11 @@ static void LoadSettings()
ImGui::MemFree(file_data); ImGui::MemFree(file_data);
} }
static void SaveSettings() static void SaveIniSettingsToDisk(const char* ini_filename)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
const char* filename = g.IO.IniFilename; g.SettingsDirtyTimer = 0.0f;
if (!filename) if (!ini_filename)
return; return;
// Gather data from windows that were active during this session // Gather data from windows that were active during this session
@ -2517,7 +2516,7 @@ static void SaveSettings()
// Write .ini file // Write .ini file
// If a window wasn't opened in this session we preserve its settings // If a window wasn't opened in this session we preserve its settings
FILE* f = ImFileOpen(filename, "wt"); FILE* f = ImFileOpen(ini_filename, "wt");
if (!f) if (!f)
return; return;
for (int i = 0; i != g.Settings.Size; i++) for (int i = 0; i != g.Settings.Size; i++)
@ -2538,7 +2537,7 @@ static void SaveSettings()
fclose(f); fclose(f);
} }
static void MarkSettingsDirty() static void MarkIniSettingsDirty()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (g.SettingsDirtyTimer <= 0.0f) if (g.SettingsDirtyTimer <= 0.0f)
@ -4010,7 +4009,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
{ {
window->Collapsed = !window->Collapsed; window->Collapsed = !window->Collapsed;
if (!(flags & ImGuiWindowFlags_NoSavedSettings)) if (!(flags & ImGuiWindowFlags_NoSavedSettings))
MarkSettingsDirty(); MarkIniSettingsDirty();
FocusWindow(window); FocusWindow(window);
} }
} }
@ -4085,7 +4084,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
if (window->AutoFitFramesY > 0) if (window->AutoFitFramesY > 0)
window->SizeFull.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y; window->SizeFull.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y;
if (!(flags & ImGuiWindowFlags_NoSavedSettings)) if (!(flags & ImGuiWindowFlags_NoSavedSettings))
MarkSettingsDirty(); MarkIniSettingsDirty();
} }
} }
@ -4214,7 +4213,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
// Manual auto-fit when double-clicking // Manual auto-fit when double-clicking
ApplySizeFullWithConstraint(window, size_auto_fit); ApplySizeFullWithConstraint(window, size_auto_fit);
if (!(flags & ImGuiWindowFlags_NoSavedSettings)) if (!(flags & ImGuiWindowFlags_NoSavedSettings))
MarkSettingsDirty(); MarkIniSettingsDirty();
SetActiveID(0); SetActiveID(0);
} }
else if (held) else if (held)
@ -4222,7 +4221,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
// We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
ApplySizeFullWithConstraint(window, (g.IO.MousePos - g.ActiveIdClickOffset + resize_rect.GetSize()) - window->Pos); ApplySizeFullWithConstraint(window, (g.IO.MousePos - g.ActiveIdClickOffset + resize_rect.GetSize()) - window->Pos);
if (!(flags & ImGuiWindowFlags_NoSavedSettings)) if (!(flags & ImGuiWindowFlags_NoSavedSettings))
MarkSettingsDirty(); MarkIniSettingsDirty();
} }
window->Size = window->SizeFull; window->Size = window->SizeFull;

Loading…
Cancel
Save