Settings: Internals: Added FindSettingsHandler()

This commit is contained in:
omar 2017-11-28 20:03:10 +01:00
parent 35eb5c5c99
commit 7ae71e4984
2 changed files with 13 additions and 6 deletions

View File

@ -2639,6 +2639,15 @@ static void LoadIniSettingsFromDisk(const char* ini_filename)
ImGui::MemFree(file_data); ImGui::MemFree(file_data);
} }
ImGuiSettingsHandler* ImGui::FindSettingsHandler(ImGuiID type_hash)
{
ImGuiContext& g = *GImGui;
for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
if (g.SettingsHandlers[handler_n].TypeHash == type_hash)
return &g.SettingsHandlers[handler_n];
return NULL;
}
// Zero-tolerance, no error reporting, cheap .ini parsing // Zero-tolerance, no error reporting, cheap .ini parsing
static void LoadIniSettingsFromMemory(const char* buf_readonly) static void LoadIniSettingsFromMemory(const char* buf_readonly)
{ {
@ -2680,10 +2689,7 @@ static void LoadIniSettingsFromMemory(const char* buf_readonly)
name_start++; // Skip second '[' name_start++; // Skip second '['
} }
const ImGuiID type_hash = ImHash(type_start, 0, 0); const ImGuiID type_hash = ImHash(type_start, 0, 0);
entry_handler = NULL; entry_handler = ImGui::FindSettingsHandler(type_hash);
for (int handler_n = 0; handler_n < g.SettingsHandlers.Size && entry_handler == NULL; handler_n++)
if (g.SettingsHandlers[handler_n].TypeHash == type_hash)
entry_handler = &g.SettingsHandlers[handler_n];
entry_data = entry_handler ? entry_handler->ReadOpenEntryFn(g, name_start) : NULL; entry_data = entry_handler ? entry_handler->ReadOpenEntryFn(g, name_start) : NULL;
} }
else if (entry_handler != NULL && entry_data != NULL) else if (entry_handler != NULL && entry_data != NULL)

View File

@ -804,6 +804,7 @@ namespace ImGui
IMGUI_API void Initialize(); IMGUI_API void Initialize();
IMGUI_API void MarkIniSettingsDirty(); IMGUI_API void MarkIniSettingsDirty();
IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(ImGuiID type_id);
IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id);
IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window);