Viewport, DPI: Don't activate current window until a viewport has been selected. At this point we'll have the proper size/scale for the current DPI + fix viewport callback when appending to an existing window more than once a frame. (#1542, #1676)

This commit is contained in:
omar 2018-03-09 15:49:12 +01:00
parent a4629b0b36
commit 648735a4cf

View File

@ -4523,6 +4523,8 @@ void ImGui::SetCurrentViewport(ImGuiViewport* viewport)
// Notify platform interface of viewport changes // Notify platform interface of viewport changes
// FIXME-DPI: This is only currently used for experimenting with handling of multiple DPI // FIXME-DPI: This is only currently used for experimenting with handling of multiple DPI
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (viewport)
viewport->LastFrameActive = g.FrameCount;
if (g.CurrentViewport == viewport) if (g.CurrentViewport == viewport)
return; return;
if (g.CurrentViewport && g.IO.PlatformInterface.EndViewport) if (g.CurrentViewport && g.IO.PlatformInterface.EndViewport)
@ -6030,10 +6032,6 @@ static void ImGui::UpdateWindowViewport(ImGuiWindow* window, bool window_pos_set
if ((window->Flags & ImGuiWindowFlags_FullViewport) && !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration)) if ((window->Flags & ImGuiWindowFlags_FullViewport) && !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration))
window->Flags |= ImGuiWindowFlags_NoTitleBar; window->Flags |= ImGuiWindowFlags_NoTitleBar;
// Disable rounding for the window
if (window->Viewport != main_viewport)
window->WindowRounding = 0.0f;
if (window->Flags & ImGuiWindowFlags_FullViewport) if (window->Flags & ImGuiWindowFlags_FullViewport)
SetWindowPos(window, window->Viewport->Pos, ImGuiCond_Always); SetWindowPos(window, window->Viewport->Pos, ImGuiCond_Always);
@ -6238,8 +6236,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow)); IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow));
// Add to stack // Add to stack
// We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow()
g.CurrentWindowStack.push_back(window); g.CurrentWindowStack.push_back(window);
SetCurrentWindow(window); g.CurrentWindow = NULL;
CheckStacksSize(window, true); CheckStacksSize(window, true);
if (flags & ImGuiWindowFlags_Popup) if (flags & ImGuiWindowFlags_Popup)
{ {
@ -6322,7 +6321,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
UpdateWindowViewport(window, window_pos_set_by_api); UpdateWindowViewport(window, window_pos_set_by_api);
SetCurrentViewport(window->Viewport); SetCurrentViewport(window->Viewport);
window->Viewport->LastFrameActive = g.FrameCount; SetCurrentWindow(window);
flags = window->Flags; flags = window->Flags;
if (p_open != NULL && window->Viewport->PlatformRequestClose && !(window->Viewport->Flags & ImGuiViewportFlags_MainViewport)) if (p_open != NULL && window->Viewport->PlatformRequestClose && !(window->Viewport->Flags & ImGuiViewportFlags_MainViewport))
@ -6333,6 +6332,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Lock window rounding, border size and padding for the frame (so that altering them doesn't cause inconsistencies) // Lock window rounding, border size and padding for the frame (so that altering them doesn't cause inconsistencies)
window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding; window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding;
if (window->Viewport != GetMainViewport())
window->WindowRounding = 0.0f;
window->WindowBorderSize = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildBorderSize : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupBorderSize : style.WindowBorderSize; window->WindowBorderSize = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildBorderSize : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupBorderSize : style.WindowBorderSize;
window->WindowPadding = style.WindowPadding; window->WindowPadding = style.WindowPadding;
if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f) if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f)
@ -6786,6 +6787,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->DC.LastItemStatusFlags = IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0; window->DC.LastItemStatusFlags = IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0;
window->DC.LastItemRect = title_bar_rect; window->DC.LastItemRect = title_bar_rect;
} }
else
{
SetCurrentViewport(window->Viewport);
SetCurrentWindow(window);
}
PushClipRect(window->InnerClipRect.Min, window->InnerClipRect.Max, true); PushClipRect(window->InnerClipRect.Min, window->InnerClipRect.Max, true);