mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 13:08:47 +02:00
Merge branch 'viewport' into docking
This commit is contained in:
45
imgui.cpp
45
imgui.cpp
@ -7136,20 +7136,31 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window)
|
||||
if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below
|
||||
{
|
||||
//IMGUI_DEBUG_LOG("ClosePopupsOverWindow(%s) -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep);
|
||||
ClosePopupToLevel(popup_count_to_keep);
|
||||
ClosePopupToLevel(popup_count_to_keep, false);
|
||||
}
|
||||
}
|
||||
|
||||
void ImGui::ClosePopupToLevel(int remaining)
|
||||
void ImGui::ClosePopupToLevel(int remaining, bool apply_focus_to_window_under)
|
||||
{
|
||||
IM_ASSERT(remaining >= 0);
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* focus_window = (remaining > 0) ? g.OpenPopupStack[remaining-1].Window : g.OpenPopupStack[0].ParentWindow;
|
||||
if (g.NavLayer == 0)
|
||||
focus_window = NavRestoreLastChildNavWindow(focus_window);
|
||||
FocusWindow(focus_window);
|
||||
focus_window->DC.NavHideHighlightOneFrame = true;
|
||||
g.OpenPopupStack.resize(remaining);
|
||||
|
||||
// FIXME: This code is faulty and we may want to eventually to replace or remove the 'apply_focus_to_window_under=true' path completely.
|
||||
// Instead of using g.OpenPopupStack[remaining-1].Window etc. we should find the highest root window that is behind the popups we are closing.
|
||||
// The current code will set focus to the parent of the popup window which is incorrect.
|
||||
// It rarely manifested until now because UpdateMouseMovingWindow() would call FocusWindow() again on the clicked window,
|
||||
// leading to a chain of focusing A (clicked window) then B (parent window of the popup) then A again.
|
||||
// However if the clicked window has the _NoMove flag set we would be left with B focused.
|
||||
// For now, we have disabled this path when called from ClosePopupsOverWindow() because the users of ClosePopupsOverWindow() don't need to alter focus anyway,
|
||||
// but we should inspect and fix this properly.
|
||||
if (apply_focus_to_window_under)
|
||||
{
|
||||
if (g.NavLayer == 0)
|
||||
focus_window = NavRestoreLastChildNavWindow(focus_window);
|
||||
FocusWindow(focus_window);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the popup we have begin-ed into.
|
||||
@ -7161,7 +7172,13 @@ void ImGui::CloseCurrentPopup()
|
||||
return;
|
||||
while (popup_idx > 0 && g.OpenPopupStack[popup_idx].Window && (g.OpenPopupStack[popup_idx].Window->Flags & ImGuiWindowFlags_ChildMenu))
|
||||
popup_idx--;
|
||||
ClosePopupToLevel(popup_idx);
|
||||
ClosePopupToLevel(popup_idx, true);
|
||||
|
||||
// A common pattern is to close a popup when selecting a menu item/selectable that will open another window.
|
||||
// To improve this usage pattern, we avoid nav highlight for a single frame in the parent window.
|
||||
// Similarly, we could avoid mouse hover highlight in this window but it is less visually problematic.
|
||||
if (ImGuiWindow* window = g.NavWindow)
|
||||
window->DC.NavHideHighlightOneFrame = true;
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags)
|
||||
@ -7222,7 +7239,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla
|
||||
{
|
||||
EndPopup();
|
||||
if (is_open)
|
||||
ClosePopupToLevel(g.BeginPopupStack.Size);
|
||||
ClosePopupToLevel(g.BeginPopupStack.Size, true);
|
||||
return false;
|
||||
}
|
||||
return is_open;
|
||||
@ -7602,8 +7619,10 @@ static void ImGui::UpdateViewports()
|
||||
|
||||
// Update DPI scale
|
||||
float new_dpi_scale;
|
||||
if (g.PlatformIO.Platform_GetWindowDpiScale)
|
||||
if (g.PlatformIO.Platform_GetWindowDpiScale && platform_funcs_available)
|
||||
new_dpi_scale = g.PlatformIO.Platform_GetWindowDpiScale(viewport);
|
||||
else if (viewport->PlatformMonitor != -1)
|
||||
new_dpi_scale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale;
|
||||
else
|
||||
new_dpi_scale = (viewport->DpiScale != 0.0f) ? viewport->DpiScale : 1.0f;
|
||||
if (viewport->DpiScale != 0.0f && new_dpi_scale != viewport->DpiScale)
|
||||
@ -7716,10 +7735,10 @@ ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const
|
||||
g.DrawListSharedData.ClipRectFullscreen.z = ImMax(g.DrawListSharedData.ClipRectFullscreen.z, viewport->Pos.x + viewport->Size.x);
|
||||
g.DrawListSharedData.ClipRectFullscreen.w = ImMax(g.DrawListSharedData.ClipRectFullscreen.w, viewport->Pos.y + viewport->Size.y);
|
||||
|
||||
// Request an initial DpiScale before the OS platform window creation
|
||||
// Store initial DpiScale before the OS platform window creation, based on expected monitor data.
|
||||
// This is so we can select an appropriate font size on the first frame of our window lifetime
|
||||
if (g.PlatformIO.Platform_GetWindowDpiScale)
|
||||
viewport->DpiScale = g.PlatformIO.Platform_GetWindowDpiScale(viewport);
|
||||
if (viewport->PlatformMonitor != -1)
|
||||
viewport->DpiScale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale;
|
||||
}
|
||||
|
||||
viewport->Window = window;
|
||||
@ -8645,7 +8664,7 @@ static void ImGui::NavUpdate()
|
||||
{
|
||||
// Close open popup/menu
|
||||
if (!(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal))
|
||||
ClosePopupToLevel(g.OpenPopupStack.Size - 1);
|
||||
ClosePopupToLevel(g.OpenPopupStack.Size - 1, true);
|
||||
}
|
||||
else if (g.NavLayer != 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user