mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 06:06:35 +00:00
Popups: popups can be closed with a right-click anywhere, without altering focus under the popup.(~#439)
This commit is contained in:
parent
853018dd4d
commit
87ae40843c
19
imgui.cpp
19
imgui.cpp
@ -643,7 +643,7 @@ static void MarkIniSettingsDirty(ImGuiWindow* window);
|
||||
|
||||
static ImRect GetVisibleRect();
|
||||
|
||||
static void CloseInactivePopups();
|
||||
static void CloseInactivePopups(ImGuiWindow* ref_window);
|
||||
static void ClosePopupToLevel(int remaining);
|
||||
static ImGuiWindow* GetFrontMostModalRootWindow();
|
||||
static ImVec2 FindBestPopupWindowPos(const ImVec2& base_pos, const ImVec2& size, int* last_dir, const ImRect& rect_to_avoid);
|
||||
@ -2441,7 +2441,7 @@ void ImGui::NewFrame()
|
||||
// But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
|
||||
g.CurrentWindowStack.resize(0);
|
||||
g.CurrentPopupStack.resize(0);
|
||||
CloseInactivePopups();
|
||||
CloseInactivePopups(g.NavWindow);
|
||||
|
||||
// Create implicit window - we will only render it if the user has added something to it.
|
||||
// We don't use "Debug" to avoid colliding with user trying to create a "Debug" window with custom flags.
|
||||
@ -2773,7 +2773,7 @@ void ImGui::EndFrame()
|
||||
|
||||
if (g.ActiveId == 0 && g.HoveredId == 0)
|
||||
{
|
||||
if (!g.NavWindow || g.NavWindow->WasActive || !g.NavWindow->Active) // Unless we just made a popup appear
|
||||
if (!g.NavWindow || !g.NavWindow->Appearing) // Unless we just made a window/popup appear
|
||||
{
|
||||
// Click to focus window and start moving (after we're done with all our widgets)
|
||||
if (g.IO.MouseClicked[0])
|
||||
@ -2794,6 +2794,13 @@ void ImGui::EndFrame()
|
||||
FocusWindow(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// With right mouse button we close popups without changing focus
|
||||
// (The left mouse button path calls FocusWindow which will lead NewFrame->CloseInactivePopups to trigger)
|
||||
if (g.IO.MouseClicked[1])
|
||||
{
|
||||
CloseInactivePopups(g.HoveredWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3567,7 +3574,7 @@ void ImGui::OpenPopup(const char* str_id)
|
||||
OpenPopupEx(g.CurrentWindow->GetID(str_id), false);
|
||||
}
|
||||
|
||||
static void CloseInactivePopups()
|
||||
static void CloseInactivePopups(ImGuiWindow* ref_window)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.OpenPopupStack.empty())
|
||||
@ -3576,7 +3583,7 @@ static void CloseInactivePopups()
|
||||
// When popups are stacked, clicking on a lower level popups puts focus back to it and close popups above it.
|
||||
// Don't close our own child popup windows
|
||||
int n = 0;
|
||||
if (g.NavWindow)
|
||||
if (ref_window)
|
||||
{
|
||||
for (n = 0; n < g.OpenPopupStack.Size; n++)
|
||||
{
|
||||
@ -3589,7 +3596,7 @@ static void CloseInactivePopups()
|
||||
|
||||
bool has_focus = false;
|
||||
for (int m = n; m < g.OpenPopupStack.Size && !has_focus; m++)
|
||||
has_focus = (g.OpenPopupStack[m].Window && g.OpenPopupStack[m].Window->RootWindow == g.NavWindow->RootWindow);
|
||||
has_focus = (g.OpenPopupStack[m].Window && g.OpenPopupStack[m].Window->RootWindow == ref_window->RootWindow);
|
||||
if (!has_focus)
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user