@ -5376,7 +5376,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags)
// User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
if ( ! ( flags & ImGuiWindowFlags_NoSavedSettings ) )
if ( ImGuiWindowSettings * settings = ImGui : : FindWindowSettings ( window - > ID ) )
if ( ImGuiWindowSettings * settings = ImGui : : FindWindowSettingsByWindow ( window ) )
{
// Retrieve settings from .ini file
window - > SettingsOffset = g . SettingsWindows . offset_from_ptr ( settings ) ;
@ -12453,8 +12453,8 @@ void ImGui::LogButtons()
// - UpdateSettings() [Internal]
// - MarkIniSettingsDirty() [Internal]
// - CreateNewWindowSettings() [Internal]
// - FindWindowSettings() [Internal]
// - FindOrCreate WindowSettings() [Internal]
// - FindWindowSettingsByName () [Internal]
// - FindWindowSettingsByWindow () [Internal]
// - FindSettingsHandler() [Internal]
// - ClearIniSettings() [Internal]
// - LoadIniSettingsFromDisk()
@ -12529,20 +12529,24 @@ ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name)
return settings ;
}
ImGuiWindowSettings * ImGui : : FindWindowSettings ( ImGuiID id )
// This is called once per window .ini entry + once per newly instanciated window.
ImGuiWindowSettings * ImGui : : FindWindowSettingsByName ( const char * name )
{
ImGuiContext & g = * GImGui ;
ImGuiID id = ImHashStr ( name ) ;
for ( ImGuiWindowSettings * settings = g . SettingsWindows . begin ( ) ; settings ! = NULL ; settings = g . SettingsWindows . next_chunk ( settings ) )
if ( settings - > ID = = id )
return settings ;
return NULL ;
}
ImGuiWindowSettings * ImGui : : FindOrCreateWindowSettings ( const char * name )
// This is faster if you are holding on a Window already as we don't need to perform a search.
ImGuiWindowSettings * ImGui : : FindWindowSettingsByWindow ( ImGuiWindow * window )
{
if ( ImGuiWindowSettings * settings = FindWindowSettings ( ImHashStr ( name ) ) )
return settings ;
return CreateNewWindowSettings ( name ) ;
ImGuiContext & g = * GImGui ;
if ( window - > SettingsOffset ! = - 1 )
return g . SettingsWindows . ptr_from_offset ( window - > SettingsOffset ) ;
return FindWindowSettingsByName ( window - > Name ) ; // Actual search executed once, so at this point we don't mind the redundant hashing.
}
void ImGui : : AddSettingsHandler ( const ImGuiSettingsHandler * handler )
@ -12569,6 +12573,7 @@ ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name)
return NULL ;
}
// Clear all settings (windows, tables, docking etc.)
void ImGui : : ClearIniSettings ( )
{
ImGuiContext & g = * GImGui ;
@ -12703,9 +12708,12 @@ static void WindowSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandl
static void * WindowSettingsHandler_ReadOpen ( ImGuiContext * , ImGuiSettingsHandler * , const char * name )
{
ImGuiWindowSettings * settings = ImGui : : FindOrCreateWindowSettings ( name ) ;
ImGuiID id = settings - > ID ;
* settings = ImGuiWindowSettings ( ) ; // Clear existing if recycling previous entry
ImGuiID id = ImHashStr ( name ) ;
ImGuiWindowSettings * settings = ImGui : : FindWindowSettingsByName ( name ) ;
if ( settings )
* settings = ImGuiWindowSettings ( ) ; // Clear existing if recycling previous entry
else
settings = ImGui : : CreateNewWindowSettings ( name ) ;
settings - > ID = id ;
settings - > WantApply = true ;
return ( void * ) settings ;
@ -12745,7 +12753,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
if ( window - > Flags & ImGuiWindowFlags_NoSavedSettings )
continue ;
ImGuiWindowSettings * settings = ( window - > SettingsOffset ! = - 1 ) ? g . SettingsWindows . ptr_from_offset ( window - > SettingsOffset ) : ImGui : : FindWindowSettings ( window - > ID ) ;
ImGuiWindowSettings * settings = ImGui : : FindWindowSettingsByWindow ( window ) ;
if ( ! settings )
{
settings = ImGui : : CreateNewWindowSettings ( window - > Name ) ;