ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.45k stars 10.34k forks source link

DragFloat: incorrect work of clamp value, when we set it by ctrl+click #7524

Closed DimaKoltun closed 7 months ago

DimaKoltun commented 7 months ago

Version/Branch of Dear ImGui:

Version 1.89, Branch: docking

Back-ends:

imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Windows 10 + MSVC 2022

Full config/build information:

Dear ImGui 1.89 WIP (18823)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1939
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_sdl
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000441
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.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.00

Details:

My Issue/Question:

When i set large value in DragFloat with limits due ctrl+click then incorrect value is set.

Screenshots/Video:

2024-04-23 14-21-40

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("Example Bug");
static float s_value = 1.0f;
ImGui::DragFloat("Test min/max", &s_value, 1.0f, 0.001f, std::numeric_limits<float>::max(), "%.3f", ImGuiSliderFlags_AlwaysClamp);
ImGui::End();
ocornut commented 7 months ago

Any integer larger than +/-16777216 cannot be reliably represented as a floating point value.

e.g. https://www.omnicalculator.com/other/floating-point

9999999 is ok 99999999 will be stored as 100000000 999999999 will be stored as 1000000000 9999999999 will be stored as 10000000000 99999999999 will be stored as 99999997952 999999999999 will be stored as 999999995904 etc.

If you need greater precision you may want to use a double with DragScalar(), or an integer.