-
-
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
Nav Branch: How to programmatically force nav highlight on item? #1074
Comments
Thanks for posting this. This type of request is an example why the NavBranch hasn't been merged yet. The issue seems to lies on the fact that you are repopulating the same window with entirely new widgets, and you expect the behavior of a newly open window to happen (select first widget, etc.). So maybe we would need a way to express this with the new API. You can probably work it around with |
Thanks for your reply! SetKeyboardFocusHere sounds like it forcibly changes the focus, which is what I said I want, but the next question is how to test when it needs to be done. If something already has focus I don't want to accidentally take focus away. IsAnyItemFocused() seemed like the thing that I would want to test, but I could not get this to work. In my DisplayMenu function listed above I tried adding the following code in the places where I was doing SetItemDefaultFocus():
But this had no effect. Putting a breakpoint on it, it was never hitting the SetKeyboardFocusHere() except on application startup (a case that was already working correctly with just using SetItemDefaultFocus). Going from one folder to another it was not calling SetKeyboardFocusHere() meaning that even though it was not highlighting any item with the blue rectangle it still thought there was IsAnyItemFocused. I also tried forcibly setting |
Update... rather than using
along with explicitly setting Perhaps these operations should be exposed as functions, such as ImGui::ClearNavFocus() // set NavId to zero but since there is already a "SetKeyboardFocusHere", it's not clear to me how the concepts of "keyboard focus" vs "nav focus" should interplay. It's just seems right now that SetKeyboardFocusHere doesn't currently affect NavId. |
Err, why closing? Isn't that a totally open question that imgui would want to solve? |
Yes, sorry I just didn't want to burden you when I had found a workable solution. Though my solution is not ideal in that ImGui isn't exposing an obvious way to do what I want and I'm having to delve in to the guts of things to make it work. I'll keep it open for you then :) |
I'm happy with keeping it open as a reminder that this is a legit (and maybe common) request that I would like to solve eventually :). Thanks! |
For the record, linking to #2048 as they haven't been linked and are essentially the same thing. |
I have added a few things related to those requests:
Other tangentially related options:
(
Technically this # also pertain to use SetKeyboardFocusHere() and other functions which are still be redesigned/improved. I'm closing this and other related issues, but feel free to comment or open new issues if you have question or problem related to those. |
Hi, I'm playing around with the Nav Branch (issue #787). I'm trying to get something working which is a gamepad driven menu. I am trying to set something up which is basically an interface choosing at item from within a folder structure, but rather than using a tree or a ImGui dropdown menu to explore the folder, I'm making more of a stateful kind of interface which displays buttons for the currently selected level of the tree. It is akin to something like windows Explorer, where the explorer window shows only the contents of the current directory, including subfolder icons and leaf-item icons.
When this folder is active it will be the only ImGui thing on the screen, and I want this to be driven by gamepad, and at any time I always want to have one of the menu items (buttons) highlighted in blue (the "nav highlight"). I think it's confusing to a pad-only user when there is no nav-highlight shown at all.
In order to force the nav-highlight to show immediately when the top-level folder appears, I have added a call to
ImGui::SetItemDefaultFocus();
for the first element in the folder. This wasn't quite enough, I also needed to explicitly doGImGui->NavDisableHighlight = false;
to get the blue highlight to show up.This works for the top-level folder, but when I enter a sub-folder nothing is immediately highlighted with the blue rectangle (although it does highlight once you start pressing up and down buttons). If I want something to be highlighted as soon as you enter the sub-folder (like the first item), it's not clear how to explicitly programmatically highlight something. I would have hoped that since the previously highlighted button ceases to exist that the the calls to SetItemDefaultFocus() would again force a new menu item button to be highlighted and that at any time something would always be highlighted. But that doesn't seem to be the case.
Furthermore, upon pressing the pad direction within the sub-folder for the first time, the nav highlight often appears in the middle of the menu, implying that it is remembering its position within the previous menu and starting at the same "button index" (it's unclear how this is actually working under the hood). I would like to be able to reset it to the top of the folder each time you enter/leave (or perhaps remember the position of the nav highlight if you leave a folder and come back again)
How can I get it so that when I'm adding and removing buttons like this there's always a nav highlight around some button that's currently being shown? How can i force the nav highlight to jump to specific button?
Here's my source code for a test case
(note, when adding this to one of the demo apps, it was necessary to comment out the code for all other ImGui windows in order for the nav highlighting to work in this window. The SetItemDefaultFocus calls seemed to be getting ignored when my test window was not the only window in the application)
Please let me know if there's a much cleaner way of doing this. It seems like I'm working against the ImGui paradigm here a bit by maintaining menu state in my application like this. Implementing this as an ImGui tree would be much cleaner for instance, but it is not the user experience I want. Perhaps there's a way to "re-skin" the trees so that the user experience is similar to this "windows explorer" style of exploration?
--thanks
The text was updated successfully, but these errors were encountered: