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 closes when window regains mouse focus #11

Open
PathogenDavid opened this issue Jul 14, 2021 · 0 comments
Open

Modal closes when window regains mouse focus #11

PathogenDavid opened this issue Jul 14, 2021 · 0 comments

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

Your Issue/Question

In my example below, I render the main menu bar only when the SDL window has focus. In the menu bar, I have a single menu and menu item to open a modal. This modal opens and behaves as expected until the window loses and regains focus, at which point the modal closes. 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!

Screenshots/Video

2021-07-13.22-44-48.mp4

Standalone, minimal, complete, and verifiable example

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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant