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

Keyboard / Controller Support? #323

Closed
velvitonator opened this issue Sep 9, 2015 · 34 comments
Closed

Keyboard / Controller Support? #323

velvitonator opened this issue Sep 9, 2015 · 34 comments
Labels
enhancement nav keyboard/gamepad navigation

Comments

@velvitonator
Copy link

velvitonator commented Sep 9, 2015

(ADMIN EDIT July 2016: see #323 (comment) for the current todo list / ongoing tasks)

I've been looking to make our ImGUI accept controller input, for use on consoles. Something like hitting d-pad down to select the next item down, etc.

From what I could tell, however, the only way to do such a thing would be to spoof mouse control. Is this the case? If so, is there a way to ask for the rectangle of a given item outside of the update loop?

I also couldn't find any way to programmatically set the focus of an item other than input text fields; did I miss something?

@ocornut ocornut changed the title Controller Support? Keyboard / Controller Support? Sep 9, 2015
@ocornut
Copy link
Owner

ocornut commented Sep 9, 2015

Before anything else, have you looked into using a system like Synergy + usynergy.c to have your game console use your PC mouse/keyboard ? I'd wholly recommend that.

If so, is there a way to ask for the rectangle of a given item outside of the update loop?

Not sure what you mean by "the update loop" nor why you would need that if you are spoofing mouse control? If you are going to spoof mouse control just make your controller adjust the MousePos and MouseDown (buttons) values.

You can call GetItemRectMin() / GetItemRectMax() to obtain the bounding rectangle of the last item (which might be clipped and outside of view, testable with IsItemVisible()) but I don't see how that would help here.

I also couldn't find any way to programmatically set the focus of an item other than input text fields; did I miss something?

No it's not available yet, there's no generalized concept of focus in fact.

Now if you really want controller support. There's different way we can approach this:

  • Emulating mouse with game controller (or keyboard) would be easy to implement and functional immediately. Obviously it'd be rather awkward and underwhelming interaction-wise, but for casual use it may be enough.
  • If you only want this for simple sort of UI like list of items you can emulate the concept of "whats focused" on user side and handle interaction yourself (e.g. Button X pressed while Item N is selected).
  • The correct thing would be to fully handle keyboard/controller navigation and per-widget focus. It's not a simple feature, probably a bunch of work to get it right (I'd say 1 week optimistically). It is a very desirable feature but I don't know when / if I'll ever be able to do it.

I have rename your topic to keyboard/controller because the problems are the same for keyboard controls and many people are likely to come from the angle of desiring keyboard control.

@velvitonator
Copy link
Author

Before anything else, have you looked into using a system like Synergy + usynergy.c to have your game console use your PC mouse/keyboard ? I'd wholly recommend that.

Yeah, we've got this up and running (except for keyboard support, since I've yet to hook up the manual character-input stuff). We want to add controller as a good native option, so users don't have to switch input devices.

Not sure what you mean by "the update loop" nor why you would need that if you are spoofing mouse control? If you are going to spoof mouse control just make your controller adjust the MousePos and MouseDown (buttons) values.

Apologies; I meant that we could do something like move the mouse down "an item" instead, but that starts to get a bit complicated for client code, especially since we'd need this to be something for everyone to use, to make their own debug GUIs. With that approach, we'd need the screen-rect of the options etc.
This is all certainly possible for us to do, it's just a matter of the effort we want to expend on it. Hence, I'm hoping to clarify the available options before embarking on something time-consuming. =)

Emulating mouse with game controller (or keyboard) would be easy to implement and functional immediately. Obviously it'd be rather awkward and underwhelming interaction-wise, but for casual use it may be enough.

Yeah, this is looking to be the only option in the timeframe we're looking at. Since we also have Synergy, I'm not convinced adding this is worth it; I know I'd easily switch to mouse + keys as soon as I had to, rather than bear analog-stick mouse cursor!

If you only want this for simple sort of UI like list of items you can emulate the concept of "whats focused" on user side and handle interaction yourself (e.g. Button X pressed while Item N is selected).

Certainly! But getting it to reflect in the UI is the tricky bit =/
Also, we already have a couple of in-game debug UIs using ImGUI, and they have quite a bit of variety. =P

The correct thing would be to fully handle keyboard/controller navigation and per-widget focus. It's not a simple feature, probably a bunch of work to get it right (I'd say 1 week optimistically). It is a very desirable feature but I don't know when / if I'll ever be able to do it.

Hmm, I'll be honest: I'm so accustomed to working with closed-source things that simply adding the feature to ImGUI didn't occur to me. I think it's a little out of scope for the timeframe I have, but it's certainly worth considering in the longer term, should we find that controller support is indispensable for whatever reason.

I have rename your topic to keyboard/controller because the problems are the same for keyboard controls and many people are likely to come from the angle of desiring keyboard control.

Good idea!

@ocornut
Copy link
Owner

ocornut commented Sep 9, 2015

Apologies; I meant that we could do something like move the mouse down "an item" instead, but that starts to get a bit complicated for client code, especially since we'd need this to be something for everyone to use,

It's trivial to store the rectangle of the hovered item (we can add that to the library), so you could move the cursor outside of it but you wouldn't know by how much as you don't know where the next item. An hybrid approach to move outward the item by the amount of its width/height and then move smoothly if there's no item under the cursor. It would be easy to implement and may be a little better than a cursor but probably still mediocre. If you are on PS4, I haven't tried it but I suspect the touch pad is precise enough to emulate a mouse.

Hmm, I'll be honest: I'm so accustomed to working with closed-source things that simply adding the feature to ImGUI didn't occur to me. I think it's a little out of scope for the timeframe I have, but it's certainly worth considering in the longer term, should we find that controller support is indispensable for whatever reason.

FYI if your project/company has the fund I'm more than happy to provide custom work on imgui to develop that sort of non-trivial feature (been looking for possible ways to fund its development as I can't really afford it any more myself, at least not at the pace I was working on it a few months ago). Something to consider, may be more optimal than you doing it and it'll benefit the sustainability of the library.

It's one of the those feature that's touching quite a lot of elements in the code - quite a complex feature to do right. If you to want to tackle it yourself I can also guide you.

@velvitonator
Copy link
Author

Sorry for the silence; I forgot the re-mark the mail as unread to get back to it.

Your idea to use the PS4 touchpad was pretty effective--it's somewhat finicky, but much better than a stick, and it wasn't too difficult to hook up the sticks and pad for scrolling, either.

So, we're good for now; thanks for the suggestion!

@ocornut
Copy link
Owner

ocornut commented Jun 11, 2016

I don't have an ETA yet but I've been working on this lately.
When it starts to be semi usable I will push it to a public branch, right now it is way too prototypey.

navigation_v0b

@ocornut
Copy link
Owner

ocornut commented Jun 12, 2016

Some progress report, been improving support for the popup stack, combos, menus, sliders, visualizing selection, avoiding confusion between keyboard and mouse, etc.
There's still a billion things to do, it is a little overwhelming.

navigation_v1

@Pagghiu
Copy link
Contributor

Pagghiu commented Jun 13, 2016

This is VERY interesting 😁

@MrMarkie
Copy link

MrMarkie commented Jul 1, 2016

This looks great. We'd like to use it for interaction with debug UI in PSVR. It's exactly the kind of thing we need for this. When are you looking to make it available?

@ocornut
Copy link
Owner

ocornut commented Jul 1, 2016

When it is done @MrMarkie :) I've been working on my non-existent spare time until now, but because this feature is now sponsored (a first) I'm aiming before end of July. Will probably start testing and iterating on API and edge cases mid-july.

@MrMarkie
Copy link

Hi. Is there any news on this feature? I'd be happy to help test it if you have a preview version

@ocornut
Copy link
Owner

ocornut commented Jul 15, 2016

I was thinking about pushing a branch but the IO api is utterly temporary/broken yet and it's still missing important features. I'll work on it this week-end. From Monday if you're happy with experimenting with it (at the cost of minor breakage in the following weeks) it would be indeed quite helpful if you want to try it and submit feedback. You can also e-mail me if you want to move this off-line for back and forth.

@MrMarkie
Copy link

Absolutely. Let me know when / where I can get it. Look forwards to trying it out.
Markie
On 15 Jul 2016 17:35, omar [email protected] wrote:I was thinking about pushing a branch but the IO api is utterly temporary/broken yet and it's still missing important features. I'll work on it this week-end. From Monday if you're happy with experimenting with it (at the cost of minor breakage in the following weeks) it would be indeed quite helpful if you want to try it and submit feedback. You can also e-mail me if you want to move this off-line for back and forth.

