Repository navigation
Description
Version/Branch of Dear ImGui:
1.89.9
Back-ends:
imgui_impl_XXX.cpp + imgui_impl_XXX.cpp
Compiler, OS:
Windows 10, MSVC 2022
Full config/build information:
Dear ImGui 1.89.9 (18990)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1941
define: _MSVC_LANG=202002
--------------------------------
io.BackendPlatformName: NULL
io.BackendRendererName: NULL
io.ConfigFlags: 0x00000000
io.ConfigInputTextCursorBlink
io.ConfigWindowsMoveFromTitleBarOnly
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00000000
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1864.00,946.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 12.00,12.00
style.WindowBorderSize: 0.00
style.FramePadding: 20.00,3.40
style.FrameRounding: 11.90
style.FrameBorderSize: 0.00
style.ItemSpacing: 4.30,5.50
style.ItemInnerSpacing: 7.10,1.80
Details:
I can't get InputFloat3 to accept the value on Enter and loss of focus like I can with InputText. As far as I can tell, ImGui::IsItemDeactivatedAfterEdit() isn't working with InputFloat3(), or at least not when combined with ImGuiInputTextFlags_EnterReturnsTrue
I want InputFloat to behave by accepting the change on Enter (ImGuiInputTextFlags_EnterReturnsTrue) with a combination of keeping them when IsItemDeactivatedAfterEdit() to keep values when tabbing or clicking to another control. The following code-block works perfectly for InputText:
bool MyInputText(const String& label, String* value)
{
const bool pressedEnter = ImGui::InputText(label.c_str(), value, ImGuiInputTextFlags_EnterReturnsTrue);
if (true == pressedEnter)
{
ImGui::SetItemDefaultFocus();
}
return (true == pressedEnter || true == ImGui::IsItemDeactivatedAfterEdit());
}
However that doesn't work with the InputFloat3, my suspicion is this stems from there being 3 InputBoxes in the float3? Is there a way to get that same behavior, I think it might even help the value drift issue from #3936, but I have created a new ticket because they may be unrelated, no values are drifting in this instance for me. The following code allows the value to change on enter, but does not change the value if I change the focus to anything else, including tabbing from X to Y (internally with the Float3), or Z to another control (externally).
bool MyInputFloat3(const String& label, float values[3], const char* format, ImGuiInputTextFlags flags)
{
const bool pressedEnter = ImGui::InputFloat3(label.c_str(), values, format, flags | ImGuiInputTextFlags_EnterReturnsTrue);
if (true == pressedEnter)
{
ImGui::SetItemDefaultFocus();
}
const bool itemDeactivatedAfterEdit = ImGui::IsItemDeactivatedAfterEdit();
return (true == pressedEnter || true == itemDeactivatedAfterEdit);
}
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
bool MyInputFloat3(const String& label, float values[3], const char* format, ImGuiInputTextFlags flags)
{
const bool pressedEnter = ImGui::InputFloat3(label.c_str(), values, format, flags | ImGuiInputTextFlags_EnterReturnsTrue);
if (true == pressedEnter)
{
ImGui::SetItemDefaultFocus();
}
const bool itemDeactivatedAfterEdit = ImGui::IsItemDeactivatedAfterEdit();
return (true == pressedEnter || true == itemDeactivatedAfterEdit);
}
Activity
ocornut commentedon Oct 16, 2024
I'm currently noticing odd behavior with
InputFloat()andImGuiInputTextFlags_EnterReturnsTruewhere data is not written back to buffer anyhow, which is very problematic. It happens both on latest and 1.89.9.I am not entirely sure that
ImGuiInputTextFlags_EnterReturnsTrueever worked for InputFloat(), InputFloat3().However, may I ask why you need
ImGuiInputTextFlags_EnterReturnsTruesince without it thenIsItemDeactivatedAfterEdit()will cover it?timbeaudet commentedon Oct 16, 2024
ImGuiInputTextFlags_EnterReturnsTrueseems to be working forInputFloat3fwiw, and I need/want it because when the designer presses Enter after typing it feels natural for that to set the value and then Deactivate bySetItemDefaultFocus(). Perhaps there other ways to do it?, but this was the solution I stumbled on withInputTextthat felt that way I wanted.Also
IsItemDeactivatedAfterEdit()seems to be the majority of my issues rather thanImGuiInputTextFlags_EnterReturnsTrueso it's interesting you found opposite problems?ocornut commentedon Oct 16, 2024
But pressing enter will always deactivate either way.
And IsItemDeactivatedAfterEdit() will return true if pressing Enter after a change. So i don’t understand why you need ImGuiInputTextFlags_EnterReturnsTrue here.
_EnterReturnsTrue essentially breaks editing for those specific widgets. So its only natural that other signals would be broken.
timbeaudet commentedon Oct 17, 2024
Simply because I don't know all the ins and outs of the back end of ImGui perfectly. This was a solution that was doing as I desired, whether it was all necessary or not. I think I started with
_EnterReturnsTrueand found that wasn't quite everything I wanted, then later foundIsItemDeactivatedAfterEdit()and the combination worked; things are different when you have a full understanding of the ins/outs of the backend, which I do not.ocornut commentedon Oct 17, 2024
So:
_EnterReturnsTruewhich I will investigate.IsItemDeactivatedAfterEdit()(and NOT_EnterReturnsTrue) SHOULD resolve what you wanted? if not I am happy to talk about it.ocornut commentedon Oct 17, 2024
(
Unrelated to your issue, but note that
SetItemDefaultFocus()is roughly equivalent toif (IsWindowAppearing()) { SetKeyboardFocusHere(-1)aka it only does processing when the window appears, so I am not sure you used it correctly it, it seems like maybe you wanted to useSetKeyboardFocusHere(-1)which means "focus previous item".SetItemDefaultFocus() and SetKeyboardFocusHere() are amount of last remnant of some old API i will rework and improve. I agree they can be confusing.
I am not even sure it is possible to use
SetKeyboardFocusHere()to refocus the last focused sub-field of a 3-elements widget, because you currently cannot tell which one of the three was last focused.)
timbeaudet commentedon Oct 17, 2024
To be clear my usage of SetItemDefaultFocus() was intended to clear item focus, not necessarily got back to previous item. Perhaps I was still using it wrong.
I modified the code to the following (for both this and my InputText version) and it seems to behave exactly as I was trying to get working. Including on enter as you said; as far as my needs go this is a good solution!
ocornut commentedon Oct 17, 2024
Thanks for confirming. I will investigate the remaining bug now.
InputScalar: added an assert to clarify that ImGuiInputTextFlags_Ente…
ocornut commentedon Oct 17, 2024
I've looked into that and established that
ImGuiInputTextFlags_EnterReturnsTruenever ever worked with InputFloat/InputInt/InputScalar functions. I have added an assert to warn about it for now: 604f2fa.I tried to make it work, which led me to do a little bit of refactor of some systems 38617a5 used by
InputScalar(), but it would requires some extra awkward change to support it. At this point I believe _EnterReturnsTrue it almost never the right thing to use for that so I've decided to keep the assert for now.If someone comes up with a need for it the asserts tells them to open an issue.
Standalone test-bed:
{ const bool PressedEnter = ImGui::InputFloat("float1", &clear_color.x, 1.0f, 1.0f, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue); ImGui::Text("PressedEnter: %s / DeactivatedAfterEdit: %s", PressedEnter ? "XXXX" : "____", ImGui::IsItemDeactivatedAfterEdit() ? "XXXX" : "____"); } { const bool PressedEnter = ImGui::InputFloat3("float3", &clear_color.x, "%.3f", ImGuiInputTextFlags_EnterReturnsTrue); ImGui::Text("PressedEnter: %s / DeactivatedAfterEdit: %s", PressedEnter ? "XXXX" : "____", ImGui::IsItemDeactivatedAfterEdit() ? "XXXX" : "____"); }Remove all instances of EnterReturnsTrue flag on ImGui scalar inputs
Internals: store ImGuiItemStatusFlags_EditedInternal bypassing ImGuiI…
InputInt, InputFloat, InputScalar: reinstated and fixed ImGuiInputTex…
ocornut commentedon Apr 24, 2026
I have reinstated
ImGuiInputTextFlags_EnterReturnsTruefor InputInt, InputFloat, InputScalar etc.(final commit is the simple 10c378c but it depends on various other changes done previously).
And fixed various aspects of it:
Note:
IsItemDeactivatedAfterEdit()in most cases.Please open a new Issue if you have an issue with
ImGuiInputTextFlags_EnterReturnsTrue.AFAIK, the remaining issue with
IsItemDeactivatedAfterEdit()is: if intentionally NOT holding on backing data (aka always passing a temporary): the +/- buttons won't work because theIsItemDeactivatedAfterEdit()arrives one frame after writing-back. (#8149) If you think there is another issue withIsItemDeactivatedAfterEdit()please post a new issue 🙏Added ImGuiItemFlags_LiveEdit flag, and much-awaited support for disa…
Split ImGuiItemFlags_LiveEdit into ImGuiItemFlags_LiveEditText, ImGui…