Skip to content
New issue

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

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

Already on GitHub? # to your account

CloseCurrentPopup() closes all stacked modal Popups when left mouse button is clicked on non-widget space #2880

Closed
elvissteinjr opened this issue Nov 3, 2019 · 2 comments
Labels

Comments

@elvissteinjr
Copy link

Version/Branch of Dear ImGui:

Version: 1.73
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32.cpp + imgui_impl_dx11.cpp
Compiler: MSVC15
Operating System: Windows 10

My Issue/Question:

I realize what I'm doing might be considered too specialized and there's a workaround, but I still found the behavior odd.

My goal is to have a modal popup, which was opened from another modal popup, take any keyboard/mouse input, then close it. For input binding purposes.
This works fine unless the left mouse click is used on the popup window itself and no widget takes the input. In that case, all popups are closed.

A workaround is to delay closing to the next frame, so it's not a huge deal. Still thought I should perhaps report it anyways. I'm also somewhat new to Dear ImGui, so I hope I didn't miss something obvious here.

Standalone, minimal, complete and verifiable example: (see #2261)

ImGui::Begin("Stacked Modal Popups");

    if (ImGui::Button("Open Modal Popup 1"))
    {
        ImGui::OpenPopup("Popup1");
    }

    if (ImGui::BeginPopupModal("Popup1"))
    {
        if (ImGui::Button("Open Modal Popup 2"))
        {
            ImGui::OpenPopup("Popup2");
        }

        if (ImGui::BeginPopupModal("Popup2"))
        {
            ImGui::Text("Click anywhere");

            if (ImGui::IsMouseClicked(0))
            {
                ImGui::CloseCurrentPopup();
            }

            ImGui::EndPopup();
        }

        ImGui::EndPopup();
    }

ImGui::End();
@ocornut ocornut added the popups label Nov 4, 2019
@ocornut
Copy link
Owner

ocornut commented Jun 16, 2020

I looked into it and the problem is that CloseCurrentPopup() does mark "Popup2" as closed by trimming g.OpenPopupStack, but at the same time at the end of frame we detect the click on Popup2 which leads to StartMouseMovingWindow > FocusWindow > ClosePopupsOverWindow and at that point Popup2 is not marked as an open popup so considered a regular window and therefore it consider Popup1 as a popup to close.

Trying to think of a fix.

ocornut added a commit that referenced this issue Jun 16, 2020
…clicking on its empty space would attempt to focus it and close other popups. (#2880)
@ocornut
Copy link
Owner

ocornut commented Jun 16, 2020

I explored various way and found a suitable fix for it, now pushed.
Thanks for reporting this!

@ocornut ocornut closed this as completed Jun 16, 2020
ocornut added a commit that referenced this issue Jul 14, 2020
…31fe97.  (#3344, #2880)

This would be problematic e.g. in situation where the application relies on io.WantCaptureKeyboard flag being cleared accordingly.
Mernion pushed a commit to Mernion/imgui that referenced this issue Aug 3, 2020
…31fe97.  (ocornut#3344, ocornut#2880)

This would be problematic e.g. in situation where the application relies on io.WantCaptureKeyboard flag being cleared accordingly.
ocornut added a commit that referenced this issue Feb 20, 2024
…ld erroneously close the window. (#7325, #7287, #7063)

Amend 76e09c4. Initial call to ClosePopupToLevel d31fe97 (#2880).
See "widgets_menu_reopen_2" in TestSuite.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants