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

Detecting if any text input is active #5177

Closed
goaaats opened this issue Apr 8, 2022 · 4 comments
Closed

Detecting if any text input is active #5177

goaaats opened this issue Apr 8, 2022 · 4 comments
Labels

Comments

@goaaats
Copy link

goaaats commented Apr 8, 2022

Version/Branch of Dear ImGui:
Version: 1.87
Branch: master

Back-end/Renderer/Compiler/OS
Back-ends: custom C# backend, but issue isn't backend related
Operating System: Linux

My Issue/Question:
I'm implementing an utility app that has users entering a lot of text - I'm planning to deploy this app on tablets and devices such as the Steam Deck, which have APIs that let developers bring up/position software keyboards when users start editing input boxes, and dismiss them when they go out of focus.

I have been looking for a way to implement this with ImGui without having to use internals - is there any chance of an official API? Is there a workaround I'm missing that doesn't require me adding special handling to all of my input boxes?

Something I tried was to use io.WantCaptureKeyboard, however, my app also depends on keyboard navigation, which will of course cause that to always return true.

Thank you!

Sample/example:

[...]
if (ImGui::GetIO().AnyTextInputActive && !lastFrameTextInputActive) {
	ShowSoftwareKeyboard()
[...]
@ocornut ocornut added the inputs label Apr 8, 2022
@ocornut
Copy link
Owner

ocornut commented Apr 8, 2022

Something I tried was to use io.WantCaptureKeyboard

The line right under io.WantCaptureKeyboard is:

bool  WantTextInput;  // Mobile/console: when set, you may display an on-screen keyboard. This is set by Dear ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active).

This also answered in the FAQ:
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-can-i-tell-whether-to-dispatch-mousekeyboard-to-dear-imgui-or-my-application

@goaaats
Copy link
Author

goaaats commented Apr 8, 2022

That works fine, apologies - somehow my IDE and Google must've failed me. Hope this gets indexed for whomever is looking for this in the future.

Thank you for your work!

@goaaats goaaats closed this as completed Apr 8, 2022
@ocornut
Copy link
Owner

ocornut commented Apr 8, 2022

No worries, good to have more indexing and redundancy.

I really wonder how featureful are other IDE. I use VS2019 and I can Alt+G my way (even from inside comments) to find symbols. I worry that some IDE may not be able to follow symbols mentioned in comments, or people are misusing them.

@PathogenDavid
Copy link
Contributor

I can Alt+G my way (even from inside comments) to find symbols

This is a Visual Assist thing, but for anyone using vanilla Visual Studio: Ctrl+T or Ctrl+Comma does something similar.

I worry that some IDE may not be able to follow symbols mentioned in comments, or people are misusing them.

As far as I know VSCode doesn't have a feature like this, so that's at least one that doesn't.

Ctrl+T kinda works in Rider (you have to select the whole symbol name first), I'd assume other JetBrains products like CLion to be similar.

I suspect even for IDEs which do have it, a lot of people don't know about it and use something like grep instead. (It definitely doesn't help that F12 doesn't work in comments for any IDE that I'm aware of.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants