mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Initialization happens during CreateContext(), which makes it easier for platform layers to interact with the context during their initialization.
This commit is contained in:
parent
1399c9c8a9
commit
b33f0e215f
17
imgui.cpp
17
imgui.cpp
@ -2636,6 +2636,7 @@ ImGuiContext* ImGui::CreateContext(ImFontAtlas* shared_font_atlas)
|
|||||||
ImGuiContext* ctx = IM_NEW(ImGuiContext)(shared_font_atlas);
|
ImGuiContext* ctx = IM_NEW(ImGuiContext)(shared_font_atlas);
|
||||||
if (GImGui == NULL)
|
if (GImGui == NULL)
|
||||||
SetCurrentContext(ctx);
|
SetCurrentContext(ctx);
|
||||||
|
Initialize(ctx);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3280,6 +3281,7 @@ void ImGui::NewFrame()
|
|||||||
|
|
||||||
// Check user data
|
// Check user data
|
||||||
// (We pass an error message in the assert expression as a trick to get it visible to programmers who are not using a debugger, as most assert handlers display their argument)
|
// (We pass an error message in the assert expression as a trick to get it visible to programmers who are not using a debugger, as most assert handlers display their argument)
|
||||||
|
IM_ASSERT(g.Initialized);
|
||||||
IM_ASSERT(g.IO.DeltaTime >= 0.0f && "Need a positive DeltaTime (zero is tolerated but will cause some timing issues)");
|
IM_ASSERT(g.IO.DeltaTime >= 0.0f && "Need a positive DeltaTime (zero is tolerated but will cause some timing issues)");
|
||||||
IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value");
|
IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value");
|
||||||
IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");
|
IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");
|
||||||
@ -3294,9 +3296,13 @@ void ImGui::NewFrame()
|
|||||||
if (g.IO.NavFlags & ImGuiNavFlags_EnableKeyboard)
|
if (g.IO.NavFlags & ImGuiNavFlags_EnableKeyboard)
|
||||||
IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation.");
|
IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation.");
|
||||||
|
|
||||||
// Initialize on first frame
|
// Load settings on first frame
|
||||||
if (!g.Initialized)
|
if (!g.SettingsLoaded)
|
||||||
Initialize(&g);
|
{
|
||||||
|
IM_ASSERT(g.SettingsWindows.empty());
|
||||||
|
LoadIniSettingsFromDisk(g.IO.IniFilename);
|
||||||
|
g.SettingsLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
g.Time += g.IO.DeltaTime;
|
g.Time += g.IO.DeltaTime;
|
||||||
g.FrameCount += 1;
|
g.FrameCount += 1;
|
||||||
@ -3602,6 +3608,7 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* imgui_ctx, ImGuiSetting
|
|||||||
void ImGui::Initialize(ImGuiContext* context)
|
void ImGui::Initialize(ImGuiContext* context)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *context;
|
ImGuiContext& g = *context;
|
||||||
|
IM_ASSERT(!g.Initialized && !g.SettingsLoaded);
|
||||||
g.LogClipboard = IM_NEW(ImGuiTextBuffer)();
|
g.LogClipboard = IM_NEW(ImGuiTextBuffer)();
|
||||||
|
|
||||||
// Add .ini handle for ImGuiWindow type
|
// Add .ini handle for ImGuiWindow type
|
||||||
@ -3613,9 +3620,6 @@ void ImGui::Initialize(ImGuiContext* context)
|
|||||||
ini_handler.WriteAllFn = SettingsHandlerWindow_WriteAll;
|
ini_handler.WriteAllFn = SettingsHandlerWindow_WriteAll;
|
||||||
g.SettingsHandlers.push_front(ini_handler);
|
g.SettingsHandlers.push_front(ini_handler);
|
||||||
|
|
||||||
// Load .ini file
|
|
||||||
IM_ASSERT(g.SettingsWindows.empty());
|
|
||||||
LoadIniSettingsFromDisk(g.IO.IniFilename);
|
|
||||||
g.Initialized = true;
|
g.Initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3765,6 +3769,7 @@ static void LoadIniSettingsFromMemory(const char* buf_readonly)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::MemFree(buf);
|
ImGui::MemFree(buf);
|
||||||
|
g.SettingsLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SaveIniSettingsToDisk(const char* ini_filename)
|
static void SaveIniSettingsToDisk(const char* ini_filename)
|
||||||
|
@ -687,6 +687,7 @@ struct ImGuiContext
|
|||||||
ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor
|
ImVec2 OsImePosRequest, OsImePosSet; // Cursor position request & last passed to the OS Input Method Editor
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
|
bool SettingsLoaded;
|
||||||
float SettingsDirtyTimer; // Save .ini Settings on disk when time reaches zero
|
float SettingsDirtyTimer; // Save .ini Settings on disk when time reaches zero
|
||||||
ImVector<ImGuiWindowSettings> SettingsWindows; // .ini settings for ImGuiWindow
|
ImVector<ImGuiWindowSettings> SettingsWindows; // .ini settings for ImGuiWindow
|
||||||
ImVector<ImGuiSettingsHandler> SettingsHandlers; // List of .ini settings handlers
|
ImVector<ImGuiSettingsHandler> SettingsHandlers; // List of .ini settings handlers
|
||||||
@ -789,6 +790,7 @@ struct ImGuiContext
|
|||||||
TooltipOverrideCount = 0;
|
TooltipOverrideCount = 0;
|
||||||
OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f);
|
OsImePosRequest = OsImePosSet = ImVec2(-1.0f, -1.0f);
|
||||||
|
|
||||||
|
SettingsLoaded = false;
|
||||||
SettingsDirtyTimer = 0.0f;
|
SettingsDirtyTimer = 0.0f;
|
||||||
|
|
||||||
LogEnabled = false;
|
LogEnabled = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user