mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-24 07:40:22 +01:00
DragFloat: Fixed a situation where dragging with value rounding enabled or with a power curve erroneously wrapped the value to one of the min/max edge. (#2024, #708, #320, #2075).
This commit is contained in:
parent
e2436ca625
commit
af6cf25255
@ -41,6 +41,8 @@ Other Changes:
|
|||||||
accidental alteration of window position. We now round the provided size. (#2067)
|
accidental alteration of window position. We now round the provided size. (#2067)
|
||||||
- Nav, Focus: Fixed ImGuiWindowFlags_NoBringToFrontOnFocus windows not being restoring focus
|
- Nav, Focus: Fixed ImGuiWindowFlags_NoBringToFrontOnFocus windows not being restoring focus
|
||||||
properly after the main menu bar or last focused window is deactivated.
|
properly after the main menu bar or last focused window is deactivated.
|
||||||
|
- DragFloat: Fixed a situation where dragging with value rounding enabled or with a power curve
|
||||||
|
erroneously wrapped the value to one of the min/max edge. (#2024, #708, #320, #2075).
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
|
@ -1708,9 +1708,10 @@ template<typename TYPE, typename SIGNEDTYPE, typename FLOATTYPE>
|
|||||||
bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const TYPE v_min, const TYPE v_max, const char* format, float power)
|
bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const TYPE v_min, const TYPE v_max, const char* format, float power)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
const bool is_decimal = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);
|
||||||
|
const bool has_min_max = (v_min != v_max) && (v_max - v_max < FLT_MAX);
|
||||||
|
|
||||||
// Default tweak speed
|
// Default tweak speed
|
||||||
bool has_min_max = (v_min != v_max) && (v_max - v_max < FLT_MAX);
|
|
||||||
if (v_speed == 0.0f && has_min_max)
|
if (v_speed == 0.0f && has_min_max)
|
||||||
v_speed = (float)((v_max - v_min) * g.DragSpeedDefaultRatio);
|
v_speed = (float)((v_max - v_min) * g.DragSpeedDefaultRatio);
|
||||||
|
|
||||||
@ -1720,14 +1721,14 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
|||||||
{
|
{
|
||||||
adjust_delta = g.IO.MouseDelta.x;
|
adjust_delta = g.IO.MouseDelta.x;
|
||||||
if (g.IO.KeyAlt)
|
if (g.IO.KeyAlt)
|
||||||
adjust_delta *= 1.0f/100.0f;
|
adjust_delta *= 1.0f / 100.0f;
|
||||||
if (g.IO.KeyShift)
|
if (g.IO.KeyShift)
|
||||||
adjust_delta *= 10.0f;
|
adjust_delta *= 10.0f;
|
||||||
}
|
}
|
||||||
else if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
else if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
||||||
{
|
{
|
||||||
int decimal_precision = (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImParseFormatPrecision(format, 3) : 0;
|
int decimal_precision = is_decimal ? ImParseFormatPrecision(format, 3) : 0;
|
||||||
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
|
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f / 10.0f, 10.0f).x;
|
||||||
v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
|
v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
|
||||||
}
|
}
|
||||||
adjust_delta *= v_speed;
|
adjust_delta *= v_speed;
|
||||||
@ -1753,7 +1754,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
|||||||
TYPE v_cur = *v;
|
TYPE v_cur = *v;
|
||||||
FLOATTYPE v_old_ref_for_accum_remainder = (FLOATTYPE)0.0f;
|
FLOATTYPE v_old_ref_for_accum_remainder = (FLOATTYPE)0.0f;
|
||||||
|
|
||||||
const bool is_power = (power != 1.0f && (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) && has_min_max);
|
const bool is_power = (power != 1.0f && is_decimal && has_min_max);
|
||||||
if (is_power)
|
if (is_power)
|
||||||
{
|
{
|
||||||
// Offset + round to user desired precision, with a curve on the v_min..v_max range to get more precision on one side of the range
|
// Offset + round to user desired precision, with a curve on the v_min..v_max range to get more precision on one side of the range
|
||||||
@ -1786,12 +1787,12 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
|||||||
if (v_cur == (TYPE)-0)
|
if (v_cur == (TYPE)-0)
|
||||||
v_cur = (TYPE)0;
|
v_cur = (TYPE)0;
|
||||||
|
|
||||||
// Clamp values (handle overflow/wrap-around)
|
// Clamp values (+ handle overflow/wrap-around for integer types)
|
||||||
if (*v != v_cur && has_min_max)
|
if (*v != v_cur && has_min_max)
|
||||||
{
|
{
|
||||||
if (v_cur < v_min || (v_cur > *v && adjust_delta < 0.0f))
|
if (v_cur < v_min || (v_cur > *v && adjust_delta < 0.0f && !is_decimal))
|
||||||
v_cur = v_min;
|
v_cur = v_min;
|
||||||
if (v_cur > v_max || (v_cur < *v && adjust_delta > 0.0f))
|
if (v_cur > v_max || (v_cur < *v && adjust_delta > 0.0f && !is_decimal))
|
||||||
v_cur = v_max;
|
v_cur = v_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user