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

Submenus not closing when hovering something else in the menu #5546

Closed
BluTree opened this issue Aug 5, 2022 · 6 comments
Closed

Submenus not closing when hovering something else in the menu #5546

BluTree opened this issue Aug 5, 2022 · 6 comments
Labels
menus menu bars, menu items

Comments

@BluTree
Copy link

BluTree commented Aug 5, 2022

Version/Branch of Dear ImGui:

Version: 1.89 WIP
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Operating System: W11

My Issue:

When menu have submenus, the submenu is not always closed when moving from the submenu item to another item.
This often happens when we move the cursor slowly from the submenu item to the other item.

Screenshots/Video
imgui

@ocornut ocornut added the menus menu bars, menu items label Aug 5, 2022
@ocornut
Copy link
Owner

ocornut commented Aug 5, 2022

We have intentionally logic in place that doesn't close a child-menu if you are moving toward it.

image

This allows for menus to open/close without delay.

The way this logic works is currently not perfect.

  • First of all, I just found a bug with it where in some cases it didn't enable at all (will try to fix soon): but that's not your problem since in your case it is enabled.
  • When enabled it's a bit too flaky right now and I think we should improve it and use a sort of decay timer.

But I have to ask you if you reported that as a curiosity you noticed but if you genuinely felt the interaction was problematic in your daily usage?

@BluTree
Copy link
Author

BluTree commented Aug 5, 2022

Thanks for your response !

I understand the purpose of the logic, but in the case I am, it is more a problem.
To explain quickly what I wanted to do, I wanted to create a delay before a submenu shows when hovering the item (by having a MenuItem, and replacing it by a submenu when the timer is finished).
With the logic of not closing the submenu while the mouse goes closer to it, my timer cannot reset if the mouse is still in the triangle (since the IsHovered of the other item will be false), and I find this problematic.

Right now the BeginMenu doesn't take any other parameters than its label and its enablement, so an alternative could be to add a flag when we want to disable this behaviour ?

@ocornut
Copy link
Owner

ocornut commented Aug 8, 2022

To explain quickly what I wanted to do, I wanted to create a delay

Why ? Always explain why otherwise I'll assume this is a XY Problem question.

@BluTree
Copy link
Author

BluTree commented Aug 8, 2022

The menus I'm working on is to preview windows as submenus, that will open as real windows when clicking on the submenu item. We wanted to create that delay to avoid previewing the window at the first frame, but after the user keep the mouse during that delay.

@ocornut
Copy link
Owner

ocornut commented Aug 8, 2022

I don't think you need to use MenuItem() or BeginMenu() at all. Use e.g. a Selectable() and you can show your preview in a tooltip which you can position with SetNextWindowPos().

@BluTree
Copy link
Author

BluTree commented Aug 8, 2022

Oh yes, a selectable can totally do the work indeed, I just need to see how the submenu position is computed to recreate this for my tooltip. Thanks for the advice.

@BluTree BluTree closed this as completed Aug 8, 2022
ocornut pushed a commit that referenced this issue Sep 1, 2022
… WIP) (#2517, #5614, noticed in #5546)

Amend bda2cde
Fixes the case where following menu hover sequence results in incorrect RestoreNavWindow (previously SourceWindow) pointing to opened sub-menu:
1. Hover "Menu -> Options" - Open ##Menu_01 window
2. Hover "Menu -> Colors"  - SourceWindow incorrectly points to ##Menu_01 window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
menus menu bars, menu items
Projects
None yet
Development

No branches or pull requests

2 participants