Called by user at the end of the main loop, after EndFrame() This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO api.
| 17411 | // Called by user at the end of the main loop, after EndFrame() |
| 17412 | // This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO api. |
| 17413 | void ImGui::UpdatePlatformWindows() |
| 17414 | { |
| 17415 | ImGuiContext& g = *GImGui; |
| 17416 | IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before UpdatePlatformWindows()?"); |
| 17417 | IM_ASSERT(g.FrameCountPlatformEnded < g.FrameCount); |
| 17418 | g.FrameCountPlatformEnded = g.FrameCount; |
| 17419 | if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) |
| 17420 | return; |
| 17421 | |
| 17422 | // Create/resize/destroy platform windows to match each active viewport. |
| 17423 | // Skip the main viewport (index 0), which is always fully handled by the application! |
| 17424 | for (int i = 1; i < g.Viewports.Size; i++) |
| 17425 | { |
| 17426 | ImGuiViewportP* viewport = g.Viewports[i]; |
| 17427 | |
| 17428 | // Destroy platform window if the viewport hasn't been submitted or if it is hosting a hidden window |
| 17429 | // (the implicit/fallback Debug##Default window will be registering its viewport then be disabled, causing a dummy DestroyPlatformWindow to be made each frame) |
| 17430 | bool destroy_platform_window = false; |
| 17431 | destroy_platform_window |= (viewport->LastFrameActive < g.FrameCount - 1); |
| 17432 | destroy_platform_window |= (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)); |
| 17433 | if (destroy_platform_window) |
| 17434 | { |
| 17435 | DestroyPlatformWindow(viewport); |
| 17436 | continue; |
| 17437 | } |
| 17438 | |
| 17439 | // New windows that appears directly in a new viewport won't always have a size on their first frame |
| 17440 | if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0 || viewport->Size.y <= 0) |
| 17441 | continue; |
| 17442 | |
| 17443 | // Create window |
| 17444 | const bool is_new_platform_window = (viewport->PlatformWindowCreated == false); |
| 17445 | if (is_new_platform_window) |
| 17446 | { |
| 17447 | IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Create Platform Window %08X '%s'\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); |
| 17448 | g.PlatformIO.Platform_CreateWindow(viewport); |
| 17449 | if (g.PlatformIO.Renderer_CreateWindow != NULL) |
| 17450 | g.PlatformIO.Renderer_CreateWindow(viewport); |
| 17451 | g.PlatformWindowsCreatedCount++; |
| 17452 | viewport->LastNameHash = 0; |
| 17453 | viewport->LastPlatformPos = viewport->LastPlatformSize = ImVec2(FLT_MAX, FLT_MAX); // By clearing those we'll enforce a call to Platform_SetWindowPos/Size below, before Platform_ShowWindow (FIXME: Is that necessary?) |
| 17454 | viewport->LastRendererSize = viewport->Size; // We don't need to call Renderer_SetWindowSize() as it is expected Renderer_CreateWindow() already did it. |
| 17455 | viewport->PlatformWindowCreated = true; |
| 17456 | } |
| 17457 | |
| 17458 | // Apply Position and Size (from ImGui to Platform/Renderer backends) |
| 17459 | if ((viewport->LastPlatformPos.x != viewport->Pos.x || viewport->LastPlatformPos.y != viewport->Pos.y) && !viewport->PlatformRequestMove) |
| 17460 | g.PlatformIO.Platform_SetWindowPos(viewport, viewport->Pos); |
| 17461 | if ((viewport->LastPlatformSize.x != viewport->Size.x || viewport->LastPlatformSize.y != viewport->Size.y) && !viewport->PlatformRequestResize) |
| 17462 | g.PlatformIO.Platform_SetWindowSize(viewport, viewport->Size); |
| 17463 | if ((viewport->LastRendererSize.x != viewport->Size.x || viewport->LastRendererSize.y != viewport->Size.y) && g.PlatformIO.Renderer_SetWindowSize) |
| 17464 | g.PlatformIO.Renderer_SetWindowSize(viewport, viewport->Size); |
| 17465 | viewport->LastPlatformPos = viewport->Pos; |
| 17466 | viewport->LastPlatformSize = viewport->LastRendererSize = viewport->Size; |
| 17467 | |
| 17468 | // Update title bar (if it changed) |
| 17469 | if (ImGuiWindow* window_for_title = GetWindowForTitleDisplay(viewport->Window)) |
| 17470 | { |
nothing calls this directly
no test coverage detected