mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-03 05:29:10 +08:00
Viewports: Fix issue inferring viewport z-order when new popups gets created. (#3734) + Metrics updates.
Revert 6bc52667
Showing inferred order and missing flags in metrics.
This commit is contained in:
parent
2a5eaf239f
commit
3607c42bec
47
imgui.cpp
47
imgui.cpp
@ -11839,7 +11839,7 @@ void ImGui::UpdatePlatformWindows()
|
||||
// This is useful for our platform z-order heuristic when io.MouseHoveredViewport is not available.
|
||||
if (viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount)
|
||||
viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear request flags
|
||||
viewport->ClearRequestFlags();
|
||||
@ -11860,8 +11860,14 @@ void ImGui::UpdatePlatformWindows()
|
||||
}
|
||||
|
||||
// Store a tag so we can infer z-order easily from all our windows
|
||||
if (focused_viewport && focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount)
|
||||
focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount;
|
||||
// We compare PlatformLastFocusedViewportId so newly created viewports with _NoFocusOnAppearing flag
|
||||
// will keep the front most stamp instead of losing it back to their parent viewport.
|
||||
if (focused_viewport && g.PlatformLastFocusedViewportId != focused_viewport->ID)
|
||||
{
|
||||
if (focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount)
|
||||
focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount;
|
||||
g.PlatformLastFocusedViewportId = focused_viewport->ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15852,6 +15858,13 @@ static void RenderViewportsThumbnails()
|
||||
ImGui::Dummy(bb_full.GetSize() * SCALE);
|
||||
}
|
||||
|
||||
static int IMGUI_CDECL ViewportComparerByFrontMostStampCount(const void* lhs, const void* rhs)
|
||||
{
|
||||
const ImGuiViewportP* a = *(const ImGuiViewportP* const *)lhs;
|
||||
const ImGuiViewportP* b = *(const ImGuiViewportP* const *)rhs;
|
||||
return b->LastFrontMostStampCount - a->LastFrontMostStampCount;
|
||||
}
|
||||
|
||||
// Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds.
|
||||
static void MetricsHelpMarker(const char* desc)
|
||||
{
|
||||
@ -16059,6 +16072,18 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
TreePop();
|
||||
}
|
||||
|
||||
if (TreeNode("Inferred order (front-to-back)"))
|
||||
{
|
||||
static ImVector<ImGuiViewportP*> viewports;
|
||||
viewports.resize(g.Viewports.Size);
|
||||
memcpy(viewports.Data, g.Viewports.Data, g.Viewports.size_in_bytes());
|
||||
if (viewports.Size > 1)
|
||||
ImQsort(viewports.Data, viewports.Size, sizeof(ImGuiViewport*), ViewportComparerByFrontMostStampCount);
|
||||
for (int i = 0; i < viewports.Size; i++)
|
||||
BulletText("Viewport #%d, ID: 0x%08X, FrontMostStampCount = %08d, Window: \"%s\"", viewports[i]->Idx, viewports[i]->ID, viewports[i]->LastFrontMostStampCount, viewports[i]->Window ? viewports[i]->Window->Name : "N/A");
|
||||
TreePop();
|
||||
}
|
||||
|
||||
for (int i = 0; i < g.Viewports.Size; i++)
|
||||
DebugNodeViewport(g.Viewports[i]);
|
||||
TreePop();
|
||||
@ -16557,11 +16582,17 @@ void ImGui::DebugNodeViewport(ImGuiViewportP* viewport)
|
||||
viewport->WorkOffsetMin.x, viewport->WorkOffsetMin.y, viewport->WorkOffsetMax.x, viewport->WorkOffsetMax.y,
|
||||
viewport->PlatformMonitor, viewport->DpiScale * 100.0f);
|
||||
if (viewport->Idx > 0) { SameLine(); if (SmallButton("Reset Pos")) { viewport->Pos = ImVec2(200, 200); viewport->UpdateWorkRect(); if (viewport->Window) viewport->Window->Pos = viewport->Pos; } }
|
||||
BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s", viewport->Flags,
|
||||
(flags & ImGuiViewportFlags_CanHostOtherWindows) ? " CanHostOtherWindows" : "", (flags & ImGuiViewportFlags_NoDecoration) ? " NoDecoration" : "",
|
||||
(flags & ImGuiViewportFlags_NoFocusOnAppearing) ? " NoFocusOnAppearing" : "", (flags & ImGuiViewportFlags_NoInputs) ? " NoInputs" : "",
|
||||
(flags & ImGuiViewportFlags_NoRendererClear) ? " NoRendererClear" : "", (flags & ImGuiViewportFlags_Minimized) ? " Minimized" : "",
|
||||
(flags & ImGuiViewportFlags_NoAutoMerge) ? " NoAutoMerge" : "");
|
||||
BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s%s%s%s", viewport->Flags,
|
||||
(flags & ImGuiViewportFlags_NoDecoration) ? " NoDecoration" : "",
|
||||
(flags & ImGuiViewportFlags_NoTaskBarIcon) ? " NoTaskBarIcon" : "",
|
||||
(flags & ImGuiViewportFlags_NoFocusOnAppearing) ? " NoFocusOnAppearing" : "",
|
||||
(flags & ImGuiViewportFlags_NoFocusOnClick) ? " NoFocusOnClick" : "",
|
||||
(flags & ImGuiViewportFlags_NoInputs) ? " NoInputs" : "",
|
||||
(flags & ImGuiViewportFlags_NoRendererClear) ? " NoRendererClear" : "",
|
||||
(flags & ImGuiViewportFlags_TopMost) ? " TopMost" : "",
|
||||
(flags & ImGuiViewportFlags_Minimized) ? " Minimized" : "",
|
||||
(flags & ImGuiViewportFlags_NoAutoMerge) ? " NoAutoMerge" : "",
|
||||
(flags & ImGuiViewportFlags_CanHostOtherWindows) ? " CanHostOtherWindows" : "");
|
||||
for (int layer_i = 0; layer_i < IM_ARRAYSIZE(viewport->DrawDataBuilder.Layers); layer_i++)
|
||||
for (int draw_list_i = 0; draw_list_i < viewport->DrawDataBuilder.Layers[layer_i].Size; draw_list_i++)
|
||||
DebugNodeDrawList(NULL, viewport, viewport->DrawDataBuilder.Layers[layer_i][draw_list_i], "DrawList");
|
||||
|
@ -1531,6 +1531,7 @@ struct ImGuiContext
|
||||
ImGuiViewportP* CurrentViewport; // We track changes of viewport (happening in Begin) so we can call Platform_OnChangedViewport()
|
||||
ImGuiViewportP* MouseViewport;
|
||||
ImGuiViewportP* MouseLastHoveredViewport; // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) + honoring the _NoInputs flag.
|
||||
ImGuiID PlatformLastFocusedViewportId;
|
||||
int ViewportFrontMostStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter
|
||||
|
||||
// Gamepad/keyboard Navigation
|
||||
@ -1752,6 +1753,7 @@ struct ImGuiContext
|
||||
CurrentDpiScale = 0.0f;
|
||||
CurrentViewport = NULL;
|
||||
MouseViewport = MouseLastHoveredViewport = NULL;
|
||||
PlatformLastFocusedViewportId = 0;
|
||||
ViewportFrontMostStampCount = 0;
|
||||
|
||||
NavWindow = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user