Settings: Added ReadInitFn pre-load handler.
(docking branch already has it, so it'll probably conflict with same contents)
This commit is contained in:
parent
5fdfa32cce
commit
476daf9aac
43
imgui.cpp
43
imgui.cpp
@ -918,9 +918,9 @@ static ImRect GetViewportRect();
|
||||
|
||||
// Settings
|
||||
static void WindowSettingsHandler_ClearAll(ImGuiContext*, ImGuiSettingsHandler*);
|
||||
static void WindowSettingsHandler_ApplyAll(ImGuiContext*, ImGuiSettingsHandler*);
|
||||
static void* WindowSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name);
|
||||
static void WindowSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line);
|
||||
static void WindowSettingsHandler_ApplyAll(ImGuiContext*, ImGuiSettingsHandler*);
|
||||
static void WindowSettingsHandler_WriteAll(ImGuiContext*, ImGuiSettingsHandler*, ImGuiTextBuffer* buf);
|
||||
|
||||
// Platform Dependents default implementation for IO functions
|
||||
@ -3945,9 +3945,9 @@ void ImGui::Initialize(ImGuiContext* context)
|
||||
ini_handler.TypeName = "Window";
|
||||
ini_handler.TypeHash = ImHashStr("Window");
|
||||
ini_handler.ClearAllFn = WindowSettingsHandler_ClearAll;
|
||||
ini_handler.ApplyAllFn = WindowSettingsHandler_ApplyAll;
|
||||
ini_handler.ReadOpenFn = WindowSettingsHandler_ReadOpen;
|
||||
ini_handler.ReadLineFn = WindowSettingsHandler_ReadLine;
|
||||
ini_handler.ApplyAllFn = WindowSettingsHandler_ApplyAll;
|
||||
ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll;
|
||||
g.SettingsHandlers.push_back(ini_handler);
|
||||
}
|
||||
@ -9784,6 +9784,12 @@ void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
|
||||
memcpy(buf, ini_data, ini_size);
|
||||
buf_end[0] = 0;
|
||||
|
||||
// Call pre-read handlers
|
||||
// Some types will clear their data (e.g. dock information) some types will allow merge/override (window)
|
||||
for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
|
||||
if (g.SettingsHandlers[handler_n].ReadInitFn)
|
||||
g.SettingsHandlers[handler_n].ReadInitFn(&g, &g.SettingsHandlers[handler_n]);
|
||||
|
||||
void* entry_data = NULL;
|
||||
ImGuiSettingsHandler* entry_handler = NULL;
|
||||
|
||||
@ -9872,24 +9878,12 @@ static void WindowSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandl
|
||||
g.SettingsWindows.clear();
|
||||
}
|
||||
|
||||
// Apply to existing windows (if any)
|
||||
static void WindowSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
|
||||
{
|
||||
ImGuiContext& g = *ctx;
|
||||
for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings))
|
||||
if (settings->WantApply)
|
||||
{
|
||||
if (ImGuiWindow* window = ImGui::FindWindowByID(settings->ID))
|
||||
ApplyWindowSettings(window, settings);
|
||||
settings->WantApply = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void* WindowSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name)
|
||||
{
|
||||
ImGuiWindowSettings* settings = ImGui::FindWindowSettings(ImHashStr(name));
|
||||
if (!settings)
|
||||
settings = ImGui::CreateNewWindowSettings(name);
|
||||
ImGuiWindowSettings* settings = ImGui::FindOrCreateWindowSettings(name);
|
||||
ImGuiID id = settings->ID;
|
||||
*settings = ImGuiWindowSettings(); // Clear existing if recycling previous entry
|
||||
settings->ID = id;
|
||||
settings->WantApply = true;
|
||||
return (void*)settings;
|
||||
}
|
||||
@ -9904,6 +9898,19 @@ static void WindowSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*,
|
||||
else if (sscanf(line, "Collapsed=%d", &i) == 1) settings->Collapsed = (i != 0);
|
||||
}
|
||||
|
||||
// Apply to existing windows (if any)
|
||||
static void WindowSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*)
|
||||
{
|
||||
ImGuiContext& g = *ctx;
|
||||
for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings))
|
||||
if (settings->WantApply)
|
||||
{
|
||||
if (ImGuiWindow* window = ImGui::FindWindowByID(settings->ID))
|
||||
ApplyWindowSettings(window, settings);
|
||||
settings->WantApply = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf)
|
||||
{
|
||||
// Gather data from windows that were active during this session
|
||||
|
@ -1082,9 +1082,10 @@ struct ImGuiSettingsHandler
|
||||
const char* TypeName; // Short description stored in .ini file. Disallowed characters: '[' ']'
|
||||
ImGuiID TypeHash; // == ImHashStr(TypeName)
|
||||
void (*ClearAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); // Clear all settings data
|
||||
void (*ApplyAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); // Read: Called after reading (in registration order)
|
||||
void (*ReadInitFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); // Read: Called before reading (in registration order)
|
||||
void* (*ReadOpenFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); // Read: Called when entering into a new ini entry e.g. "[Window][Name]"
|
||||
void (*ReadLineFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); // Read: Called for every line of text within an ini entry
|
||||
void (*ApplyAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); // Read: Called after reading (in registration order)
|
||||
void (*WriteAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf); // Write: Output every entries into 'out_buf'
|
||||
void* UserData;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user