-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Menus API work #126
Comments
To mimic similar existing api, the "default" could be something like this:
Using overload of Item(), Not considering extra parameters to MenuBegin yet.
But something along those lines. The order of parameters makes it a bit tricky if we want to add a printf-format style version of the function, but I imagine this is rather rare (e.g. for filenames in a Recent Files you may want to embed a local shortcut). I don't have a solution I am happy with for that. |
I would imagine that Popup menu can work in a similar way:
|
Yes, but you'd need to keep track of the menu lifetime somehow. Pseudo-code:
ImGui would keep track of the menu being active. Clicking outside the menu or pressing Escape would deactivate it. Or better?
Except ID can be string / idx / pointer the same way ImGui::TreeNode() allows for all three. Then within a tree we can test for right-click over a node and start a popup that would run for this specific node. |
How would it work for mouse? Something like this?
I think this is quite common because you may not press an actual control to bring up a Popup menu. |
Hum.. I think I like approach 1 better even if I don't have any strong opinions about it. |
Under the above scheme it would be somethng like
Which leaves a chance for another item to be active or another more specialized menu to run. Note how the Begin() test is outside of the mouse test block. With the Open/Begin scheme maybe Begin is a misleading word. It is more analogous to TreeNode() which tests a state (is the tree node open). Or if we keep the bool on the user side as in the first example of my previous post, then we become more analogous to Begin() so it is clearer but the common case requires a little more work. So to reiterate:
|
Alright. That makes sense. |
Add to that: as a user I would like to be able to right-click on any tree node and have popup with a "Copy" button that allows copying the entire node contents to the clipboard (the logging api allows to do that easily). I think it'd be a sensible default in many cases. Now, ideally I don't want to user to have to add the popup code after every TreeNode call. The user can create their own replacement helper for TreeNode() that does both. Or we can have a dedicated functionality just for this case were TreeNode can automatically spawn a popup with a "Copy" function when right-clicking. Or we can have a system where the user can push a callback to provide a default popup menu. Either way it would need to allow the user code to ignore that menu and create their own. Not sure how to approach that exactly but it is solvable. I guess this is more of a feature of the general/tree API rather than specific to menus. |
FYI i tested and added a demo of the idea of creating popup menus with the existing API.
There's a few problems but it works. I hope by the next version I'll be able to turn that into a 2nd class citizen (with shorter API, automatic positioning, clipping within screen, perhaps ALT+letter shortcuts). Some of the most immediate problems with this:
|
I added a simple BeginPopup() / EndPopup() API to wrap the pattern above.
|
I tweaked that enough that BeginPopup() / EndPopup() is pretty much usable now. You won't get icons/shortcuts/submenus expected in a normal menu yet. |
Nice! Will check this out as soon as I have time. |
Hmm strange is your style modified? |
OK yeah it happens if WindowPadding.x < AutoFitPadding.x |
Oh, okay. I just wanted to post all my style settings. These are the two you mentioned:
|
It's not actually new it's a bug in Selectable() but the auto-resizing windows shows it clearly. The repro is:
|
Pushed a fix! Let me know if that works for you :) I deleted 1.37 and will republish it. |
I haven't investigated this but is it possible to use submenus with this approach also? |
Not really yet, it's not really a proper menu API. You can do sub popups on click but that wouldn't be super user friendly. We want sub-menu hover, automatic positioning and alignment, etc. |
Cool :) I will wait a bit then with removing my native (as in platform specific) popups until you have it in. |
I've been testing this for last few days and so far everything works perfectly, great job! Something that would be useful is a way to know whether there is any menu or popup currently open to allow ignoring mouse clicks in the void area which are only meant to close all currently open menu/popups - right now such clicks can (depending on the application) cause unwanted non-gui interactions because WantCaptureMouse is false |
…child (#126) It think it makes more sense? Maybe? Note that calling OpenPopup() every frame probably doesn't make sense.
Good to hear it's working well for you. Note that I may still change the name of the 3 functions I added yesterday (currently BeginPopupContextItem / BeginPopupContextWindow / BeginPopupContextVoid). I'll look into what you're mentioning. I think the bug should be that WantCaptureMouse should always be true automatically when a popup is active, so you don't have to check that yourself. |
…racked mouse button ownership when mouse down (#126)
@thevaber : should be fixed now. When you close a popup or menu by clicking in void WantCaptureMouse will be kept high as long as the button isn't released. I am now seeing that the input inhibition performed by popups/menus doesn't match what Windows is doing with menus. Windows only inhibits inputs for things under the popup for the same window, but other windows aren't affected. I wonder if I should work toward that. The reason it relates to WantCaptureMouse is that with the fix above if you have a menu open it might feels unreactive if you click on the void to, say, move your game 3d camera and it doesn't work on the first click, you need to release and click. However having popups/menus open and trying to close them isn't such a common thing and it should be understandable to the user why they need to click once to close the popups/menus before they can interact with your game. The difference between an operating system with a desktop and imgui "void" in your game app is that you never actually have void, that space is likely used by the rest of your app and if you are using inputs to interact with that space then we are left with nowhere to click on to close a popup without triggering something. |
Thanks for the fix! Indeed, for some applications this behavior might not be desirable, while for some it is nearly essential. My use case is a painting application - think photoshop, you have a brush tool selected and you start doing something in menus - then you change your mind, and click outside the menu to get rid of it, likely on the canvas - and you don't want that to actually paint anything. In photoshop (and other similar software I tried) this is the case, no painting is done on such mouse clicks (until the mouse button is released and clicked again), but clicking anywhere other than the canvas works exactly as Windows OS does it, like you described (ignoring clicks to the same window). But for some other applications, even clicking the "void" (well, non-imgui area) should actually do something. I see some applications solving this by having a rather short timer for closing the menu when it's not hovered, thus not requiring a mouse click to close the menu at all, though that seems not exactly ideal either, it feels quite cumbersome.. So I'm guessing that this void click behavior will probably need to be configurable, or perhaps use another WantCaptureMouse-like variable (something like WantCaptureMouseVoid, which anyone can choose to ignore or OR it with WantCaptureMouse)? |
Yes that would make sense. I'll wait until actual feedback come to get the "other" behavior before adding something. Menus are still new. Also don't hesitate to post screenshots if you're done something cool that you can share! |
for me clicking in void to close the popup and ignoring that click |
…)+ comments Sorry if you used this parameter already.
I am going to release that as 1.40 (skipping 1.39 because the changelist is very huge already) in a few hours. Hopefully we won't find a bug that would require to change all the API the next day. |
Closing this topic for now. Bug fixes and additions such as shortcuts, e.g. can be handled in a separate topic. |
…ting inside one of their child. If a Left<>Right navigation request fails to find a match we forward the request to the root menu. (#787, #126) Currently the sibling menu is isn't automatically opened, that's still left to it (and even that can be anoying in Windows when the first menu-item is a child menu)
…e via internals) + fix menus being affected by style.SelectableTextAlign (#126)
…e via internals) + fix menus being affected by style.SelectableTextAlign (#126)
Discussion for an upcoming menu api (still being designed).
If you have ideas or references of menu being implemented in imgui systems please post here!
Some thoughts:
The text was updated successfully, but these errors were encountered: