-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
How to set the current keyboard focus. #1712
Comments
Okay, setting the context's .NavId seems to work for me, but is there a less brutal way to move the keyboard focus? |
Hello @eriksintorn, There's no public API at the moment but you can use There's a private branch I started working on with functions to Focus and Activate items, and handle Tabbing more consistently, but there was a couple of tricky unsolved issues so that's unfinished at the moment. |
Perfect! To also get the selected item highlighted I'm still hacking a bit. But this will work fine until you've finished a proper API. I am amazed with the quality of this library, and the speed with which you answer questions! Thank you very much.
|
I spent 3-4 days on the proper API (which encompassed some other things such as the tabbing) and the code was becoming a little too complex so I'll need to rework it, I don't know when but hopefully within a few months. Note that you should not want/need to ever modify imgui.cpp, you can include A word of warning though:
Dear ImGui is really not designed for in-game UI. I believe if you go this way you will encounter a lot of small and tricky hurdles to overcome if you are aiming for high-quality in-game UI. I would personally advise against it but I know some people have been doing it. The most accomplished case I can think of doing it is the game Deformers: Which went the way of redrawing their own controls over using imgui underlying logic (ignoring imgui render output). Somehow apparently the directional navigation worked for them. Personally I would suggest creating custom widgets for in-game, and you may use ImDrawList and some of the lower-level ImGui stuff if you are comfortable with that. |
No worries, we are aiming for a shockingly rudimental UI at the moment :). Thanks again. |
@eriksintorn You are probably not into this anymore, but replying so there are references for others:
(1) The reason for (2) is that attempting to implement this properly requires a large amount of design for features and flags, related to window focusing, opt-in/opt-out override of modals covering the target, scrolling in target window and potentially its parents, handling of highlight state and nav cursor visibility, clipping issues etc. I have been slowly converging toward assembling and designing many of the features but for this specific thing it hasn't materialized into a nice public API yet, but I feel I am getting pretty close. |
Hello,
Apologies if there is an obvious answer to this, but I cannot find it. In my game, I have an inventory represented by a number of buttons. When I press a specific key, focus is shifted to that window and I can use the keyboard to navigate to the button (item) I want to use, and it is nicely highlighted.
I am wondering if there is any way to set the current keyboard focus (the currently selected item/button) in code? I've obviously tried SetKeyboardFocusHere(), but that seems to only work on InputText and similar widgets, not buttons? Or am I doing something wrong?
Any help greatly appreciated, thanks.
The text was updated successfully, but these errors were encountered: