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

Custom Escape key handling in Input functions #5688

Closed
s9w opened this issue Sep 16, 2022 · 3 comments
Closed

Custom Escape key handling in Input functions #5688

s9w opened this issue Sep 16, 2022 · 3 comments

Comments

@s9w
Copy link

s9w commented Sep 16, 2022

Version/Branch of Dear ImGui:

Version: v1.88
Branch: master

My Issue/Question:

In any input widget, pressing the escape key currently has a hard-wired behavior: It removes the last-added portion of the text. It's debatable if that behavior is correct - other programs usually delete the entire input. However the greater problem is that this behavior can neither be changed nor disabled. It's not altered by ImGuiWindowFlags_NoNavInputs for example, but rather fixed behavior in imgui_widgets.cpp.

This makes it impracticable to use the escape key for more advanced logic. For example I was planning to delete the current selected input if it's not empty, and go back to a menu window otherwise. But this collides with imgui's own logic that clears an input field - but only if it's the first input - a nightmare to reverse-engineer and couteract.

I would welcome any way to mitigate this - could be hiding this behind a flag or whatever.

@ocornut
Copy link
Owner

ocornut commented Sep 16, 2022

I am currently working on a larger feature which will allow this.

@ocornut ocornut changed the title escape key handling in input functions Custom Escape key handling in Input functions Sep 16, 2022
@ocornut ocornut added the inputs label Sep 16, 2022
@ocornut
Copy link
Owner

ocornut commented Sep 20, 2022

I am currently working on a larger feature which will allow this.

While I'm working on a generic system for routing and owning keys and shortcut, I also realize the behavior your mention is fairly common, so I also added it as a dedicated flag: ImGuiInputTextFlags_EscapeClearsAll. (commit 3036dec)

It clears inputs if not empty otherwise deactivate the widget.

@s9w
Copy link
Author

s9w commented Sep 21, 2022

Hey that solves my use case, thanks a lot!

@s9w s9w closed this as completed Sep 21, 2022
ocornut added a commit that referenced this issue Jun 21, 2023
ocornut added a commit that referenced this issue Jul 6, 2023
…sion is taken on input buffer + Showcase a few more InputText() flags. (#5688, #2620)

This makes is more obvious that value_change==true when apply_new_text != NULL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants