mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-19 06:26:35 +00:00
Viewports: (breaking) removed ImGuiPlatformIO::MainViewport which is now pretty much unused and duplicate (and misleading as we will evolve the concept)
Use GetMainViewport() if stuck.
This commit is contained in:
parent
22d9a61b33
commit
fa55b0cb60
@ -76,7 +76,10 @@ Other changes:
|
|||||||
(FIXME: This need a fuller explanation!)
|
(FIXME: This need a fuller explanation!)
|
||||||
|
|
||||||
- Added ImGuiPlatformIO structure and GetPlatformIO().
|
- 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 ImGuiPlatformMonitor to feed OS monitor information in the ImGuiPlatformIO::Monitors.
|
||||||
- Added GetMainViewport().
|
- Added GetMainViewport().
|
||||||
- Added GetWindowViewport(), SetNextWindowViewport().
|
- Added GetWindowViewport(), SetNextWindowViewport().
|
||||||
@ -88,7 +91,7 @@ Other changes:
|
|||||||
- Added ImGuiConfigFlags_ViewportsEnable configuration flag and other viewport options.
|
- Added ImGuiConfigFlags_ViewportsEnable configuration flag and other viewport options.
|
||||||
- Added io.ConfigViewportsNoAutoMerge, io.ConfigViewportsNoTaskBarIcon, io.ConfigViewportsNoDecoration, io.ConfigViewportsNoDefaultParent options.
|
- Added io.ConfigViewportsNoAutoMerge, io.ConfigViewportsNoTaskBarIcon, io.ConfigViewportsNoDecoration, io.ConfigViewportsNoDefaultParent options.
|
||||||
- Added ImGuiBackendFlags_PlatformHasViewports, ImGuiBackendFlags_RendererHasViewports, ImGuiBackendFlags_HasMouseHoveredViewport backend flags.
|
- 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 ImGuiViewport structure, ImGuiViewportFlags flags.
|
||||||
- Added ImGuiWindowClass and SetNextWindowClass() for passing viewport related hints to the OS/platform back-end.
|
- 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.
|
- Examples: Renderer: OpenGL2, OpenGL3, DirectX11, DirectX12, Vulkan: Added support for multi-viewports.
|
||||||
|
10
imgui.cpp
10
imgui.cpp
@ -4220,7 +4220,6 @@ void ImGui::Initialize(ImGuiContext* context)
|
|||||||
viewport->Idx = 0;
|
viewport->Idx = 0;
|
||||||
viewport->PlatformWindowCreated = true;
|
viewport->PlatformWindowCreated = true;
|
||||||
g.Viewports.push_back(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]);
|
g.PlatformIO.Viewports.push_back(g.Viewports[0]);
|
||||||
|
|
||||||
// Extensions
|
// Extensions
|
||||||
@ -6413,7 +6412,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
if (window->Viewport->PlatformMonitor == -1)
|
if (window->Viewport->PlatformMonitor == -1)
|
||||||
{
|
{
|
||||||
// Fallback for "lost" window (e.g. a monitor disconnected): we move the window back over the main viewport
|
// 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
|
else
|
||||||
{
|
{
|
||||||
@ -11260,13 +11260,14 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: handle 0 to N host viewports
|
||||||
static bool ImGui::UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window)
|
static bool ImGui::UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
return UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0]);
|
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!)
|
// (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)
|
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()
|
static void ImGui::UpdateViewportsEndFrame()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
g.PlatformIO.MainViewport = g.Viewports[0];
|
|
||||||
g.PlatformIO.Viewports.resize(0);
|
g.PlatformIO.Viewports.resize(0);
|
||||||
for (int i = 0; i < g.Viewports.Size; i++)
|
for (int i = 0; i < g.Viewports.Size; i++)
|
||||||
{
|
{
|
||||||
@ -11589,7 +11589,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
|
|||||||
window->ViewportAllowPlatformMonitorExtend = -1;
|
window->ViewportAllowPlatformMonitorExtend = -1;
|
||||||
|
|
||||||
// Restore main viewport if multi-viewport is not supported by the backend
|
// 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))
|
if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable))
|
||||||
{
|
{
|
||||||
SetWindowViewport(window, main_viewport);
|
SetWindowViewport(window, main_viewport);
|
||||||
|
7
imgui.h
7
imgui.h
@ -894,7 +894,7 @@ namespace ImGui
|
|||||||
// Read comments around the ImGuiPlatformIO structure for more details.
|
// Read comments around the ImGuiPlatformIO structure for more details.
|
||||||
// Note: You may use GetWindowViewport() to get the current viewport of the current window.
|
// 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 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 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 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().
|
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)
|
// 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")
|
// (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<ImGuiViewport*> Viewports; // Main viewports, followed by all secondary viewports.
|
ImVector<ImGuiViewport*> Viewports; // Main viewports, followed by all secondary viewports.
|
||||||
ImGuiPlatformIO() { memset(this, 0, sizeof(*this)); } // Zero clear
|
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 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).
|
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.
|
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.
|
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.
|
// 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
|
// 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 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)
|
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); }
|
~ImGuiViewport() { IM_ASSERT(PlatformUserData == NULL && RendererUserData == NULL); }
|
||||||
|
|
||||||
// Access work-area rectangle with GetWorkXXX functions (see comments above)
|
// Access work-area rectangle with GetWorkXXX functions (see comments above)
|
||||||
|
@ -6575,7 +6575,7 @@ void ImGui::EndMenuBar()
|
|||||||
bool ImGui::BeginMainMenuBar()
|
bool ImGui::BeginMainMenuBar()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiViewportP* viewport = g.Viewports[0];
|
ImGuiViewportP* viewport = (ImGuiViewportP*)GetMainViewport();
|
||||||
ImGuiWindow* menu_bar_window = FindWindowByName("##MainMenuBar");
|
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.
|
// For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set.
|
||||||
|
Loading…
Reference in New Issue
Block a user