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

Pressing Space in an InputText causes a Enter press (and enter press makes page go back to previous page) #11

Closed
tobiazsh opened this issue Oct 11, 2024 · 4 comments

Comments

@tobiazsh
Copy link

tobiazsh commented Oct 11, 2024

When pressing space or enter on the keyboard in ImGui, the page jumps back once although it shouldn't. This is especially annoying in ImGui.inputText's since I cannot press space without it going back.

Example code;

ImGui.begin("Test");

ImGui.inputText(String, ImString);

ImGui.end();

This issue has already been addressed in the official ImGui repo and marked as fixed but I do not know how to implement their fix in java.

ocornut/imgui#4552

I see that InputTextFlags.EnterReturnsTrue has been added but that does the exact opposite of what I want to see.

If anyone could help me on this one, that'd be great! Thanks!

@FlorianMichael
Copy link
Owner

You will probably have to wait for ImGui-Java to update their included imgui version to get the fix as well

@tobiazsh
Copy link
Author

I mean, the version should already be the one with the fix, or at least it says that on the about menu. Funny enough, it works just fine in the about window.

@tobiazsh
Copy link
Author

ImGui was not at fault. So, what basically happend is that the button in the background from the Minecraft GUI that opens the ImGui GUI was still focused and whenever you pressed Enter or Space, it got pressed and the ImGui Window opened again thus going back to the first window. I noticed this when I tried if the same thing happens in an actual Minecraft Instance instead of the development environment (where I had sounds turned off) and I heard the typical Minecraft button "click" sound. By then, I knew something was off and I checked the code. Turns out just removing all the children from the Minecraft Screen was not enough and I also had to defocus any focused element to prevent it from being clicked. I've done this by just re-drawing everything so it loses focus and then removing the children. screen.blur(); was not enough apparently.

TL;DR:
ImGui works fine. Minecraft button was still focused, whenever space or enter was pressed, it activated. By re-drawing everything, it loses focus and then works fine.

@FlorianMichael
Copy link
Owner

Oh I see, I was already confused but that makes sense, thanks for clarification and sorry for the long response times.

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

No branches or pull requests

2 participants