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

Overlapped/Nested button not receiving any events #6303

Closed
mungaihehe opened this issue Apr 5, 2023 · 6 comments
Closed

Overlapped/Nested button not receiving any events #6303

mungaihehe opened this issue Apr 5, 2023 · 6 comments
Labels

Comments

@mungaihehe
Copy link

Version/Branch of Dear ImGui:

Version: 1.89.5 WIP
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

My Problem
nested buttons

The inner button (or input text) isn't receiving any mouse events

Is there any way to have a nested button that can be activated?

Thanks in advance

@emoon
Copy link
Contributor

emoon commented Apr 5, 2023

Without you showing any of your code it's hard to say, but make sure to validate against this https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-why-is-my-widget-not-reacting-when-i-click-on-it

@GamingMinds-DanielC
Copy link
Contributor

The ID stack is an option, but my bet would be a missing SetItemAllowOverlap() for the outer button. Impossible to say for sure without code though.

@ocornut
Copy link
Owner

ocornut commented Apr 5, 2023

See this comment #3909 (comment)
About using SetItemAllowOverlap() and overlapping mode.
By default, the first submitted widget gets mouse hit, with AllowOverlap mode that order is reversed.

@ocornut ocornut changed the title Nested button not receiving any events Overlapped/Nested button not receiving any events Apr 5, 2023
@mungaihehe
Copy link
Author

Thanks for your help so far @GamingMinds-DanielC @emoon @ocornut

Here is the code

            ImGui::SetNextWindowSize(ImVec2(600, 600));
            ImGui::Begin("Sample window");

                auto cursor = ImGui::GetCursorPos();
                bool isOverlappingClicked = ImGui::InvisibleButton("Outer Button", ImGui::GetContentRegionAvail());
                if (isOverlappingClicked) {
                    std::cout << "Outer Button Clicked" << std::endl;
                }
    
                ImGui::SetItemAllowOverlap();
    
                ImGui::SetCursorPos(cursor);
                if (ImGui::Button("Inner button")) {
                    std::cout << "Inner Button Clicked" << std::endl;
                }

            ImGui::End();

The behaviour
2023-04-06 16-27-24

I can't get the "Inner button" to register clicks. What am I missing?

@ocornut
Copy link
Owner

ocornut commented Jun 12, 2023

@mungaihehe sorry for late answer. A behavior change in 1.89 changed this. See #3909 (comment)
At the moment you need to also pass ImGuiButtonFlags_AllowItemOverlap to InvisibleButton() to get this to work.

@ocornut
Copy link
Owner

ocornut commented Jun 28, 2023

This is now fixed but required an API change, see #6512 (comment)

@ocornut ocornut closed this as completed Jun 28, 2023
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

4 participants