Viewports: Fix popup/tooltip created without a parent window from being given a ParentViewportId value of the implicit/fallback window. (#4236, #2409)

Amend 3ead9820
This commit is contained in:
ocornut 2021-06-17 16:22:14 +02:00
parent afabb2f3d8
commit cce307a2be
2 changed files with 12 additions and 7 deletions

View File

@ -126,6 +126,8 @@ Docking+Viewports Branch:
- Docking: Clicking on the right-most close button of a docking node closes all windows. (#4186)
- Docking: Fix IsWindowAppearing() and ImGuiCond_Appearing on docked windows. (#4177, #3982, #1497, #1061)
- Viewports: Fix popup/tooltip created without a parent window from being given a ParentViewportId value
from the implicit/fallback window. (#4236, #2409)
- Backends: Vulkan: Fix the use of the incorrect fence for secondary viewports. (#4208) [@FunMiles]

View File

@ -11807,7 +11807,7 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window)
if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasViewport) == 0)
{
// By default inherit from parent window
if (window->Viewport == NULL && window->ParentWindow && !window->ParentWindow->IsFallbackWindow)
if (window->Viewport == NULL && window->ParentWindow && (!window->ParentWindow->IsFallbackWindow || window->ParentWindow->WasActive))
window->Viewport = window->ParentWindow->Viewport;
// Attempt to restore saved viewport id (= window that hasn't been activated yet), try to restore the viewport based on saved 'window->ViewportPos' restored from .ini file
@ -11972,12 +11972,6 @@ void ImGui::WindowSyncOwnedViewport(ImGuiWindow* window, ImGuiWindow* parent_win
viewport_flags |= ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoFocusOnClick;
// We can overwrite viewport flags using ImGuiWindowClass (advanced users)
if (window->WindowClass.ParentViewportId)
window->Viewport->ParentViewportId = window->WindowClass.ParentViewportId;
else if ((window_flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && parent_window_in_stack)
window->Viewport->ParentViewportId = parent_window_in_stack->Viewport->ID;
else
window->Viewport->ParentViewportId = g.IO.ConfigViewportsNoDefaultParent ? 0 : IMGUI_VIEWPORT_DEFAULT_ID;
if (window->WindowClass.ViewportFlagsOverrideSet)
viewport_flags |= window->WindowClass.ViewportFlagsOverrideSet;
if (window->WindowClass.ViewportFlagsOverrideClear)
@ -11990,6 +11984,15 @@ void ImGui::WindowSyncOwnedViewport(ImGuiWindow* window, ImGuiWindow* parent_win
viewport_flags |= ImGuiViewportFlags_NoRendererClear;
window->Viewport->Flags = viewport_flags;
// Update parent viewport ID
// (the !IsFallbackWindow test mimic the one done in WindowSelectViewport())
if (window->WindowClass.ParentViewportId)
window->Viewport->ParentViewportId = window->WindowClass.ParentViewportId;
else if ((window_flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && parent_window_in_stack && (!parent_window_in_stack->IsFallbackWindow || parent_window_in_stack->WasActive))
window->Viewport->ParentViewportId = parent_window_in_stack->Viewport->ID;
else
window->Viewport->ParentViewportId = g.IO.ConfigViewportsNoDefaultParent ? 0 : IMGUI_VIEWPORT_DEFAULT_ID;
}
// Called by user at the end of the main loop, after EndFrame()