@@ -2525,7 +2525,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
2525
2525
LastTimeActive = -1 .0f ;
2526
2526
ItemWidthDefault = 0 .0f ;
2527
2527
FontWindowScale = 1 .0f ;
2528
- SettingsIdx = -1 ;
2528
+ SettingsOffset = -1 ;
2529
2529
2530
2530
DrawList = &DrawListInst;
2531
2531
DrawList->_OwnerName = Name;
@@ -3818,7 +3818,6 @@ void ImGui::Shutdown(ImGuiContext* context)
3818
3818
g.PrivateClipboard .clear ();
3819
3819
g.InputTextState .ClearFreeMemory ();
3820
3820
3821
- g.SettingsWindowsNames .clear ();
3822
3821
g.SettingsWindows .clear ();
3823
3822
g.SettingsHandlers .clear ();
3824
3823
@@ -4704,7 +4703,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
4704
4703
if (ImGuiWindowSettings* settings = ImGui::FindWindowSettings (window->ID ))
4705
4704
{
4706
4705
// Retrieve settings from .ini file
4707
- window->SettingsIdx = g.SettingsWindows .index_from_ptr (settings);
4706
+ window->SettingsOffset = g.SettingsWindows .offset_from_ptr (settings);
4708
4707
SetWindowConditionAllowFlags (window, ImGuiCond_FirstUseEver, false );
4709
4708
window->Pos = ImVec2 (settings->Pos .x , settings->Pos .y );
4710
4709
window->Collapsed = settings->Collapsed ;
@@ -9205,27 +9204,31 @@ void ImGui::MarkIniSettingsDirty(ImGuiWindow* window)
9205
9204
ImGuiWindowSettings* ImGui::CreateNewWindowSettings (const char * name)
9206
9205
{
9207
9206
ImGuiContext& g = *GImGui;
9208
- g.SettingsWindows .push_back (ImGuiWindowSettings ());
9209
- ImGuiWindowSettings* settings = &g.SettingsWindows .back ();
9207
+
9210
9208
#if !IMGUI_DEBUG_INI_SETTINGS
9211
9209
// Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
9212
9210
// Preserve the full string when IMGUI_DEBUG_INI_SETTINGS is set to make .ini inspection easier.
9213
9211
if (const char * p = strstr (name, " ###" ))
9214
9212
name = p;
9215
9213
#endif
9216
- size_t name_len = strlen (name);
9217
- settings->NameOffset = g.SettingsWindowsNames .size ();
9218
- g.SettingsWindowsNames .append (name, name + name_len + 1 ); // Append with zero terminator
9214
+ const size_t name_len = strlen (name);
9215
+
9216
+ // Allocate chunk
9217
+ const size_t chunk_size = sizeof (ImGuiWindowSettings) + name_len + 1 ;
9218
+ ImGuiWindowSettings* settings = g.SettingsWindows .alloc_chunk (chunk_size);
9219
+ IM_PLACEMENT_NEW (settings) ImGuiWindowSettings ();
9219
9220
settings->ID = ImHashStr (name, name_len);
9221
+ memcpy (settings->GetName (), name, name_len + 1 ); // Store with zero terminator
9222
+
9220
9223
return settings;
9221
9224
}
9222
9225
9223
9226
ImGuiWindowSettings* ImGui::FindWindowSettings (ImGuiID id)
9224
9227
{
9225
9228
ImGuiContext& g = *GImGui;
9226
- for (int i = 0 ; i != g.SettingsWindows .Size ; i++ )
9227
- if (g. SettingsWindows [i]. ID == id)
9228
- return &g. SettingsWindows [i] ;
9229
+ for (ImGuiWindowSettings* settings = g. SettingsWindows . begin (); settings != NULL ; settings = g.SettingsWindows .next_chunk (settings) )
9230
+ if (settings-> ID == id)
9231
+ return settings ;
9229
9232
return NULL ;
9230
9233
}
9231
9234
@@ -9380,11 +9383,11 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
9380
9383
if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
9381
9384
continue ;
9382
9385
9383
- ImGuiWindowSettings* settings = (window->SettingsIdx != -1 ) ? & g.SettingsWindows [ window->SettingsIdx ] : ImGui::FindWindowSettings (window->ID );
9386
+ ImGuiWindowSettings* settings = (window->SettingsOffset != -1 ) ? g.SettingsWindows . ptr_from_offset ( window->SettingsOffset ) : ImGui::FindWindowSettings (window->ID );
9384
9387
if (!settings)
9385
9388
{
9386
9389
settings = ImGui::CreateNewWindowSettings (window->Name );
9387
- window->SettingsIdx = g.SettingsWindows .index_from_ptr (settings);
9390
+ window->SettingsOffset = g.SettingsWindows .offset_from_ptr (settings);
9388
9391
}
9389
9392
IM_ASSERT (settings->ID == window->ID );
9390
9393
settings->Pos = ImVec2ih ((short )window->Pos .x , (short )window->Pos .y );
@@ -9393,11 +9396,10 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
9393
9396
}
9394
9397
9395
9398
// Write to text buffer
9396
- buf->reserve (buf->size () + g.SettingsWindows .Size * 96 ); // ballpark reserve
9397
- for (int i = 0 ; i != g.SettingsWindows .Size ; i++ )
9399
+ buf->reserve (buf->size () + g.SettingsWindows .size () * 6 ); // ballpark reserve
9400
+ for (ImGuiWindowSettings* settings = g. SettingsWindows . begin (); settings != NULL ; settings = g.SettingsWindows .next_chunk (settings) )
9398
9401
{
9399
- const ImGuiWindowSettings* settings = &g.SettingsWindows [i];
9400
- const char * settings_name = g.SettingsWindowsNames .c_str () + settings->NameOffset ;
9402
+ const char * settings_name = settings->GetName ();
9401
9403
buf->appendf (" [%s][%s]\n " , handler->TypeName , settings_name);
9402
9404
buf->appendf (" Pos=%d,%d\n " , settings->Pos .x , settings->Pos .y );
9403
9405
buf->appendf (" Size=%d,%d\n " , settings->Size .x , settings->Size .y );
0 commit comments