- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
// New contexts always point by default to this font atlas. It can be changed by reassigning the GetIO().Fonts variable.
staticImFontAtlasGImDefaultFontAtlas;
// Default context storage + current context pointer.
// Implicitely used by all ImGui functions. Always assumed to be != NULL. Change to a different context by calling ImGui::SetCurrentContext()
// If you are hot-reloading this code in a DLL you will lose the static/global variables. Create your own context+font atlas instead of relying on those default (see FAQ entry "How can I preserve my ImGui context across reloading a DLL?").
// ImGui is currently not thread-safe because of this variable. If you want thread-safety to allow N threads to access N different contexts, you might work around it by:
// Current context pointer. Implicitely used by all ImGui functions. Always assumed to be != NULL.
// CreateContext() will automatically set this pointer if it is NULL. Change to a different context by calling ImGui::SetCurrentContext().
// If you use DLL hotreloading you might need to call SetCurrentContext() after reloading code from this file.
// ImGui functions are not thread-safe because of this pointer. If you want thread-safety to allow N threads to access N different contexts, you can:
// - Change this variable to use thread local storage. You may #define GImGui in imconfig.h for that purpose. Future development aim to make this context pointer explicit to all calls. Also read https://github.com/ocornut/imgui/issues/586
// - Having multiple instances of the ImGui code compiled inside different namespace (easiest/safest, if you have a finite number of contexts)
// - or: Changing this variable to be TLS. You may #define GImGui in imconfig.h for further custom hackery. Future development aim to make this context pointer explicit to all calls. Also read https://github.com/ocornut/imgui/issues/586
#ifndef GImGui
staticImGuiContextGImDefaultContext;
ImGuiContext*GImGui=&GImDefaultContext;
ImGuiContext*GImGui=NULL;
#endif
// Memory Allocator functions. Use SetAllocatorFunctions() to change them.
// This function is merely here to free heap allocations.
voidImGui::Shutdown()
voidImGui::Shutdown(ImGuiContext*context)
{
ImGuiContext&g=*GImGui;
ImGuiContext&g=*context;
// The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame)
if(g.IO.Fonts)// Testing for NULL to allow user to NULLify in case of running Shutdown() on multiple contexts. Bit hacky.
g.IO.Fonts->Clear();
if(g.IO.Fonts&&g.FontAtlasOwnedByContext)
IM_DELETE(g.IO.Fonts);
// Cleanup of other data are conditional on actually having initialize ImGui.
// In a namespace so that user can add extra functions in a separate file (e.g. Value() helpers for your vector or common types)
namespaceImGui
{
// Context creation and access, if you want to use multiple context, share context between modules (e.g. DLL).
// All contexts share a same ImFontAtlas by default. If you want different font atlas, you can new() them and overwrite the GetIO().Fonts variable of an ImGui context.
// All those functions are not reliant on the current context.
IMGUI_APIvoidDestroyContext(ImGuiContext*ctx=NULL);// NULL = Destroy current context
IMGUI_APIImGuiContext*GetCurrentContext();
IMGUI_APIvoidSetCurrentContext(ImGuiContext*ctx);
// Main
IMGUI_APIImGuiIO&GetIO();
IMGUI_APIImGuiStyle&GetStyle();
@ -134,7 +142,6 @@ namespace ImGui
IMGUI_APIvoidNewFrame();// start a new ImGui frame, you can submit any command from this point until Render()/EndFrame().
IMGUI_APIvoidRender();// ends the ImGui frame, finalize the draw data, then call your io.RenderDrawListsFn() function if set.
IMGUI_APIvoidEndFrame();// ends the ImGui frame. automatically called by Render(), so most likely don't need to ever call that yourself directly. If you don't need to render you may call EndFrame() but you'll have wasted CPU already. If you don't need to render, better to not create any imgui windows instead!
IMGUI_APIvoidShutdown();
// Demo, Debug, Informations
IMGUI_APIvoidShowDemoWindow(bool*p_open=NULL);// create demo/test window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
@ -143,6 +150,7 @@ namespace ImGui
IMGUI_APIboolShowStyleSelector(constchar*label);
IMGUI_APIvoidShowFontSelector(constchar*label);
IMGUI_APIvoidShowUserGuide();// add basic help/info block (not a window): how to manipulate ImGui as a end-user (mouse/keyboard controls).
IMGUI_APIconstchar*GetVersion();
// Window
IMGUI_APIboolBegin(constchar*name,bool*p_open=NULL,ImGuiWindowFlagsflags=0);// push window to the stack and start appending to it. see .cpp for details. return false when window is collapsed (so you can early out in your code) but you always need to call End() regardless. 'bool* p_open' creates a widget on the upper-right to close the window (which sets your bool to false).
@ -510,15 +518,6 @@ namespace ImGui
IMGUI_APIconstchar*GetClipboardText();
IMGUI_APIvoidSetClipboardText(constchar*text);
// Context creation and access, if you want to use multiple context, share context between modules (e.g. DLL). There is a default context created and active by default.
// All contexts share a same ImFontAtlas by default. If you want different font atlas, you can new() them and overwrite the GetIO().Fonts variable of an ImGui context.
// All those functions are not reliant on the current context.
IMGUI_APIvoidShutdown(ImGuiContext*context);// Since 1.54 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext().