mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Misc: Optimized storage of window settings data (reducing allocation count).
This commit is contained in:
		@@ -68,6 +68,7 @@ Other Changes:
 | 
				
			|||||||
  incorrectly locating the arrow hit position to the left of the frame. (#2451, #2438, #1897)
 | 
					  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
 | 
					- 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)
 | 
					  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)
 | 
					- 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: 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.
 | 
					- 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.PrivateClipboard.clear();
 | 
				
			||||||
    g.InputTextState.ClearFreeMemory();
 | 
					    g.InputTextState.ClearFreeMemory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (int i = 0; i < g.SettingsWindows.Size; i++)
 | 
					    g.SettingsWindowsNames.clear();
 | 
				
			||||||
        IM_DELETE(g.SettingsWindows[i].Name);
 | 
					 | 
				
			||||||
    g.SettingsWindows.clear();
 | 
					    g.SettingsWindows.clear();
 | 
				
			||||||
    g.SettingsHandlers.clear();
 | 
					    g.SettingsHandlers.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -9205,8 +9204,10 @@ ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name)
 | 
				
			|||||||
    if (const char* p = strstr(name, "###"))
 | 
					    if (const char* p = strstr(name, "###"))
 | 
				
			||||||
        name = p;
 | 
					        name = p;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    settings->Name = ImStrdup(name);
 | 
					    size_t name_len = strlen(name);
 | 
				
			||||||
    settings->ID = ImHashStr(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;
 | 
					    return settings;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -9387,7 +9388,8 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
 | 
				
			|||||||
    for (int i = 0; i != g.SettingsWindows.Size; i++)
 | 
					    for (int i = 0; i != g.SettingsWindows.Size; i++)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        const ImGuiWindowSettings* settings = &g.SettingsWindows[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("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y);
 | 
				
			||||||
        buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y);
 | 
					        buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y);
 | 
				
			||||||
        buf->appendf("Collapsed=%d\n", settings->Collapsed);
 | 
					        buf->appendf("Collapsed=%d\n", settings->Collapsed);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -662,15 +662,16 @@ struct IMGUI_API ImGuiInputTextState
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Windows data saved in imgui.ini file
 | 
					// 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
 | 
					struct ImGuiWindowSettings
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    char*       Name;
 | 
					    int         NameOffset;     // Offset into SettingsWindowNames[]
 | 
				
			||||||
    ImGuiID     ID;
 | 
					    ImGuiID     ID;
 | 
				
			||||||
    ImVec2ih    Pos;
 | 
					    ImVec2ih    Pos;
 | 
				
			||||||
    ImVec2ih    Size;
 | 
					    ImVec2ih    Size;
 | 
				
			||||||
    bool        Collapsed;
 | 
					    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
 | 
					struct ImGuiSettingsHandler
 | 
				
			||||||
@@ -1039,6 +1040,7 @@ struct ImGuiContext
 | 
				
			|||||||
    ImGuiTextBuffer                SettingsIniData;             // In memory .ini settings
 | 
					    ImGuiTextBuffer                SettingsIniData;             // In memory .ini settings
 | 
				
			||||||
    ImVector<ImGuiSettingsHandler> SettingsHandlers;            // List of .ini settings handlers
 | 
					    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)
 | 
					    ImVector<ImGuiWindowSettings>  SettingsWindows;             // ImGuiWindow .ini settings entries (parsed from the last loaded .ini file and maintained on saving)
 | 
				
			||||||
 | 
					    ImGuiTextBuffer                SettingsWindowsNames;        // Names for SettingsWindows
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Logging
 | 
					    // Logging
 | 
				
			||||||
    bool                    LogEnabled;
 | 
					    bool                    LogEnabled;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user