mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 09:27:00 +00:00
Viewport: DestroyPlatformWindows() checks for the bool CreatedPlatformWindow flag correctly. Note that we set CreatedPlatformWindow=true for the main viewport to allow the back-end to store data in the public Viewport structure (for consistency). (#1542)
This commit is contained in:
parent
9852649e97
commit
5d630c930d
@ -137,7 +137,7 @@ int main(int, char**)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T WORK AS EXPECTED. DON'T USE IN USER APP!
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
||||
|
21
imgui.cpp
21
imgui.cpp
@ -4599,6 +4599,7 @@ void ImGui::Initialize(ImGuiContext* context)
|
||||
ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)();
|
||||
viewport->ID = IMGUI_VIEWPORT_DEFAULT_ID;
|
||||
viewport->Idx = 0;
|
||||
viewport->CreatedPlatformWindow = true; // Set this flag so DestroyPlatformWindows() gives a chance for backend to receive DestroyWindow calls for the main viewport.
|
||||
g.Viewports.push_back(viewport);
|
||||
g.PlatformIO.MainViewport = g.Viewports[0]; // Make it accessible in public-facing GetPlatformIO() immediately (before the first call to EndFrame)
|
||||
g.PlatformIO.Viewports.push_back(g.Viewports[0]);
|
||||
@ -4608,16 +4609,20 @@ void ImGui::Initialize(ImGuiContext* context)
|
||||
|
||||
void ImGui::DestroyPlatformWindows()
|
||||
{
|
||||
// We call the destroy window on the main viewport (index 0) to give a chance to the back-end to clear any data it may hold on it.
|
||||
// We call the destroy window on the main viewport (index 0) to give a chance to the back-end to clear any data
|
||||
// have stored in e.g. PlatformHandle.
|
||||
// It is expected that the back-end stored a flag to remember that it doesn't own the window created for the main viewport,
|
||||
// and won't destroy the underlying platform/renderer data.
|
||||
// and won't destroy the underlying platform/renderer data (e.g.
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.PlatformIO.Renderer_DestroyWindow)
|
||||
for (int i = 0; i < g.Viewports.Size; i++)
|
||||
g.PlatformIO.Renderer_DestroyWindow(g.Viewports[i]);
|
||||
if (g.PlatformIO.Platform_DestroyWindow)
|
||||
for (int i = 0; i < g.Viewports.Size; i++)
|
||||
g.PlatformIO.Platform_DestroyWindow(g.Viewports[i]);
|
||||
for (int i = 0; i < g.Viewports.Size; i++)
|
||||
if (g.Viewports[i]->CreatedPlatformWindow)
|
||||
{
|
||||
if (g.PlatformIO.Renderer_DestroyWindow)
|
||||
g.PlatformIO.Renderer_DestroyWindow(g.Viewports[i]);
|
||||
if (g.PlatformIO.Platform_DestroyWindow)
|
||||
g.PlatformIO.Platform_DestroyWindow(g.Viewports[i]);
|
||||
g.Viewports[i]->CreatedPlatformWindow = false;
|
||||
}
|
||||
}
|
||||
|
||||
// This function is merely here to free heap allocations.
|
||||
|
Loading…
Reference in New Issue
Block a user