-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Feature request - Intercept certain keypresses in text input fields? #68
Comments
👍 I have exactly the same problem trying to implement a console. |
I'll have to think how to handle that. To handle cursor-position based completion (and cursor preserving history) your code will need to have access to data such as cursor position, selection. Once InputText is able to expose those data into a small structure and read them back if modified then it could just call a callback and you can do what you want within it. So maybe the system doesn't need to be created with keystroke in mind in particular. Note that if you don't need the cursor position you could probably get away with just using a function that can tell you if the current widget has focus, and then run your code after. This function is currently missing in ImGui but trivial to implement so I could add that as a first step. What do you mean by "(Would be nice to have an ImGuiKey_Tab for this as well,)" ? |
Oh, I mean currently Tab is treated as a "text" character and wouldn't be intercepted by the code in InputText. But I suppose the "text input" loop could check for '\t' as well. |
Yes, however this is implemented it would have to work for TAB obviously. |
I am now working on implementing a nice console with those example as a test ground for adding the missing features. |
Yay! On Wed, Oct 29, 2014 at 5:19 AM, omar notifications@github.com wrote:
|
Not much progress on the actual requests (history/completion) but I have implemented a basic console (that doesn't have those features yet!). However toward doing this I already made a few others small changes/additions to the library. edit the example in included as part of the demo window. |
Coool! :D |
I have added the callback options now. ( It was messier than initially expected because the text input manipulates wchar internally and I wanted to provide UTF-8 to the user because that is what the user provides as input. With variable-size characters in UTF-8 have to convert thing like cursor-pos and selection range from character-to-byte and vice-versa, along with the text itself, and InputText() has a bunch of hoops already. I may want to clean that mess in the future. ) I have implemented a demo of completion in the console. I have not implemented history in the demo yet but the callback should be there (untested). The console demo app is 170 lines which is starting to be a little too much but that is due to the fancy completion scheme. It might be time to move sample code to a separate location? hmm? |
Closing this now. Will add a sample code for History using up/down later on but the feature is available. |
fyi - the Console example now handles history with Up/Down arrows along with a command "History. |
I was looking to make a sort of script console with ImGui but as it is the text input is pretty un-customizable. I'd like to be able to hit the up arrow to go through history (which I could manage myself, no need to put input history in ImGui) and use tab for autocompletion (again, I can handle that).
InputText looks for a bunch of specific keys with IsKeyPressedMap() and then delegates them to edit_state or the stb_textedit control. Obviously that's where the customized keys need to be intercepted. Maybe it could take a structure that holds two arrays, one that flags which keys have custom behavior, and one to put the state of the key in:
And then user code would check for a keypress after calling InputText and handle it appropriately. (Would be nice to have an ImGuiKey_Tab for this as well.)
I dunno, just a thought.
The text was updated successfully, but these errors were encountered: