Drags, Sliders: fixed an overflow using ImGuiSliderFlags_Logarithmic with S32/S64 types. (#9526, #3361, #1823, #1316, #642)

This commit is contained in:
ocornut
2026-08-30 19:44:15 +02:00
parent 1e51b6ffdc
commit d3c5ff395c
2 changed files with 5 additions and 2 deletions

View File

@@ -3006,7 +3006,7 @@ float ImGui::ScaleRatioFromValueT(ImGuiDataType data_type, TYPE v, TYPE v_min, T
result = 0.0f; // Workaround for values that are in-range but below our fudge
else if (v_clamped >= v_max_fudged)
result = 1.0f; // Workaround for values that are in-range but above our fudge
else if ((v_min * v_max) < 0.0f) // Range crosses zero, so split into two portions
else if (((FLOATTYPE)v_min * (FLOATTYPE)v_max) < 0.0f) // Range crosses zero, so split into two portions
{
float zero_point_center = (-(float)v_min) / ((float)v_max - (float)v_min); // The zero point in parametric space. There's an argument we should take the logarithmic nature into account when calculating this, but for now this should do (and the most common case of a symmetrical range works fine)
float zero_point_snap_L = zero_point_center - zero_deadzone_halfsize;
@@ -3060,7 +3060,7 @@ TYPE ImGui::ScaleValueFromRatioT(ImGuiDataType data_type, float t, TYPE v_min, T
float t_with_flip = flipped ? (1.0f - t) : t; // t, but flipped if necessary to account for us flipping the range
if ((v_min * v_max) < 0.0f) // Range crosses zero, so we have to do this in two parts
if (((FLOATTYPE)v_min * (FLOATTYPE)v_max) < 0.0f) // Range crosses zero, so we have to do this in two parts
{
float zero_point_center = (-(float)ImMin(v_min, v_max)) / ImAbs((float)v_max - (float)v_min); // The zero point in parametric space
float zero_point_snap_L = zero_point_center - zero_deadzone_halfsize;