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

Defocus text input? #5897

Closed
invrainbow opened this issue Nov 20, 2022 · 1 comment
Closed

Defocus text input? #5897

invrainbow opened this issue Nov 20, 2022 · 1 comment

Comments

@invrainbow
Copy link

invrainbow commented Nov 20, 2022

I apologize if this is basic or has been answered, but I searched around imgui.h and couldn't find the answer.

Is there a way to defocus a text input? SetKeyboardFocusHere focuses the input, is it possible to do the opposite?

Edit: I just saw #5611. Unfortunately, in my case I can't just defocus the whole window as I really am trying to just defocus the input. The aforementioned issue mentions SetNavID(0) but the actual signature of SetNavID() has several more parameters, and it's not clear from the example calls in imgui_widgets.cpp how this is done. Any advice here would be greatly appreciated.

Edit 2: I tried SetNavID(0, GImGui->NavLayer, 0, ImRect()) and it didn't do anything.

Edit 3: I tried

ImGui::SetWindowFocus(NULL); // unfocus window to clear keyboard focus
ImGui::SetWindowFocus(); // refocus window

and although it appears to work, it seems awkward and implicit (is it well defined that unfocusing the window reliably clears keyboard focus?). Would still love a better way.

Edit 4: Okay, last edit. I dug around what SetWindowFocus(NULL) was doing and guessed that ClearActiveID() would do the trick, which turned out to be correct.

@ocornut
Copy link
Owner

ocornut commented Nov 21, 2022

ClearActiveID() works.

Note that defocusing wouldn't constitute a validation, and features like #701 or issues like #4714 (finger crossed finishing the fix soon) there are different alternative ways you would want to "defocus text input": defocus and revert? defocus on leave as it, but if we add #701 does it means the current value is lost? defocus with explicit validation, etc. Future users may be mindful of those.

@ocornut ocornut closed this as completed Nov 21, 2022
@ocornut ocornut added the focus label Nov 21, 2022
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