Skip to content

Commit

Permalink
Viewports: Minor tweaks. (#2471)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed May 8, 2019
1 parent 9bf3f91 commit 239c873
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 9 additions & 2 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ static void UpdateViewportsNewFrame();
static void UpdateViewportsEndFrame();
static void UpdateSelectWindowViewport(ImGuiWindow* window);
static bool UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* host_viewport);
static bool UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window);
static void SetCurrentViewport(ImGuiWindow* window, ImGuiViewportP* viewport);
static bool GetWindowAlwaysWantOwnViewport(ImGuiWindow* window);
static int FindPlatformMonitorForPos(const ImVec2& pos);
Expand Down Expand Up @@ -10233,6 +10234,12 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG
return true;
}

static bool ImGui::UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
return UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0]);
}

// Scale all windows (position, size). Use when e.g. changing DPI. (This is a lossy operation!)
void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale)
{
Expand Down Expand Up @@ -10584,7 +10591,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
// We cannot test window->ViewportOwned as it set lower in the function.
bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && g.ActiveId == 0);
if (try_to_merge_into_host_viewport)
UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0]);
UpdateTryMergeWindowIntoHostViewports(window);
}

// Fallback to default viewport
Expand Down Expand Up @@ -10618,7 +10625,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
window->Viewport->ID = window->ID;
window->Viewport->LastNameHash = 0;
}
else if (!UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0])) // Merge?
else if (!UpdateTryMergeWindowIntoHostViewports(window)) // Merge?
{
// New viewport
window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoFocusOnAppearing);
Expand Down
3 changes: 2 additions & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,8 @@ enum ImGuiViewportFlags_
ImGuiViewportFlags_NoInputs = 1 << 4, // Platform Window: Make mouse pass through so we can drag this window while peaking behind it.
ImGuiViewportFlags_NoRendererClear = 1 << 5, // Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely).
ImGuiViewportFlags_TopMost = 1 << 6, // Platform Window: Display on top (for tooltips only)
ImGuiViewportFlags_Minimized = 1 << 7 // Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport.
ImGuiViewportFlags_Minimized = 1 << 7, // Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport.
ImGuiViewportFlags_CanHostOtherWindows = 1 << 8 // Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window)
};

// The viewports created and managed by imgui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport.
Expand Down
5 changes: 0 additions & 5 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,6 @@ struct ImDrawDataBuilder
IMGUI_API void FlattenIntoSingleLayer();
};

enum ImGuiViewportFlagsPrivate_
{
ImGuiViewportFlags_CanHostOtherWindows = 1 << 10 // Normal viewports are associated to a single window. The main viewport can host multiple windows.
};

// ImGuiViewport Private/Internals fields (cardinal sin: we are using inheritance!)
// Note that every instance of ImGuiViewport is in fact a ImGuiViewportP.
struct ImGuiViewportP : public ImGuiViewport
Expand Down

0 comments on commit 239c873

Please sign in to comment.