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

(New template) Modal closes when window regains mouse focus #14

Open
PathogenDavid opened this issue Jul 14, 2021 · 1 comment
Open
Labels

Comments

@PathogenDavid
Copy link
Member

PathogenDavid commented Jul 14, 2021

Version

1.84 WIP (18302)

Branch

master

Platform Backend

imgui_impl_sdl

Renderer Backend

imgui_impl_opengl3

Compiler

No response

Operating System

Ubuntu 20.04

Steps to Reproduce

  1. Add the code below to example_sdl_opengl3 and launch the example
  2. Select File -> Open Modal in the menu bar
  3. Click off the main viewport window (the menu bar will disappear)
  4. Click back on the main viewport window
bool open_modal = false;
if (SDL_GetMouseFocus()) {
    if (ImGui::BeginMainMenuBar()) {
        if (ImGui::BeginMenu("File")) {
            open_modal = ImGui::MenuItem("Open Modal");
            ImGui::EndMenu();
        }
        ImGui::EndMainMenuBar();
    }
}
if (open_modal) {
    ImGui::OpenPopup("Modal");
}
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal("Modal", NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
    if (ImGui::Button("Close")) {
        ImGui::CloseCurrentPopup();
    }
    ImGui::EndPopup();
}

Expected Behavior

The menu bar reappears and the modal stays open.

Actual Behavior

The menu bar reappears, but the modal closes unexpectedly.

2021-07-13.22-44-48.mp4

Other Details

I want to render the main menu bar only when the SDL window has focus. Ideally, the modal would remain open until I call ImGui::CloseCurrentPopup(). I'm wondering if I'm misusing modals or if this is possible a bug. Is there a preferred way to implement this behavior?

Apologies if this is a redundant question. I see #331, but my question is more of a tangent from the discussion in that issue.

Thank you for taking a look!

@PathogenDavid
Copy link
Member Author

👆 Note that I did not actually add that label, it was added automagically since I was using the bug report template

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

1 participant