1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-13 18:50:58 +01:00

WIP Menus: Fixed closing popup on menu item activation when a child menu is open from the popup (#126)

This commit is contained in:
ocornut 2015-05-24 22:30:48 +01:00
parent 3498617a3c
commit 48ede93a58

View File

@ -3056,14 +3056,15 @@ static void ClosePopup(const char* str_id) // not exposed because 'id' scope is
void ImGui::CloseCurrentPopup()
{
ImGuiState& g = *GImGui;
if (g.CurrentPopupStack.empty() || g.OpenedPopupStack.empty() || g.CurrentPopupStack.back().PopupID != g.OpenedPopupStack.back().PopupID)
int popup_idx = (int)g.CurrentPopupStack.size() - 1;
if (popup_idx < 0 || popup_idx > (int)g.OpenedPopupStack.size() || g.CurrentPopupStack[popup_idx].PopupID != g.OpenedPopupStack[popup_idx].PopupID)
return;
if (g.CurrentWindow->PopupID == g.OpenedPopupStack.back().PopupID && g.Windows.size() >= 2)
if (g.CurrentWindow->PopupID == g.OpenedPopupStack[popup_idx].PopupID && g.Windows.size() > 1)
FocusWindow(g.Windows[g.Windows.size()-2]);
g.OpenedPopupStack.pop_back();
g.OpenedPopupStack.resize(popup_idx);
}
static void CloseAllPopups()
static void CloseCurrentMenus()
{
// Close all popups
// FIXME-MENUS: invalid for popup->menus with current BeginMenu() scheme
@ -7317,7 +7318,7 @@ static bool SelectableEx(const char* label, bool selected, const ImVec2& size_ar
// Automatically close popups
if (pressed && (window->Flags & ImGuiWindowFlags_ChildMenu))
CloseAllPopups();
CloseCurrentMenus();
else if (pressed && (window->Flags & ImGuiWindowFlags_Popup))
ImGui::CloseCurrentPopup();
return pressed;