diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1161f8df..c1ba2635 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -76,7 +76,10 @@ Other changes: (FIXME: This need a fuller explanation!) - Added ImGuiPlatformIO structure and GetPlatformIO(). - Similarly to ImGuiIO and GetIO(), this structure is the main point of communication for backends supporting multi-viewports. + - Similarly to ImGuiIO and GetIO(), this structure is the main point of communication for backends supporting multi-viewports. + - Backend sets functions in ImGuiPlatformIO to manipulate platform windows. + - ImGuiPlatformIO::Monitors is a list of platform monitors (input from backend) + - ImGuiPlatformIO::Viewports is a list of viewports (output from dear imgui) - Added ImGuiPlatformMonitor to feed OS monitor information in the ImGuiPlatformIO::Monitors. - Added GetMainViewport(). - Added GetWindowViewport(), SetNextWindowViewport(). @@ -88,7 +91,7 @@ Other changes: - Added ImGuiConfigFlags_ViewportsEnable configuration flag and other viewport options. - Added io.ConfigViewportsNoAutoMerge, io.ConfigViewportsNoTaskBarIcon, io.ConfigViewportsNoDecoration, io.ConfigViewportsNoDefaultParent options. - Added ImGuiBackendFlags_PlatformHasViewports, ImGuiBackendFlags_RendererHasViewports, ImGuiBackendFlags_HasMouseHoveredViewport backend flags. -- Added io.MainViewport, io.Viewports, io.MouseHoveredViewport (MouseHoveredViewport is optional _even_ for multi-viewport support). +- Added io.MouseHoveredViewport (optional _even_ for multi-viewport support, tied to ImGuiBackendFlags_HasMouseHoveredViewport flag). - Added ImGuiViewport structure, ImGuiViewportFlags flags. - Added ImGuiWindowClass and SetNextWindowClass() for passing viewport related hints to the OS/platform back-end. - Examples: Renderer: OpenGL2, OpenGL3, DirectX11, DirectX12, Vulkan: Added support for multi-viewports. diff --git a/imgui.cpp b/imgui.cpp index 164aec7a..6f3e9494 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4220,7 +4220,6 @@ void ImGui::Initialize(ImGuiContext* context) viewport->Idx = 0; viewport->PlatformWindowCreated = true; 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]); // Extensions @@ -6413,7 +6412,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (window->Viewport->PlatformMonitor == -1) { // Fallback for "lost" window (e.g. a monitor disconnected): we move the window back over the main viewport - SetWindowPos(window, g.Viewports[0]->Pos + style.DisplayWindowPadding, ImGuiCond_Always); + ImGuiViewport* main_viewport = GetMainViewport(); + SetWindowPos(window, main_viewport->Pos + style.DisplayWindowPadding, ImGuiCond_Always); } else { @@ -11260,13 +11260,14 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG return true; } +// FIXME: handle 0 to N host viewports static bool ImGui::UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window) { ImGuiContext& g = *GImGui; return UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0]); } -// Translate imgui windows when a Host Viewport has been moved +// Translate Dear ImGui windows when a Host Viewport has been moved // (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!) void ImGui::TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos) { @@ -11502,7 +11503,6 @@ static void ImGui::UpdateViewportsNewFrame() static void ImGui::UpdateViewportsEndFrame() { ImGuiContext& g = *GImGui; - g.PlatformIO.MainViewport = g.Viewports[0]; g.PlatformIO.Viewports.resize(0); for (int i = 0; i < g.Viewports.Size; i++) { @@ -11589,7 +11589,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window) window->ViewportAllowPlatformMonitorExtend = -1; // Restore main viewport if multi-viewport is not supported by the backend - ImGuiViewportP* main_viewport = g.Viewports[0]; + ImGuiViewportP* main_viewport = (ImGuiViewportP*)GetMainViewport(); if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) { SetWindowViewport(window, main_viewport); diff --git a/imgui.h b/imgui.h index 15520261..79d593cf 100644 --- a/imgui.h +++ b/imgui.h @@ -894,7 +894,7 @@ namespace ImGui // Read comments around the ImGuiPlatformIO structure for more details. // Note: You may use GetWindowViewport() to get the current viewport of the current window. IMGUI_API ImGuiPlatformIO& GetPlatformIO(); // platform/renderer functions, for backend to setup + viewports list. - IMGUI_API ImGuiViewport* GetMainViewport(); // main viewport. same as GetPlatformIO().MainViewport == GetPlatformIO().Viewports[0]. + IMGUI_API ImGuiViewport* GetMainViewport(); // return primary/default viewport. In the future in "no main platform window" mode we will direct this to primary monitor. IMGUI_API void UpdatePlatformWindows(); // call in main loop. will call CreateWindow/ResizeWindow/etc. platform functions for each secondary viewport, and DestroyWindow for each inactive viewport. IMGUI_API void RenderPlatformWindowsDefault(void* platform_render_arg = NULL, void* renderer_render_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs. IMGUI_API void DestroyPlatformWindows(); // call DestroyWindow platform functions for all viewports. call from backend Shutdown() if you need to close platform windows before imgui shutdown. otherwise will be called by DestroyContext(). @@ -2930,7 +2930,6 @@ struct ImGuiPlatformIO // Viewports list (the list is updated by calling ImGui::EndFrame or ImGui::Render) // (in the future we will attempt to organize this feature to remove the need for a "main viewport") - ImGuiViewport* MainViewport; // Guaranteed to be == Viewports[0] ImVector Viewports; // Main viewports, followed by all secondary viewports. ImGuiPlatformIO() { memset(this, 0, sizeof(*this)); } // Zero clear }; @@ -2973,8 +2972,8 @@ struct ImGuiViewport ImVec2 WorkOffsetMin; // Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height). Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!) ImVec2 WorkOffsetMax; // Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height). float DpiScale; // 1.0f = 96 DPI = No extra scale. - ImDrawData* DrawData; // The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). ImGuiID ParentViewportId; // (Advanced) 0: no parent. Instruct the platform backend to setup a parent/child relationship between platform windows. + ImDrawData* DrawData; // The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). // Our design separate the Renderer and Platform backends to facilitate combining default backends with each others. // When our create your own backend for a custom engine, it is possible that both Renderer and Platform will be handled @@ -2988,7 +2987,7 @@ struct ImGuiViewport bool PlatformRequestResize; // Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size) bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4) - ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; ParentViewportId = 0; RendererUserData = PlatformUserData = PlatformHandle = PlatformHandleRaw = NULL; PlatformRequestMove = PlatformRequestResize = PlatformRequestClose = false; } + ImGuiViewport() { memset(this, 0, sizeof(*this)); } ~ImGuiViewport() { IM_ASSERT(PlatformUserData == NULL && RendererUserData == NULL); } // Access work-area rectangle with GetWorkXXX functions (see comments above) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 2f33118c..d0539412 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6575,7 +6575,7 @@ void ImGui::EndMenuBar() bool ImGui::BeginMainMenuBar() { ImGuiContext& g = *GImGui; - ImGuiViewportP* viewport = g.Viewports[0]; + ImGuiViewportP* viewport = (ImGuiViewportP*)GetMainViewport(); ImGuiWindow* menu_bar_window = FindWindowByName("##MainMenuBar"); // For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set.