@ -2060,8 +2060,6 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
TYPE v_cur = * v ;
FLOATTYPE v_old_ref_for_accum_remainder = ( FLOATTYPE ) 0.0f ;
IM_ASSERT ( ImGuiDragFlags_Logarithmic = = ImGuiSliderFlags_Logarithmic ) ;
float logarithmic_zero_epsilon = 0.0f ; // Only valid when is_logarithmic is true
const float zero_deadzone_halfsize = 0.0f ; // Drag widgets have no deadzone (as it doesn't make sense)
if ( is_logarithmic )
@ -2071,9 +2069,9 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
logarithmic_zero_epsilon = ImPow ( 0.1f , ( float ) decimal_precision ) ;
// Convert to parametric space, apply delta, convert back
float v_old_parametric = Slid erCalc RatioFromValueT < TYPE , FLOATTYPE > ( data_type , v_cur , v_min , v_max , logarithmic_zero_epsilon , zero_deadzone_halfsize , flags ) ;
float v_old_parametric = Sca leRatioFromValueT < TYPE , FLOATTYPE > ( data_type , v_cur , v_min , v_max , is_logarithmic , logarithmic_zero_epsilon , zero_deadzone_halfsize ) ;
float v_new_parametric = v_old_parametric + g . DragCurrentAccum ;
v_cur = Slid erCalc ValueFromRatioT < TYPE , FLOATTYPE > ( data_type , v_new_parametric , v_min , v_max , logarithmic_zero_epsilon , zero_deadzone_halfsize , flags ) ;
v_cur = Sca leValueFromRatioT < TYPE , FLOATTYPE > ( data_type , v_new_parametric , v_min , v_max , is_logarithmic , logarithmic_zero_epsilon , zero_deadzone_halfsize ) ;
v_old_ref_for_accum_remainder = v_old_parametric ;
}
else
@ -2090,7 +2088,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
if ( is_logarithmic )
{
// Convert to parametric space, apply delta, convert back
float v_new_parametric = Slid erCalc RatioFromValueT < TYPE , FLOATTYPE > ( data_type , v_cur , v_min , v_max , logarithmic_zero_epsilon , zero_deadzone_halfsize , flags ) ;
float v_new_parametric = Sca leRatioFromValueT < TYPE , FLOATTYPE > ( data_type , v_cur , v_min , v_max , is_logarithmic , logarithmic_zero_epsilon , zero_deadzone_halfsize ) ;
g . DragCurrentAccum - = ( float ) ( v_new_parametric - v_old_ref_for_accum_remainder ) ;
}
else
@ -2403,6 +2401,8 @@ bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* p_data
//-------------------------------------------------------------------------
// [SECTION] Widgets: SliderScalar, SliderFloat, SliderInt, etc.
//-------------------------------------------------------------------------
// - ScaleRatioFromValueT<> [Internal]
// - ScaleValueFromRatioT<> [Internal]
// - SliderBehaviorT<>() [Internal]
// - SliderBehavior() [Internal]
// - SliderScalar()
@ -2421,14 +2421,14 @@ bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* p_data
// - VSliderInt()
//-------------------------------------------------------------------------
// Convert a value v in the output space of a slider into a parametric position on the slider itself (the logical opposite of Slid erCalc ValueFromRatioT)
// Convert a value v in the output space of a slider into a parametric position on the slider itself (the logical opposite of Sca leValueFromRatioT)
template < typename TYPE , typename FLOATTYPE >
float ImGui : : Slid erCalc RatioFromValueT ( ImGuiDataType data_type , TYPE v , TYPE v_min , TYPE v_max , float logarithmic_zero_epsilon , float zero_deadzone_halfsize , ImGuiSliderFlags flags )
float ImGui : : Sca leRatioFromValueT ( ImGuiDataType data_type , TYPE v , TYPE v_min , TYPE v_max , bool is_logarithmic , float logarithmic_zero_epsilon , float zero_deadzone_halfsize )
{
if ( v_min = = v_max )
return 0.0f ;
IM_UNUSED ( data_type ) ;
const bool is_logarithmic = ( flags & ImGuiSliderFlags_Logarithmic ) & & ( data_type = = ImGuiDataType_Float | | data_type = = ImGuiDataType_Double ) ;
const TYPE v_clamped = ( v_min < v_max ) ? ImClamp ( v , v_min , v_max ) : ImClamp ( v , v_max , v_min ) ;
if ( is_logarithmic )
{
@ -2477,15 +2477,13 @@ float ImGui::SliderCalcRatioFromValueT(ImGuiDataType data_type, TYPE v, TYPE v_m
return ( float ) ( ( FLOATTYPE ) ( v_clamped - v_min ) / ( FLOATTYPE ) ( v_max - v_min ) ) ;
}
// Convert a parametric position on a slider into a value v in the output space (the logical opposite of Slid erCalc RatioFromValueT)
// Convert a parametric position on a slider into a value v in the output space (the logical opposite of Sca leRatioFromValueT)
template < typename TYPE , typename FLOATTYPE >
TYPE ImGui : : Slid erCalc ValueFromRatioT ( ImGuiDataType data_type , float t , TYPE v_min , TYPE v_max , float logarithmic_zero_epsilon , float zero_deadzone_halfsize , ImGuiSliderFlags flags )
TYPE ImGui : : Sca leValueFromRatioT ( ImGuiDataType data_type , float t , TYPE v_min , TYPE v_max , bool is_logarithmic , float logarithmic_zero_epsilon , float zero_deadzone_halfsize )
{
if ( v_min = = v_max )
return ( TYPE ) 0.0f ;
const bool is_decimal = ( data_type = = ImGuiDataType_Float ) | | ( data_type = = ImGuiDataType_Double ) ;
const bool is_logarithmic = ( flags & ImGuiSliderFlags_Logarithmic ) & & ( data_type = = ImGuiDataType_Float | | data_type = = ImGuiDataType_Double ) ;
TYPE result ;
if ( is_logarithmic )
@ -2647,8 +2645,8 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
}
else if ( g . SliderCurrentAccumDirty )
{
clicked_t = Slid erCalc RatioFromValueT < TYPE , FLOATTYPE > ( data_type , * v , v_min , v_max , logarithmic_zero_epsilon , zero_deadzone_halfsize , flags ) ;
clicked_t = Sca leRatioFromValueT < TYPE , FLOATTYPE > ( data_type , * v , v_min , v_max , is_logarithmic , logarithmic_zero_epsilon , zero_deadzone_halfsize ) ;
if ( ( clicked_t > = 1.0f & & delta > 0.0f ) | | ( clicked_t < = 0.0f & & delta < 0.0f ) ) // This is to avoid applying the saturation when already past the limits
{
set_new_value = false ;
@ -2661,10 +2659,10 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
clicked_t = ImSaturate ( clicked_t + delta ) ;
// Calculate what our "new" clicked_t will be, and thus how far we actually moved the slider, and subtract this from the accumulator
TYPE v_new = Slid erCalc ValueFromRatioT < TYPE , FLOATTYPE > ( data_type , clicked_t , v_min , v_max , logarithmic_zero_epsilon , zero_deadzone_halfsize , flags ) ;
TYPE v_new = Sca leValueFromRatioT < TYPE , FLOATTYPE > ( data_type , clicked_t , v_min , v_max , is_logarithmic , logarithmic_zero_epsilon , zero_deadzone_halfsize ) ;
if ( ! ( flags & ImGuiSliderFlags_NoRoundToFormat ) )
v_new = RoundScalarWithFormatT < TYPE , SIGNEDTYPE > ( format , data_type , v_new ) ;
float new_clicked_t = Slid erCalc RatioFromValueT < TYPE , FLOATTYPE > ( data_type , v_new , v_min , v_max , logarithmic_zero_epsilon , zero_deadzone_halfsize , flags ) ;
float new_clicked_t = Sca leRatioFromValueT < TYPE , FLOATTYPE > ( data_type , v_new , v_min , v_max , is_logarithmic , logarithmic_zero_epsilon , zero_deadzone_halfsize ) ;
if ( delta > 0 )
g . SliderCurrentAccum - = ImMin ( new_clicked_t - old_clicked_t , delta ) ;
@ -2678,7 +2676,7 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
if ( set_new_value )
{
TYPE v_new = Slid erCalc ValueFromRatioT < TYPE , FLOATTYPE > ( data_type , clicked_t , v_min , v_max , logarithmic_zero_epsilon , zero_deadzone_halfsize , flags ) ;
TYPE v_new = Sca leValueFromRatioT < TYPE , FLOATTYPE > ( data_type , clicked_t , v_min , v_max , is_logarithmic , logarithmic_zero_epsilon , zero_deadzone_halfsize ) ;
// Round to user desired precision based on format string
if ( ! ( flags & ImGuiSliderFlags_NoRoundToFormat ) )
@ -2700,7 +2698,7 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
else
{
// Output grab position so it can be displayed by the caller
float grab_t = Slid erCalc RatioFromValueT < TYPE , FLOATTYPE > ( data_type , * v , v_min , v_max , logarithmic_zero_epsilon , zero_deadzone_halfsize , flags ) ;
float grab_t = Sca leRatioFromValueT < TYPE , FLOATTYPE > ( data_type , * v , v_min , v_max , is_logarithmic , logarithmic_zero_epsilon , zero_deadzone_halfsize ) ;
if ( axis = = ImGuiAxis_Y )
grab_t = 1.0f - grab_t ;
const float grab_pos = ImLerp ( slider_usable_pos_min , slider_usable_pos_max , grab_t ) ;