Repository navigation
Description
Version/Branch of Dear ImGui:
v1.92.2b-docking (1f7f1f5)
Back-ends:
probably all, but tested with win32_directx9
Compiler, OS:
probably all, but using Windows 10 (Version 22H2 (OS Build 19045.6216)) and VS2022 (Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35215 for x64)
Full config/build information:
Dear ImGui 1.92.2b (19222)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1944
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx9
io.ConfigFlags: 0x00000483
NavEnableKeyboard
NavEnableGamepad
DockingEnable
ViewportsEnable
io.ConfigDpiScaleFonts
io.ConfigDpiScaleViewports
io.ConfigViewportsNoDecoration
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C1F
HasGamepad
HasMouseCursors
HasSetMousePos
PlatformHasViewports
HasMouseHoveredViewport
RendererHasVtxOffset
RendererHasTextures
RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
io.Fonts->FontLoaderName: stb_truetype
io.DisplaySize: 1264.00,761.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00Details:
I'm trying to make InputInt work when there's no direct access to the actual value - just by-value getters/setters. (It'd be inconvenient to change this.)
The code I'd expect to be able to use would be along these lines:
int tmp=GetValue();
if(ImGui::InputInt("label",&tmp)) {
if(ImGui::IsItemDeactivatedAfterEdit()) {
SetValue(tmp);
}
}
And this does work somewhat ok, in that SetValue is called for pressing Return, but not for intermediate edits, as desired - but, after pressing Escape, IsItemDeactivatedAfterEdit( returns true (which is fine), and tmp is the edited value rather than the original one (which is a bit surprising).
I don't mind if SetValue gets called again with the original value, because the setter can always check and do nothing if it's the same value. But it feels odd that pressing Escape doesn't undo the edits! The behaviour of the input int widget in the Widgets/Basic/InputText section of the demo is much more as I'd expect: Return accepts the edited value, and Escape reverts its it to the pre-edit value. It operates directly on a static int though which isn't appropriate in this case.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
You can clone my test code from a branch of my fork:
git clone https://github.com/tom-seddon/imgui
cd imgui
git checkout tom/InputInt_problem
The changes are to imgui_demo.cpp (diff here: tom-seddon@b6273fe) - so it should hopefully apply to any example with any backends with any OS/compiler combination, but I've been building and running example_win32_directx9 from the VS2022 IDE on Windows 10 (exact versions as above)
Repro steps:
- Build and run demo
- Expand the
Widgets/Basicsection in the demo. There should be a row labelledinput int (2)visible - this is the test I've added - Click on the
input introw, current value 123. Type in124and press Return. The value changes to 124 - Click on the
input introw, current value 124. Type in125and press Escape. The value changes back to 124 - Click on the
input int (2)row, current value 124. Type in125and press Return. The value changes to 125 - Click on the
input int (2)row, current value 125. Type in126and press Escape. The value changes to 126 rather than reverting to 125
Activity
ocornut commentedon Sep 4, 2025
Thanks for your report.
FYI you don't need to put effort making a patch for such a simple repro (this is more work for you but actually also for me)
The repro is simply the block I can paste anywhere to confirm and test the issue:
ocornut commentedon Sep 4, 2025
It is caused by this block:
The compare is done on the input buffer rather that the edit buffer, therefore the buffers matches and the value is not applied.
Interestingly that check has been here since the dawn of time, but it didn't trigger the bug until 1.91.7 because of 00f12b9 (#8273)
InputText, InputInt, InputFloat: fixed an issue where using Escape to…
InputText: fixed an issue where using Escape with ImGuiInputTextFlags…
ocornut commentedon Sep 4, 2025
ImGuiInputTextFlags_EscapeClearsAllThis seems to pass all tests and is consistent with the fact that we don't use/rely on
bufinInputTextEx()for most operations.tom-seddon commentedon Sep 4, 2025
Now running with a959617 in my project and it's working nicely. Thanks ever so much for the quick turnaround.
InputTextMultiline: fixed an issue where edit buffer wouldn't be reap…
Added ImGuiItemFlags_LiveEdit flag, and much-awaited support for disa…
Split ImGuiItemFlags_LiveEdit into ImGuiItemFlags_LiveEditText, ImGui…
InputText, InputInt, InputFloat: fixed an issue where using Escape to…
InputText: fixed an issue where using Escape with ImGuiInputTextFlags…