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

When you click on the menu, it will automatically click on the menu item #8233

Open
o-3-o opened this issue Dec 16, 2024 · 5 comments
Open
Labels
bug inputs menus menu bars, menu items

Comments

@o-3-o
Copy link

o-3-o commented Dec 16, 2024

Version/Branch of Dear ImGui:

Version 1.91.6 master

Back-ends:

imgui_impl_dx11.cpp + imgui_impl_win32.cpp

Compiler, OS:

win11+vs2022

Full config/build information:

Dear ImGui 1.91.6 (19160)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1942
define: _MSVC_LANG=201402
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000003
 NavEnableKeyboard
 NavEnableGamepad
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
io.DisplaySize: 1264.00,761.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

If the mouse is over a sub-item when the menu pops up, it will automatically click

Screenshots/Video:

动画

Minimal, Complete and Verifiable Example code:

ImGui::ShowDemoWindow();
@ocornut ocornut added bug menus menu bars, menu items inputs labels Dec 16, 2024
@ocornut
Copy link
Owner

ocornut commented Dec 16, 2024

Thanks for your report.
This is tricky. MenuItem() intentionally uses ImGuiSelectableFlags_NoSetKeyOwner:

// We use ImGuiSelectableFlags_NoSetKeyOwner to allow down on one menu item, move, up on another.
const ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_SelectOnRelease | ImGuiSelectableFlags_NoSetKeyOwner | ImGuiSelectableFlags_SetNavIdOnHover;

The reason is that we explicitly want a single mouse down to be able to browse child menus (some people use menus this way).
But that logic breaks when the next appearing child menu is overlapping the current mouse position.
I don't yet know what the better workaround would be.

Are you directly impacted by this?

@o-3-o
Copy link
Author

o-3-o commented Dec 17, 2024

Thanks for your report. This is tricky. MenuItem() intentionally uses ImGuiSelectableFlags_NoSetKeyOwner:

// We use ImGuiSelectableFlags_NoSetKeyOwner to allow down on one menu item, move, up on another.
const ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_SelectOnRelease | ImGuiSelectableFlags_NoSetKeyOwner | ImGuiSelectableFlags_SetNavIdOnHover;

The reason is that we explicitly want a single mouse down to be able to browse child menus (some people use menus this way). But that logic breaks when the next appearing child menu is overlapping the current mouse position. I don't yet know what the better workaround would be.

Are you directly impacted by this?

Thank you for your answer. Yes, I did solve this problem after commenting out if (flags & ImGuiSelectableFlags_NoSetKeyOwner) { button_flags |= ImGuiButtonFlags_NoSetKeyOwner; } in the Selectable API. However, the BeginMenu API does not set an option for this flag, which will result in the inability to click on the expected menu item when the window size is small.

@o-3-o
Copy link
Author

o-3-o commented Dec 21, 2024

Hello @ocornut Excuse me, is there a way to prevent the menu from using the ImGuiSelectableFlags_NoSetKeyOwner flag? Without polluting the Dear ImGui file.

@ocornut
Copy link
Owner

ocornut commented Dec 21, 2024 via email

@o-3-o
Copy link
Author

o-3-o commented Dec 21, 2024

Yes, I want to use imgui to make a desktop application UI framework, but it is still in the testing stage of the framework. This desktop application fills the main window with full screen. Under normal circumstances, this problem is not easy to trigger. In order to deal with all emergencies, it does not rule out that other users will set the window to this size. It would be perfect if there is an option to control it.
动画

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug inputs menus menu bars, menu items
Projects
None yet
Development

No branches or pull requests

2 participants