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

Double-click window collapsing doesn't correctly test for other active widgets e.g. InvisibleButton(..., ImGuiButtonFlags_MouseButtonRight) #7841

Closed
achabense opened this issue Jul 30, 2024 · 2 comments
Labels

Comments

@achabense
Copy link

Version/Branch of Dear ImGui:

Version 1.90.9

Back-ends:

imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer2.cpp

Compiler, OS:

Windows 10 + MSVC 2022

Full config/build information:

No response

Details:

For InvisibleButton(..., ImGuiButtonFlags_MouseButtonRight), when the button is right-clicked and held, users can still collapse the windows by (left) double-clicking the title bars. I think this behavior is a bit surprising.

Screenshots/Video:

effect

Minimal, Complete and Verifiable Example code:

If the invisible button is right-clicked, interactions with other widgets are disabled as expected, but A or B window will still be collapsed when their title bars are (left) double-clicked.

void issue() {
    static bool a = true, b = true;

    if (a) {
        if (ImGui::Begin("A", &a)) {
            ImGui::InvisibleButton("Invisible", {100, 100}, ImGuiButtonFlags_MouseButtonRight);
            ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32_WHITE);
        }
        ImGui::End();
    }

    if (b) {
        if (ImGui::Begin("B", &b)) {
            ImGui::Button("B", {100, 100});
        }
        ImGui::End();
    }
}
@ocornut ocornut added the bug label Jul 30, 2024
@ocornut ocornut changed the title InvisibleButton(..., ImGuiButtonFlags_MouseButtonRight) and window-collapsing Double-click window collapsing doesn't correctly test for other active widgets e.g. InvisibleButton(..., ImGuiButtonFlags_MouseButtonRight) Jul 30, 2024
@ocornut
Copy link
Owner

ocornut commented Jul 30, 2024

Hello,
Thanks for reporting.
This seems to be a bug related to the fact that specifically the "double click on title bar empty space" behavior is not consistent with practically any other behavior in the code.

Code does:

// We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed), so verify that we don't have items over the title bar.
ImRect title_bar_rect = window->TitleBarRect();
if (g.HoveredWindow == window && g.HoveredId == 0 && g.HoveredIdPreviousFrame == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max))
    if (g.IO.MouseClickedCount[0] == 2 && GetKeyOwner(ImGuiKey_MouseLeft) == ImGuiKeyOwner_NoOwner)
        window->WantCollapseToggle = true;

I'm not even sure why the code doesn't simply add a if (g.ActiveId == 0) code, seems like it would fix it, and we could remove the GetKeyOwner() test as well. Will investigate at some point.

ocornut added a commit that referenced this issue Sep 17, 2024
@ocornut
Copy link
Owner

ocornut commented Sep 17, 2024

I have pushed a fix dad9f45 for this. Thanks!

@ocornut ocornut closed this as completed Sep 17, 2024
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