@ -1706,9 +1706,10 @@ TYPE ImGui::RoundScalarWithFormatT(const char* format, ImGuiDataType data_type,
// This is called by DragBehavior() when the widget is active (held by mouse or being manipulated with Nav controls)
// This is called by DragBehavior() when the widget is active (held by mouse or being manipulated with Nav controls)
template < typename TYPE , typename SIGNEDTYPE , typename FLOATTYPE >
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 , ImGuiDragFlags flags )
{
{
ImGuiContext & g = * GImGui ;
ImGuiContext & g = * GImGui ;
const ImGuiAxis axis = ( flags & ImGuiDragFlags_Vertical ) ? ImGuiAxis_Y : ImGuiAxis_X ;
const bool is_decimal = ( data_type = = ImGuiDataType_Float ) | | ( data_type = = ImGuiDataType_Double ) ;
const bool is_decimal = ( data_type = = ImGuiDataType_Float ) | | ( data_type = = ImGuiDataType_Double ) ;
const bool has_min_max = ( v_min ! = v_max ) ;
const bool has_min_max = ( v_min ! = v_max ) ;
@ -1720,7 +1721,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
float adjust_delta = 0.0f ;
float adjust_delta = 0.0f ;
if ( g . ActiveIdSource = = ImGuiInputSource_Mouse & & IsMousePosValid ( ) & & g . IO . MouseDragMaxDistanceSqr [ 0 ] > 1.0f * 1.0f )
if ( g . ActiveIdSource = = ImGuiInputSource_Mouse & & IsMousePosValid ( ) & & g . IO . MouseDragMaxDistanceSqr [ 0 ] > 1.0f * 1.0f )
{
{
adjust_delta = g . IO . MouseDelta .x ;
adjust_delta = g . IO . MouseDelta [axis ] ;
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 )
@ -1729,11 +1730,15 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
else if ( g . ActiveIdSource = = ImGuiInputSource_Nav )
else if ( g . ActiveIdSource = = ImGuiInputSource_Nav )
{
{
int decimal_precision = is_decimal ? 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 ) [axis ] ;
v_speed = ImMax ( v_speed , GetMinimumStepAtDecimalPrecision ( decimal_precision ) ) ;
v_speed = ImMax ( v_speed , GetMinimumStepAtDecimalPrecision ( decimal_precision ) ) ;
}
}
adjust_delta * = v_speed ;
adjust_delta * = v_speed ;
// For vertical drag we currently assume that Up=higher value (like we do with vertical sliders). This may become a parameter.
if ( axis = = ImGuiAxis_Y )
adjust_delta = - adjust_delta ;
// Clear current value on activation
// Clear current value on activation
// Avoid altering values and clamping when we are _already_ past the limits and heading in the same direction, so e.g. if range is 0..255, current value is 300 and we are pushing to the right side, keep the 300.
// Avoid altering values and clamping when we are _already_ past the limits and heading in the same direction, so e.g. if range is 0..255, current value is 300 and we are pushing to the right side, keep the 300.
bool is_just_activated = g . ActiveIdIsJustActivated ;
bool is_just_activated = g . ActiveIdIsJustActivated ;
@ -1804,7 +1809,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
return true ;
return true ;
}
}
bool ImGui : : DragBehavior ( ImGuiID id , ImGuiDataType data_type , void * v , float v_speed , const void * v_min , const void * v_max , const char * format , float power )
bool ImGui : : DragBehavior ( ImGuiID id , ImGuiDataType data_type , void * v , float v_speed , const void * v_min , const void * v_max , const char * format , float power , ImGuiDragFlags flags )
{
{
ImGuiContext & g = * GImGui ;
ImGuiContext & g = * GImGui ;
if ( g . ActiveId = = id )
if ( g . ActiveId = = id )
@ -1819,12 +1824,12 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* v, float v_s
switch ( data_type )
switch ( data_type )
{
{
case ImGuiDataType_S32 : return DragBehaviorT < ImS32 , ImS32 , float > ( data_type , ( ImS32 * ) v , v_speed , v_min ? * ( const ImS32 * ) v_min : IM_S32_MIN , v_max ? * ( const ImS32 * ) v_max : IM_S32_MAX , format , power );
case ImGuiDataType_S32 : return DragBehaviorT < ImS32 , ImS32 , float > ( data_type , ( ImS32 * ) v , v_speed , v_min ? * ( const ImS32 * ) v_min : IM_S32_MIN , v_max ? * ( const ImS32 * ) v_max : IM_S32_MAX , format , power , flags );
case ImGuiDataType_U32 : return DragBehaviorT < ImU32 , ImS32 , float > ( data_type , ( ImU32 * ) v , v_speed , v_min ? * ( const ImU32 * ) v_min : IM_U32_MIN , v_max ? * ( const ImU32 * ) v_max : IM_U32_MAX , format , power );
case ImGuiDataType_U32 : return DragBehaviorT < ImU32 , ImS32 , float > ( data_type , ( ImU32 * ) v , v_speed , v_min ? * ( const ImU32 * ) v_min : IM_U32_MIN , v_max ? * ( const ImU32 * ) v_max : IM_U32_MAX , format , power , flags );
case ImGuiDataType_S64 : return DragBehaviorT < ImS64 , ImS64 , double > ( data_type , ( ImS64 * ) v , v_speed , v_min ? * ( const ImS64 * ) v_min : IM_S64_MIN , v_max ? * ( const ImS64 * ) v_max : IM_S64_MAX , format , power );
case ImGuiDataType_S64 : return DragBehaviorT < ImS64 , ImS64 , double > ( data_type , ( ImS64 * ) v , v_speed , v_min ? * ( const ImS64 * ) v_min : IM_S64_MIN , v_max ? * ( const ImS64 * ) v_max : IM_S64_MAX , format , power , flags );
case ImGuiDataType_U64 : return DragBehaviorT < ImU64 , ImS64 , double > ( data_type , ( ImU64 * ) v , v_speed , v_min ? * ( const ImU64 * ) v_min : IM_U64_MIN , v_max ? * ( const ImU64 * ) v_max : IM_U64_MAX , format , power );
case ImGuiDataType_U64 : return DragBehaviorT < ImU64 , ImS64 , double > ( data_type , ( ImU64 * ) v , v_speed , v_min ? * ( const ImU64 * ) v_min : IM_U64_MIN , v_max ? * ( const ImU64 * ) v_max : IM_U64_MAX , format , power , flags );
case ImGuiDataType_Float : return DragBehaviorT < float , float , float > ( data_type , ( float * ) v , v_speed , v_min ? * ( const float * ) v_min : - FLT_MAX , v_max ? * ( const float * ) v_max : FLT_MAX , format , power );
case ImGuiDataType_Float : return DragBehaviorT < float , float , float > ( data_type , ( float * ) v , v_speed , v_min ? * ( const float * ) v_min : - FLT_MAX , v_max ? * ( const float * ) v_max : FLT_MAX , format , power , flags );
case ImGuiDataType_Double : return DragBehaviorT < double , double , double > ( data_type , ( double * ) v , v_speed , v_min ? * ( const double * ) v_min : - DBL_MAX , v_max ? * ( const double * ) v_max : DBL_MAX , format , power );
case ImGuiDataType_Double : return DragBehaviorT < double , double , double > ( data_type , ( double * ) v , v_speed , v_min ? * ( const double * ) v_min : - DBL_MAX , v_max ? * ( const double * ) v_max : DBL_MAX , format , power , flags );
case ImGuiDataType_COUNT : break ;
case ImGuiDataType_COUNT : break ;
}
}
IM_ASSERT ( 0 ) ;
IM_ASSERT ( 0 ) ;
@ -1889,7 +1894,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
// Actual drag behavior
// Actual drag behavior
ItemSize ( total_bb , style . FramePadding . y ) ;
ItemSize ( total_bb , style . FramePadding . y ) ;
const bool value_changed = DragBehavior ( id , data_type , v , v_speed , v_min , v_max , format , power );
const bool value_changed = DragBehavior ( id , data_type , v , v_speed , v_min , v_max , format , power , ImGuiDragFlags_None );
if ( value_changed )
if ( value_changed )
MarkItemEdited ( id ) ;
MarkItemEdited ( id ) ;