Skip to content

Commit 7475c1e

Browse files
committed
Data types: DragScalar: Fixed speed of integer values tweaking with keyboard/gamepad when speed < 1. Enforce min/max bounds when power curves are used. SliderScalar: Fixed integer/slow tweaking. (ocornut#643)
1 parent fc7fc83 commit 7475c1e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

CHANGELOG.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Breaking Changes:
5151
Other Changes:
5252
(IN PROGRESS, WILL ADD TO THIS LIST AS WE WORK ON 1.61)
5353

54+
- Added DragScalar, DragScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#643, #320, #708, #1011)
55+
- Added InputScalar, InputScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#643, #320, #708, #1011)
56+
- Added SliderScalar, SliderScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#643, #320, #708, #1011)
5457
- Window: Fixed default proportional item width lagging by one frame on resize.
5558
- Window: Fixed pop-ups/tooltips/menus not honoring style.DisplaySafeAreaPadding as well as it should have (part of menus displayed outside the safe area, etc.).
5659
- Window: Fixed windows using the ImGuiWindowFlags_NoSavedSettings flag from not using the same default position as other windows. (#1760)
@@ -66,9 +69,6 @@ Other Changes:
6669
- InputText: Fixed returning true when edition is canceled with ESC and the current buffer matches the initial value.
6770
- InputFloat,InputFloat2,InputFloat3,InputFloat4: Added variations taking a more flexible and consistent optional "const char* format" parameter instead of "int decimal_precision".
6871
This allow using custom formats to display values in scientific notation, and is generally more consistent with other API. Obsoleted functions using the optional "int decimal_precision" parameter. (#648)
69-
- Added DragScalar, DragScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#320, #643, #708, #1011)
70-
- Added InputScalar, InputScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#320, #643, #708, #1011)
71-
- Added SliderScalar, SliderScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#320, #643, #708, #1011)
7272
- DragFloat, DragInt: Cancel mouse tweak when current value is initially past the min/max boundaries and mouse is pushing in the same direction (keyboard/gamepad version already did this).
7373
- DragFloat, DragInt: Honor natural type limits (e.g. INT_MAX, FLT_MAX) instead of wrapping around. (#708, #320)
7474
- DragFloat, SliderFloat: Fixes to allow input of scientific notation numbers when using CTRL+Click to input the value. (~#648, #1011)

imgui.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -8891,8 +8891,8 @@ static bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType d
88918891
}
88928892
else
88938893
{
8894-
if (v_max - v_min <= 100.0f || v_max - v_min >= -100.0f || IsNavInputDown(ImGuiNavInput_TweakSlow))
8895-
delta = ((delta < 0.0f) ? -1.0f : +1.0f) / (float)(v_max - v_min); // Gamepad/keyboard tweak speeds in integer steps
8894+
if ((v_range >= -100.0f && v_range <= 100.0f) || IsNavInputDown(ImGuiNavInput_TweakSlow))
8895+
delta = ((delta < 0.0f) ? -1.0f : +1.0f) / (float)v_range; // Gamepad/keyboard tweak speeds in integer steps
88968896
else
88978897
delta /= 100.0f;
88988898
}
@@ -9257,7 +9257,7 @@ static bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed
92579257
}
92589258
if (g.ActiveIdSource == ImGuiInputSource_Nav)
92599259
{
9260-
int decimal_precision = ImParseFormatPrecision(format, 3);
9260+
int decimal_precision = (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImParseFormatPrecision(format, 3) : 0;
92619261
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
92629262
v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
92639263
}
@@ -9367,7 +9367,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
93679367
return false;
93689368

93699369
if (power != 1.0f)
9370-
IM_ASSERT(v_min != v_max); // When using a power curve the drag needs to have known bounds
9370+
IM_ASSERT(v_min != NULL && v_max != NULL); // When using a power curve the drag needs to have known bounds
93719371

93729372
ImGuiContext& g = *GImGui;
93739373
const ImGuiStyle& style = g.Style;

0 commit comments

Comments
 (0)