mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57:00 +00:00
Misc: Optimized storage of window settings data (reducing allocation count).
This commit is contained in:
parent
3929255b77
commit
4c13807b7d
@ -68,6 +68,7 @@ Other Changes:
|
||||
incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897)
|
||||
- DragScalar, SliderScalar, InputScalar: Added p_ prefix to parameter that are pointers to the data
|
||||
to clarify how they are used, and more comments redirecting to the demo code. (#2844)
|
||||
- Misc: Optimized storage of window settings data (reducing allocation count).
|
||||
- Misc: Windows: Do not use _wfopen() if IMGUI_DISABLE_WIN32_FUNCTIONS is defined. (#2815)
|
||||
- Docs: Improved and moved FAQ to docs/FAQ.md so it can be readable on the web. [@ButternCream, @ocornut]
|
||||
- Docs: Added permanent redirect from https://www.dearimgui.org/faq to FAQ page.
|
||||
|
12
imgui.cpp
12
imgui.cpp
@ -3809,8 +3809,7 @@ void ImGui::Shutdown(ImGuiContext* context)
|
||||
g.PrivateClipboard.clear();
|
||||
g.InputTextState.ClearFreeMemory();
|
||||
|
||||
for (int i = 0; i < g.SettingsWindows.Size; i++)
|
||||
IM_DELETE(g.SettingsWindows[i].Name);
|
||||
g.SettingsWindowsNames.clear();
|
||||
g.SettingsWindows.clear();
|
||||
g.SettingsHandlers.clear();
|
||||
|
||||
@ -9205,8 +9204,10 @@ ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name)
|
||||
if (const char* p = strstr(name, "###"))
|
||||
name = p;
|
||||
#endif
|
||||
settings->Name = ImStrdup(name);
|
||||
settings->ID = ImHashStr(name);
|
||||
size_t name_len = strlen(name);
|
||||
settings->NameOffset = g.SettingsWindowsNames.size();
|
||||
g.SettingsWindowsNames.append(name, name + name_len + 1); // Append with zero terminator
|
||||
settings->ID = ImHashStr(name, name_len);
|
||||
return settings;
|
||||
}
|
||||
|
||||
@ -9387,7 +9388,8 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
|
||||
for (int i = 0; i != g.SettingsWindows.Size; i++)
|
||||
{
|
||||
const ImGuiWindowSettings* settings = &g.SettingsWindows[i];
|
||||
buf->appendf("[%s][%s]\n", handler->TypeName, settings->Name);
|
||||
const char* settings_name = g.SettingsWindowsNames.c_str() + settings->NameOffset;
|
||||
buf->appendf("[%s][%s]\n", handler->TypeName, settings_name);
|
||||
buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y);
|
||||
buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y);
|
||||
buf->appendf("Collapsed=%d\n", settings->Collapsed);
|
||||
|
@ -662,15 +662,16 @@ struct IMGUI_API ImGuiInputTextState
|
||||
};
|
||||
|
||||
// Windows data saved in imgui.ini file
|
||||
// Because we never destroy or rename ImGuiWindowSettings, we can store the names in a separate buffer easily.
|
||||
struct ImGuiWindowSettings
|
||||
{
|
||||
char* Name;
|
||||
int NameOffset; // Offset into SettingsWindowNames[]
|
||||
ImGuiID ID;
|
||||
ImVec2ih Pos;
|
||||
ImVec2ih Size;
|
||||
bool Collapsed;
|
||||
|
||||
ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = false; }
|
||||
ImGuiWindowSettings() { NameOffset = -1; ID = 0; Pos = Size = ImVec2ih(0, 0); Collapsed = false; }
|
||||
};
|
||||
|
||||
struct ImGuiSettingsHandler
|
||||
@ -1039,6 +1040,7 @@ struct ImGuiContext
|
||||
ImGuiTextBuffer SettingsIniData; // In memory .ini settings
|
||||
ImVector<ImGuiSettingsHandler> SettingsHandlers; // List of .ini settings handlers
|
||||
ImVector<ImGuiWindowSettings> SettingsWindows; // ImGuiWindow .ini settings entries (parsed from the last loaded .ini file and maintained on saving)
|
||||
ImGuiTextBuffer SettingsWindowsNames; // Names for SettingsWindows
|
||||
|
||||
// Logging
|
||||
bool LogEnabled;
|
||||
|
Loading…
Reference in New Issue
Block a user