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

Need reliable way to set keyboard navigation position by code #3208

Open
JPGygax68 opened this issue May 6, 2020 · 3 comments
Open

Need reliable way to set keyboard navigation position by code #3208

JPGygax68 opened this issue May 6, 2020 · 3 comments
Labels
focus nav keyboard/gamepad navigation scrolling

Comments

@JPGygax68
Copy link

After more than a dozen hours trying all kinds of combinations of SetActiveID(), SetNavID(), SetFocusID() SetKeyboardFocusHere() and even SetNavIDWithRectRel(), I am completely stuck.

What I need to do seems simple enough: I have to be able to set the keyboard navigation position to specific widgets by code, in order to create a tab sequence that will feel sufficiently natural to users.

I truly believe I've tried everything. I tried to follow the code, but must confess that I couldn't figure out how it works in this regard.

Following a suggestion from Discord, I also tried ActivateItem(), which was one of my many "almost worked" moments. The problem with that attempt was that, when applied to a TreeNode, will also toggle it.

I get the feeling that it cannot be as difficult as all that; after all, all I want is to imitate what the keyboard navigation system already does. But without help, I will have to abandon this and redesign my UI to work without keyboard navigation, though I'm afraid my customer will reject the result.

@ocornut ocornut added focus nav keyboard/gamepad navigation scrolling labels May 6, 2020
@ocornut
Copy link
Owner

ocornut commented May 8, 2020

I believe it's missing a few functions right now.

Basically there are three aspects to it:

  1. SetNavID() will set the nav focus and this is the main function you want to use.

  2. However this doesn't guarantee that the focused items will be visible, for this you could call ScrollToBringRectIntoView() but the problem is that for this you need to know it's position, which you don't necessarily know at the time you call SetNavID(), so if you want to hack around it you may need to do it awkwardly over two frames.

  3. Although focus is set, the keyboard focus highlight tends to get disabled when using the mouse. See Activate navigation by default #2048 (comment) for this.

TL;DR; is that it's currently not easy to do all of this from your side of thing but hopefully those three points can guide you toward a short-term workaround.

I understand this is a current issue with Navigation which needs to be resolved, the problem being that if you dig into some gritty details it gets more tricky, but basically I should sit down and work on it. Being honest, some of the internal functions for Navigation are a large confusing mess, so our current approach is to first add more tests to clarify some of the subtle features and then we'd be in an easier position to make those changes without breaking stuff.

@JPGygax68
Copy link
Author

JPGygax68 commented May 8, 2020

Thanks @ocornut . I'm afraid that there's something more to it, because I was already making use of all the functions you mentioned. Could it be that the built-in tab navigation interferes with my attempts? Could that be turned off?

Or could it possibly be the arrow key navigation system that is interfering? I know that one can be turned off globally, but could it be turned off for a specific window and its children?

(Do not get me wrong though, the keyboard navigation system usually works very intuitively and is a genuine advantage over other UI libraries.)

@ocornut
Copy link
Owner

ocornut commented May 8, 2020

I don't think you should be attempting to implement manual tabbing, rather we should add tabbing support to the Navigation code. But also we should make it easier to hook various elements of Navigation for custom purpose, so that should still be possible ideally...

ocornut added a commit that referenced this issue Sep 29, 2021
ocornut added a commit that referenced this issue Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus nav keyboard/gamepad navigation scrolling
Projects
None yet
Development

No branches or pull requests

2 participants