Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal window can not display when called by clicking menu item #1134

Closed
maxint opened this issue May 5, 2017 · 2 comments
Closed

Modal window can not display when called by clicking menu item #1134

maxint opened this issue May 5, 2017 · 2 comments
Labels

Comments

@maxint
Copy link

maxint commented May 5, 2017

Using the latest code from master branch, the following code does not work.

if (ImGui::BeginMainMenuBar())
{
    if (ImGui::BeginMenu("Help"))
    {
        if (ImGui::MenuItem("About...", "F1"))
            ImGui::OpenPopup("About");
        if (ImGui::BeginPopupModal("About", NULL, ImGuiWindowFlags_AlwaysAutoResize))
        {
            if (ImGui::Button("OK", ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); }
            ImGui::EndPopup();
        }
        ImGui::EndMenu();
    }
    ImGui::EndMainMenuBar();
}

I check the source code of imgui. When "About..." menu item is clicked.

// Automatically close popups
if (pressed && !(flags & ImGuiSelectableFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
    CloseCurrentPopup();

Then IsPopupOpen() check failed. as g.OpenPopupStack.Size == g.CurrentPopupStack.Size right now.

static bool IsPopupOpen(ImGuiID id)
{
    ImGuiContext& g = *GImGui;
    return g.OpenPopupStack.Size > g.CurrentPopupStack.Size && g.OpenPopupStack[g.CurrentPopupStack.Size].PopupId == id;
}
@maxint maxint changed the title Modal window can not display when called by menu item Modal window can not display when called by clicking menu item May 5, 2017
@ocornut
Copy link
Owner

ocornut commented May 5, 2017

  1. The menu will be closed when you click the MenuItem(), so you cannot put BeginPopupModal() instead the menu if block.

  2. There's another problem with mismatching ID which is not fully solved, see:
    Can not open modal popup from menu / Issue with ID stack #331

For now you should call OpenPopup() from the same scope you are calling BeginPopup().

Closing because duplicate of #331.

@ocornut ocornut closed this as completed May 5, 2017
@maxint
Copy link
Author

maxint commented May 5, 2017

Hi omar,
Thanks for your fast replay 😄 I will follow #331.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants