Viewport: BeginMainMenuBar(): explicitly set viewport to avoid creating new one when ImGuiConfigFlags_ViewportsNoMerge is set + misc shallow changes.

This commit is contained in:
omar 2018-11-13 22:00:12 +01:00
parent a3d6554e8e
commit f2d577c33f
2 changed files with 7 additions and 8 deletions

View File

@ -3001,6 +3001,7 @@ void ImGui::UpdateMouseMovingWindow()
{ {
// Try to merge the window back into the main viewport. // Try to merge the window back into the main viewport.
// This works because MouseViewport should be != MovingWindow->Viewport on release (as per code in UpdateViewports) // This works because MouseViewport should be != MovingWindow->Viewport on release (as per code in UpdateViewports)
if (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
UpdateTryMergeWindowIntoHostViewport(moving_window, g.MouseViewport); UpdateTryMergeWindowIntoHostViewport(moving_window, g.MouseViewport);
// Restore the mouse viewport so that we don't hover the viewport _under_ the moved window during the frame we released the mouse button. // Restore the mouse viewport so that we don't hover the viewport _under_ the moved window during the frame we released the mouse button.
@ -5073,7 +5074,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->Pos = FindBestWindowPosForPopup(window); window->Pos = FindBestWindowPosForPopup(window);
if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned) if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned)
{
if (!window->Viewport->GetRect().Contains(window->Rect())) if (!window->Viewport->GetRect().Contains(window->Rect()))
{ {
// Late create viewport, based on the assumption that with our calculations, the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport) // Late create viewport, based on the assumption that with our calculations, the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport)
@ -5089,7 +5089,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->FontDpiScale = (g.IO.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleFonts) ? window->Viewport->DpiScale : 1.0f; window->FontDpiScale = (g.IO.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleFonts) ? window->Viewport->DpiScale : 1.0f;
SetCurrentWindow(window); SetCurrentWindow(window);
} }
}
// Synchronize viewport --> window in case the platform window has been moved or resized from the OS/WM // Synchronize viewport --> window in case the platform window has been moved or resized from the OS/WM
if (window->ViewportOwned) if (window->ViewportOwned)
@ -7197,8 +7196,6 @@ static bool ImGui::GetWindowAlwaysWantOwnViewport(ImGuiWindow* window)
static void ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* viewport) static void ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (!(g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable))
return;
if (!(viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) || window->Viewport == viewport) if (!(viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) || window->Viewport == viewport)
return; return;
if (!viewport->GetRect().Contains(window->Rect())) if (!viewport->GetRect().Contains(window->Rect()))
@ -7510,10 +7507,10 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
// Mark window as allowed to protrude outside of its viewport and into the current monitor // Mark window as allowed to protrude outside of its viewport and into the current monitor
// We need to take account of the possibility that mouse may become invalid. // We need to take account of the possibility that mouse may become invalid.
const bool use_mouse_ref = (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow);
if (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) if (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup))
{ {
ImVec2 mouse_ref = (flags & ImGuiWindowFlags_Tooltip) ? g.IO.MousePos : g.CurrentPopupStack.back().OpenMousePos; ImVec2 mouse_ref = (flags & ImGuiWindowFlags_Tooltip) ? g.IO.MousePos : g.CurrentPopupStack.back().OpenMousePos;
bool use_mouse_ref = (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow);
bool mouse_valid = IsMousePosValid(&mouse_ref); bool mouse_valid = IsMousePosValid(&mouse_ref);
if ((window->Appearing || (flags & ImGuiWindowFlags_Tooltip)) && (!use_mouse_ref || mouse_valid)) if ((window->Appearing || (flags & ImGuiWindowFlags_Tooltip)) && (!use_mouse_ref || mouse_valid))
window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos()); window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos());

View File

@ -5439,9 +5439,11 @@ float ImGuiMenuColumns::CalcExtraSpace(float avail_w)
bool ImGui::BeginMainMenuBar() bool ImGui::BeginMainMenuBar()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiViewport* viewport = g.Viewports[0];
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f)); g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f));
SetNextWindowPos(g.Viewports[0]->Pos); SetNextWindowPos(viewport->Pos);
SetNextWindowSize(ImVec2(g.Viewports[0]->Size.x, g.NextWindowData.MenuBarOffsetMinVal.y + g.FontBaseSize + g.Style.FramePadding.y)); SetNextWindowSize(ImVec2(viewport->Size.x, g.NextWindowData.MenuBarOffsetMinVal.y + g.FontBaseSize + g.Style.FramePadding.y));
SetNextWindowViewport(viewport->ID); // Enforce viewport so we don't create our onw viewport when ImGuiConfigFlags_ViewportsNoMerge is set.
PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0,0)); PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0,0));
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar; ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar;