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

Simple way to scroll to a widget and give it keyboard focus? #2021

Closed
kavika13 opened this issue Aug 14, 2018 · 5 comments
Closed

Simple way to scroll to a widget and give it keyboard focus? #2021

kavika13 opened this issue Aug 14, 2018 · 5 comments
Labels
nav keyboard/gamepad navigation

Comments

@kavika13
Copy link

kavika13 commented Aug 14, 2018

v1.53 (can't easily update right now, in case this is easier in a newer version)

Is there a simple way to scroll to a widget and give it keyboard focus? Right now it seems like I need to jump through some hoops to get it to work right.

The only way I've gotten it to work right:

  • Frame 0+: Display widget (...wait for external impulse that triggers set-focus logic)
  • Frame 1: Display widget
  • Frame 1: SetScrollHere
  • Frame 2: SetKeyboardFocusHere
  • Frame 2: Display widget
  • Frame 3+: Display widget

If I call SetKeyboardFocusHere without calling SetScrollHere first, then it does nothing, unless I already have the window scrolled to the right place.

If I call SetScrollHere then immediately call SetKeyboardFocusHere, either immediately before or immediately after the widget call, then the wrong thing gets focused.

In my experiments, it also seems like SetScrollHere and SetKeyboardFocusHere have different concepts of "here", and the order they need to be invoked (list at the top) makes it pretty hard to use.

Please let me know if you want a minimal repro to accompany this, or if it is already clear enough.

@ocornut ocornut added the nav keyboard/gamepad navigation label Aug 14, 2018
@ocornut
Copy link
Owner

ocornut commented Aug 14, 2018

Hello,

No need for a repro, it's a known issue (see e.g. #343) and I am aware of the inconsistency with the "Here" concept :(

A while ago I started a work-in-progress branch to ditch SetKeyboardFocusHere() and replace it with a couple of new helpers, along with reworking the entire Tabbing code which is severely outdated, but I couldn't finish the work and had to move to other tasks. There were a few unsolved issues back then, but I'll like to get back to it - those functions are known to be problematic.

I think a workaround you may use to get SetKeyboardFocusHere() to register is to manually set g.ActiveId = to the ID of the item if you are able to obtain it, this will disable clipping.

Note that 1.60+ has SetItemDefaultFocus() which would perhaps do what you need on an Appearing windows.

-Omar

@kavika13
Copy link
Author

kavika13 commented Aug 14, 2018

I have successfully worked around this challenge in my code already, by just having some global variable I set temporarily after the impulse is detected, and clear on the next frame.

I wanted to file this ticket as sort of a "feature request" to make this simpler in some way. Maybe SetItemDefaultFocus() already covers it?

My use case is changing the control that has focus, depending on some outside input. In my case, it is selecting one of the several widgets in my 3D scene that will cause the corresponding field in the 2D UI to gain focus. The window probably will already be open when I want this focus change to happen.

image

@ocornut
Copy link
Owner

ocornut commented Aug 14, 2018

SetItemDefaultFocus() won't cover your use case at it is designed for the window appearing frame.

The future/intended new API FocusItem and ActivateItem are aimed at solving this properly.

@kavika13
Copy link
Author

Should I close this ticket then, since it is sort of a dupe/there's planned features for this already?

@ocornut
Copy link
Owner

ocornut commented Aug 15, 2018

Closing! Thanks for the reminder that this needs to be sorted out :)

@ocornut ocornut closed this as completed Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nav keyboard/gamepad navigation
Projects
None yet
Development

No branches or pull requests

2 participants