—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.

ocornut added a commit that referenced this issue Jul 18, 2016
…w lower in the function so that Nav branch can use CursorStartPos on the first window frame. (#323)

Pushing in master because it _should_ be a no-op but I'd rather test for any issue in Begin() as soon as possible.
@ocornut
Copy link
Owner

ocornut commented Jul 19, 2016

Quick update GIF
navigation_v2

I'm not finished but I'll be pushing first test version to a branch tonight, along with instructions for those interested.

@MrMarkie
Copy link

This looks excellent!!
On 19 Jul 2016 22:28, omar [email protected] wrote:Quick update GIF

I'm not finished but I'll be pushing first test version to a branch tonight, along with instructions for those interested.

—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.

ocornut added a commit that referenced this issue Jul 19, 2016
…e value already stored within the CurrentPopupStack in the previous frame. Doesn't make a big difference here, but will do as gamepad/keyboard navigation will set its own popup position. (#323)
ocornut added a commit that referenced this issue Jul 19, 2016
…in upcoming nav commits. Testing power==1.0f without fabsf(). Maybe just use == 1.0f as well? (#323)
ocornut added a commit that referenced this issue Jul 19, 2016
…stly a workaround to that activation with enter doesn't validate immediately, which is turns triggers an assert in InputScalarAsWidgetReplacement - can't see an issue with changing it this way so trying out) + using local flag clear_active_id to only clear the active id at the end of the frame, which is one of the step that my stash for #701 requires. (#323)
ocornut added a commit that referenced this issue Jul 19, 2016
…ve no side-effects! (So that later we can update Nav between Keyboard and Mouse) (#323)
ocornut added a commit that referenced this issue Jul 19, 2016
ocornut added a commit that referenced this issue Aug 20, 2016
ocornut added a commit that referenced this issue Aug 20, 2016
ocornut added a commit that referenced this issue Aug 20, 2016
ocornut added a commit that referenced this issue Aug 20, 2016
…ouseDown[] so that invalid mouse button won't keep breaking nav (#323)
ocornut added a commit that referenced this issue Aug 21, 2016
…at seems to be Windows beahvior at least for menus (#323)
ocornut added a commit that referenced this issue Aug 21, 2016
… popup/tooltip positioning when using mouse+nav (#323)
ocornut added a commit that referenced this issue Aug 21, 2016
ocornut added a commit that referenced this issue Aug 21, 2016
…Consistent with expectation & will be used as fallback for nav (#323)
ocornut added a commit that referenced this issue Aug 21, 2016
ocornut added a commit that referenced this issue Aug 21, 2016
ocornut added a commit that referenced this issue Aug 21, 2016
@ocornut
Copy link
Owner

ocornut commented Aug 21, 2016

MOVING TO #787

@ocornut ocornut closed this as completed Aug 21, 2016
@ocornut ocornut added the nav keyboard/gamepad navigation label Jun 2, 2017
ocornut added a commit that referenced this issue Aug 29, 2017
f71cdd1  Internal tidying up, moved code to CalcNextScrollFromScrollTargetAndClamp() so it can be reused by upcoming nav code.
c816e6c Fixed SetScrollX() handling of center ratio (which actually wasn't exposed publicly). (#323, #246)
ocornut added a commit that referenced this issue Sep 18, 2017
…les (#323)

Missing support Vulkan (#549), Apple (#575, #247), SDL (#58, #356),
Allegro, Marmalade (#368, #375)
ocornut added a commit that referenced this issue Oct 4, 2017
…e MouseDelta test (added in 43ee5d7, #323) as I don't think it is needed. (#787)
ocornut added a commit that referenced this issue Jul 25, 2022
…ding config flags (#5504). Fixes 8b8a61b. #4921, #4858, #787, #1599, #323)

NavUpdate() can now clears ImGuiInputSource_None.
kjblanchard pushed a commit to kjblanchard/imgui that referenced this issue May 5, 2023
ocornut added a commit that referenced this issue Jul 25, 2024
… two years ago. (#4921, #4858, #787, #1599, #323)

Use SetKeyOwner(ImGuiKey_Escape, g.ActiveId); instead. Amend 8b8a61b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement nav keyboard/gamepad navigation
Projects
None yet
Development

No branches or pull requests

7 participants