diff --git a/imgui.cpp b/imgui.cpp index 8a577564b..5285bc746 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3732,6 +3732,10 @@ static void LoadIniSettingsFromMemory(const char* buf_readonly) if (line[0] == '[' && line_end > line && line_end[-1] == ']') { + // Close last entry + if (entry_data && entry_handler && entry_handler->ReadCloseFn) + entry_handler->ReadCloseFn(&g, entry_handler, entry_data); + // Parse "[Type][Name]". Note that 'Name' can itself contains [] characters, which is acceptable with the current format and parsing code. line_end[-1] = 0; const char* name_end = line_end - 1; @@ -3757,6 +3761,11 @@ static void LoadIniSettingsFromMemory(const char* buf_readonly) entry_handler->ReadLineFn(&g, entry_handler, entry_data, line); } } + + // Close last entry + if (entry_data && entry_handler && entry_handler->ReadCloseFn) + entry_handler->ReadCloseFn(&g, entry_handler, entry_data); + ImGui::MemFree(buf); g.SettingsLoaded = true; } diff --git a/imgui_internal.h b/imgui_internal.h index ddbbf0d77..e13b55801 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -428,9 +428,10 @@ struct ImGuiSettingsHandler { const char* TypeName; // Short description stored in .ini file. Disallowed characters: '[' ']' ImGuiID TypeHash; // == ImHash(TypeName, 0, 0) - void* (*ReadOpenFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); - void (*ReadLineFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); - void (*WriteAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf); + void* (*ReadOpenFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); // Read: Called when entering into a new ini entry e.g. "[Window][Name]" + void (*ReadCloseFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry); // Read: Called when closing an existing entry, so code can validate overall data. [Optional] + void (*ReadLineFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); // Read: Called for every line of text within an ini entry + void (*WriteAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf); // Write: Output every entries into 'out_buf' void* UserData; ImGuiSettingsHandler() { memset(this, 0, sizeof(*this)); }