mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Settings: Added Clear Settings in Metrics. (#2188) + Preserve last loaded copy in internal buffer used for save (so it can be browsed easily).
This commit is contained in:
parent
9ee442d3f0
commit
b6a04d7750
56
imgui.cpp
56
imgui.cpp
@ -9598,6 +9598,19 @@ void ImGui::LogButtons()
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] SETTINGS
|
// [SECTION] SETTINGS
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
// - UpdateSettings() [Internal]
|
||||||
|
// - MarkIniSettingsDirty() [Internal]
|
||||||
|
// - CreateNewWindowSettings() [Internal]
|
||||||
|
// - FindWindowSettings() [Internal]
|
||||||
|
// - FindOrCreateWindowSettings() [Internal]
|
||||||
|
// - FindSettingsHandler() [Internal]
|
||||||
|
// - ClearIniSettings() [Internal]
|
||||||
|
// - LoadIniSettingsFromDisk()
|
||||||
|
// - LoadIniSettingsFromMemory()
|
||||||
|
// - SaveIniSettingsToDisk()
|
||||||
|
// - SaveIniSettingsToMemory()
|
||||||
|
// - WindowSettingsHandler_***() [Internal]
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Called by NewFrame()
|
// Called by NewFrame()
|
||||||
void ImGui::UpdateSettings()
|
void ImGui::UpdateSettings()
|
||||||
@ -9680,16 +9693,6 @@ ImGuiWindowSettings* ImGui::FindOrCreateWindowSettings(const char* name)
|
|||||||
return CreateNewWindowSettings(name);
|
return CreateNewWindowSettings(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::LoadIniSettingsFromDisk(const char* ini_filename)
|
|
||||||
{
|
|
||||||
size_t file_data_size = 0;
|
|
||||||
char* file_data = (char*)ImFileLoadToMemory(ini_filename, "rb", &file_data_size);
|
|
||||||
if (!file_data)
|
|
||||||
return;
|
|
||||||
LoadIniSettingsFromMemory(file_data, (size_t)file_data_size);
|
|
||||||
IM_FREE(file_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name)
|
ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
@ -9700,6 +9703,25 @@ ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImGui::ClearIniSettings()
|
||||||
|
{
|
||||||
|
ImGuiContext& g = *GImGui;
|
||||||
|
g.SettingsIniData.clear();
|
||||||
|
for (int i = 0; i != g.Windows.Size; i++)
|
||||||
|
g.Windows[i]->SettingsOffset = -1;
|
||||||
|
g.SettingsWindows.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui::LoadIniSettingsFromDisk(const char* ini_filename)
|
||||||
|
{
|
||||||
|
size_t file_data_size = 0;
|
||||||
|
char* file_data = (char*)ImFileLoadToMemory(ini_filename, "rb", &file_data_size);
|
||||||
|
if (!file_data)
|
||||||
|
return;
|
||||||
|
LoadIniSettingsFromMemory(file_data, (size_t)file_data_size);
|
||||||
|
IM_FREE(file_data);
|
||||||
|
}
|
||||||
|
|
||||||
// Zero-tolerance, no error reporting, cheap .ini parsing
|
// Zero-tolerance, no error reporting, cheap .ini parsing
|
||||||
void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
|
void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
|
||||||
{
|
{
|
||||||
@ -9711,10 +9733,11 @@ void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
|
|||||||
// For our convenience and to make the code simpler, we'll also write zero-terminators within the buffer. So let's create a writable copy..
|
// For our convenience and to make the code simpler, we'll also write zero-terminators within the buffer. So let's create a writable copy..
|
||||||
if (ini_size == 0)
|
if (ini_size == 0)
|
||||||
ini_size = strlen(ini_data);
|
ini_size = strlen(ini_data);
|
||||||
char* buf = (char*)IM_ALLOC(ini_size + 1);
|
g.SettingsIniData.Buf.resize((int)ini_size + 1);
|
||||||
char* buf_end = buf + ini_size;
|
char* const buf = g.SettingsIniData.Buf.Data;
|
||||||
|
char* const buf_end = buf + ini_size;
|
||||||
memcpy(buf, ini_data, ini_size);
|
memcpy(buf, ini_data, ini_size);
|
||||||
buf[ini_size] = 0;
|
buf_end[0] = 0;
|
||||||
|
|
||||||
void* entry_data = NULL;
|
void* entry_data = NULL;
|
||||||
ImGuiSettingsHandler* entry_handler = NULL;
|
ImGuiSettingsHandler* entry_handler = NULL;
|
||||||
@ -9752,8 +9775,10 @@ void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
|
|||||||
entry_handler->ReadLineFn(&g, entry_handler, entry_data, line);
|
entry_handler->ReadLineFn(&g, entry_handler, entry_data, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IM_FREE(buf);
|
|
||||||
g.SettingsLoaded = true;
|
g.SettingsLoaded = true;
|
||||||
|
|
||||||
|
// [DEBUG] Restore untouched copy so it can be browsed in Metrics (not strictly necessary)
|
||||||
|
memcpy(buf, ini_data, ini_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::SaveIniSettingsToDisk(const char* ini_filename)
|
void ImGui::SaveIniSettingsToDisk(const char* ini_filename)
|
||||||
@ -10407,6 +10432,9 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
// Settings
|
// Settings
|
||||||
if (ImGui::TreeNode("Settings"))
|
if (ImGui::TreeNode("Settings"))
|
||||||
{
|
{
|
||||||
|
if (ImGui::SmallButton("Clear"))
|
||||||
|
ImGui::ClearIniSettings();
|
||||||
|
ImGui::SameLine();
|
||||||
if (ImGui::SmallButton("Save to disk"))
|
if (ImGui::SmallButton("Save to disk"))
|
||||||
ImGui::SaveIniSettingsToDisk(g.IO.IniFilename);
|
ImGui::SaveIniSettingsToDisk(g.IO.IniFilename);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
@ -1718,6 +1718,7 @@ namespace ImGui
|
|||||||
// Settings
|
// Settings
|
||||||
IMGUI_API void MarkIniSettingsDirty();
|
IMGUI_API void MarkIniSettingsDirty();
|
||||||
IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window);
|
IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window);
|
||||||
|
IMGUI_API void ClearIniSettings();
|
||||||
IMGUI_API ImGuiWindowSettings* CreateNewWindowSettings(const char* name);
|
IMGUI_API ImGuiWindowSettings* CreateNewWindowSettings(const char* name);
|
||||||
IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id);
|
IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id);
|
||||||
IMGUI_API ImGuiWindowSettings* FindOrCreateWindowSettings(const char* name);
|
IMGUI_API ImGuiWindowSettings* FindOrCreateWindowSettings(const char* name);
|
||||||
|
Loading…
Reference in New Issue
Block a user