-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
ImGuiInputTextFlags_EnterReturnsTrue discards value when losing focus #3946
Comments
Thank you, I can confirm this is failing because Out of curiosity, why using |
Probably broken by d3a387c which reworked the flow of marking a value as edited. |
My use case is as follows: I have a pair of integer values that the user can input, and an "Apply" button that triggers some (potentially lengthy) computation based on them. For the user's convenience, I thought it would be nice if they could click into the first edit field, type "1234 TAB 5678 ENTER", and it would automatically trigger the computation, like this:
|
I guess it depends how long the lengthy computation may be, but generally a common idiom is to use IsItemDeactivatedAfterEdit() which will react to tabbing out or unfocusing. But that will also react on pressing Enter or clicking out of the first field which may or not be desirable for you.
|
That's exactly the point, unfortunately ... it would be somewhat irritating if the computation already starts after only one of these values have been entered. I can only speak for myself, but I would be confused and annoyed if I wanted to change the parameter from 23,42 to 13,37, and was suddenly presented a result for 13,42 that I never wanted to have. |
The hope was that this would fix a bug (ocornut/imgui#3946), but this didn't turn out to be the case. But there's no reason not to update anyway.
Hello Friends, {
bool enter = ImGui::InputDouble(label, &edit, 0.01, 0.1, "%.4f", ImGuiInputTextFlags_EnterReturnsTrue);
if (enter || (ImGui::IsItemDeactivatedAfterEdit() && std::abs(edit - saved) > 0.0001))
{
saved = edit;
}
}
The desired behaviour is that the saved value must be set on Enter or on FocusOut. (I need to disable Live update) Thanks. |
Linking to #8065, where I realized (I had forgot and this was buried here) that But, reading this message from @kajott :
I realize this is an issue and my intuition was: hey, I'll mark this as something I would like to get solved soon. However @mnesarco I don't think your issue is the same. This works fine: static double saved = 0.0f;
static double edit = 0.0f;
ImGui::Text("Saved %f, Edit %f", saved, edit);
ImGui::InputDouble("blah", &edit, 0.01, 0.1);
if (ImGui::IsItemDeactivatedAfterEdit() && std::abs(edit - saved) > 0.0001)
saved = edit; And you don't need to use |
Hello @ocornut thank you for reviewing this. But my issue was in a project i was working 3 years ago, so i implemented some workaround or something back in time, now tbh i don't recall a piece of the code :D |
Version/Branch of Dear ImGui:
Version: 1.82
Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp
Compiler: Microsoft, _MSC_VER=1926, 64-bit
Operating System: Windows 10 2009
My Issue/Question:
When using
InputInt
/InputFloat
or the 2D/3D/4D versions thereof, theImGuiInputTextFlags_EnterReturnsTrue
flag has an unexpected side effect: Every time the input field loses focus, the changed value is discarded. Only pressing Enter makes a modification permanent. Using e.g. Tab to go to the next control and type in the next value means that the newly-entered data is lost in transit.InputText
is not affected by this.Standalone, minimal, complete and verifiable example:
Try entering a value and using Tab or the mouse to get to the other one. The value just entered will be reset to 0.
The text was updated successfully, but these errors were encountered: