Popups: reworked GetMousePosOnOpeningCurrentPopup() to be legal to call within the BeginPopup/EndPopup scope of a popup which was just closed. (#9551)

This commit is contained in:
ocornut 2026-09-22 15:57:40 +02:00
parent 58d7570b8b
commit d12321803d
2 changed files with 3 additions and 2 deletions

View file

@ -83,6 +83,8 @@ Other Changes:
- Amended context menu right-click opening code to check that the right-click
hasn't been owned by another items. This is more correct and also necessary
to avoid Drags/Sliders cancelling also triggering a cancel menu. (#8564, #9534)
- Reworked `GetMousePosOnOpeningCurrentPopup()` to be legal to call within
the BeginPopup/EndPopup scope of a popup which was just closed. (#9551) [@jkunstwald]
- ImGuiTextFilter:
- Added support for space as an "and" filter, which is the standard. (#2435, #30)
e.g. w/ filter 'hello world' (without quotes) both words needs to be in input data.

View file

@ -10269,12 +10269,11 @@ void ImGui::TeleportMousePos(const ImVec2& pos)
//IMGUI_DEBUG_LOG_IO("TeleportMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y);
}
// NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed!
ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup()
{
ImGuiContext& g = *GImGui;
if (g.BeginPopupStack.Size > 0)
return g.OpenPopupStack[g.BeginPopupStack.Size - 1].OpenMousePos;
return g.BeginPopupStack[g.BeginPopupStack.Size - 1].OpenMousePos;
return g.IO.MousePos;
}