@ -1680,25 +1680,25 @@ const ImGuiDataTypeInfo* ImGui::DataTypeGetInfo(ImGuiDataType data_type)
return & GDataTypeInfo [ data_type ] ;
}
int ImGui : : DataTypeFormatString ( char * buf , int buf_size , ImGuiDataType data_type , const void * data_ptr , const char * format )
int ImGui : : DataTypeFormatString ( char * buf , int buf_size , ImGuiDataType data_type , const void * p_ data, const char * format )
{
// Signedness doesn't matter when pushing integer arguments
if ( data_type = = ImGuiDataType_S32 | | data_type = = ImGuiDataType_U32 )
return ImFormatString ( buf , buf_size , format , * ( const ImU32 * ) data_ptr ) ;
return ImFormatString ( buf , buf_size , format , * ( const ImU32 * ) p_ data) ;
if ( data_type = = ImGuiDataType_S64 | | data_type = = ImGuiDataType_U64 )
return ImFormatString ( buf , buf_size , format , * ( const ImU64 * ) data_ptr ) ;
return ImFormatString ( buf , buf_size , format , * ( const ImU64 * ) p_ data) ;
if ( data_type = = ImGuiDataType_Float )
return ImFormatString ( buf , buf_size , format , * ( const float * ) data_ptr ) ;
return ImFormatString ( buf , buf_size , format , * ( const float * ) p_ data) ;
if ( data_type = = ImGuiDataType_Double )
return ImFormatString ( buf , buf_size , format , * ( const double * ) data_ptr ) ;
return ImFormatString ( buf , buf_size , format , * ( const double * ) p_ data) ;
if ( data_type = = ImGuiDataType_S8 )
return ImFormatString ( buf , buf_size , format , * ( const ImS8 * ) data_ptr ) ;
return ImFormatString ( buf , buf_size , format , * ( const ImS8 * ) p_ data) ;
if ( data_type = = ImGuiDataType_U8 )
return ImFormatString ( buf , buf_size , format , * ( const ImU8 * ) data_ptr ) ;
return ImFormatString ( buf , buf_size , format , * ( const ImU8 * ) p_ data) ;
if ( data_type = = ImGuiDataType_S16 )
return ImFormatString ( buf , buf_size , format , * ( const ImS16 * ) data_ptr ) ;
return ImFormatString ( buf , buf_size , format , * ( const ImS16 * ) p_ data) ;
if ( data_type = = ImGuiDataType_U16 )
return ImFormatString ( buf , buf_size , format , * ( const ImU16 * ) data_ptr ) ;
return ImFormatString ( buf , buf_size , format , * ( const ImU16 * ) p_ data) ;
IM_ASSERT ( 0 ) ;
return 0 ;
}
@ -1755,7 +1755,7 @@ void ImGui::DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void*
// User can input math operators (e.g. +100) to edit a numerical values.
// NB: This is _not_ a full expression evaluator. We should probably add one and replace this dumb mess..
bool ImGui : : DataTypeApplyOpFromText ( const char * buf , const char * initial_value_buf , ImGuiDataType data_type , void * data_ptr , const char * format )
bool ImGui : : DataTypeApplyOpFromText ( const char * buf , const char * initial_value_buf , ImGuiDataType data_type , void * p_ data, const char * format )
{
while ( ImCharIsBlankA ( * buf ) )
buf + + ;
@ -1781,7 +1781,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
int data_backup [ 2 ] ;
const ImGuiDataTypeInfo * type_info = ImGui : : DataTypeGetInfo ( data_type ) ;
IM_ASSERT ( type_info - > Size < = sizeof ( data_backup ) ) ;
memcpy ( data_backup , data_ptr , type_info - > Size ) ;
memcpy ( data_backup , p_ data, type_info - > Size ) ;
if ( format = = NULL )
format = type_info - > ScanFmt ;
@ -1790,7 +1790,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
int arg1i = 0 ;
if ( data_type = = ImGuiDataType_S32 )
{
int * v = ( int * ) data_ptr ;
int * v = ( int * ) p_ data;
int arg0i = * v ;
float arg1f = 0.0f ;
if ( op & & sscanf ( initial_value_buf , format , & arg0i ) < 1 )
@ -1805,7 +1805,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
{
// For floats we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in
format = " %f " ;
float * v = ( float * ) data_ptr ;
float * v = ( float * ) p_ data;
float arg0f = * v , arg1f = 0.0f ;
if ( op & & sscanf ( initial_value_buf , format , & arg0f ) < 1 )
return false ;
@ -1819,7 +1819,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
else if ( data_type = = ImGuiDataType_Double )
{
format = " %lf " ; // scanf differentiate float/double unlike printf which forces everything to double because of ellipsis
double * v = ( double * ) data_ptr ;
double * v = ( double * ) p_ data;
double arg0f = * v , arg1f = 0.0 ;
if ( op & & sscanf ( initial_value_buf , format , & arg0f ) < 1 )
return false ;
@ -1834,7 +1834,7 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
{
// All other types assign constant
// We don't bother handling support for legacy operators since they are a little too crappy. Instead we will later implement a proper expression evaluator in the future.
sscanf ( buf , format , data_ptr ) ;
sscanf ( buf , format , p_ data) ;
}
else
{
@ -1842,18 +1842,18 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
int v32 ;
sscanf ( buf , format , & v32 ) ;
if ( data_type = = ImGuiDataType_S8 )
* ( ImS8 * ) data_ptr = ( ImS8 ) ImClamp ( v32 , ( int ) IM_S8_MIN , ( int ) IM_S8_MAX ) ;
* ( ImS8 * ) p_ data = ( ImS8 ) ImClamp ( v32 , ( int ) IM_S8_MIN , ( int ) IM_S8_MAX ) ;
else if ( data_type = = ImGuiDataType_U8 )
* ( ImU8 * ) data_ptr = ( ImU8 ) ImClamp ( v32 , ( int ) IM_U8_MIN , ( int ) IM_U8_MAX ) ;
* ( ImU8 * ) p_ data = ( ImU8 ) ImClamp ( v32 , ( int ) IM_U8_MIN , ( int ) IM_U8_MAX ) ;
else if ( data_type = = ImGuiDataType_S16 )
* ( ImS16 * ) data_ptr = ( ImS16 ) ImClamp ( v32 , ( int ) IM_S16_MIN , ( int ) IM_S16_MAX ) ;
* ( ImS16 * ) p_ data = ( ImS16 ) ImClamp ( v32 , ( int ) IM_S16_MIN , ( int ) IM_S16_MAX ) ;
else if ( data_type = = ImGuiDataType_U16 )
* ( ImU16 * ) data_ptr = ( ImU16 ) ImClamp ( v32 , ( int ) IM_U16_MIN , ( int ) IM_U16_MAX ) ;
* ( ImU16 * ) p_ data = ( ImU16 ) ImClamp ( v32 , ( int ) IM_U16_MIN , ( int ) IM_U16_MAX ) ;
else
IM_ASSERT ( 0 ) ;
}
return memcmp ( data_backup , data_ptr , type_info - > Size ) ! = 0 ;
return memcmp ( data_backup , p_ data, type_info - > Size ) ! = 0 ;
}
static float GetMinimumStepAtDecimalPrecision ( int decimal_precision )
@ -2023,7 +2023,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
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 , ImGuiDragFlags flags )
bool ImGui : : DragBehavior ( ImGuiID id , ImGuiDataType data_type , void * p_ v, float v_speed , const void * p_min, const void * p _max, const char * format , float power , ImGuiDragFlags flags )
{
ImGuiContext & g = * GImGui ;
if ( g . ActiveId = = id )
@ -2038,30 +2038,32 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* v, float v_s
switch ( data_type )
{
case ImGuiDataType_S8 : { ImS32 v32 = ( ImS32 ) * ( ImS8 * ) v; bool r = DragBehaviorT < ImS32 , ImS32 , float > ( ImGuiDataType_S32 , & v32 , v_speed , v_min ? * ( const ImS8 * ) v_min : IM_S8_MIN , v_max ? * ( const ImS8 * ) v _max : IM_S8_MAX , format , power , flags ) ; if ( r ) * ( ImS8 * ) v = ( ImS8 ) v32 ; return r ; }
case ImGuiDataType_U8 : { ImU32 v32 = ( ImU32 ) * ( ImU8 * ) v; bool r = DragBehaviorT < ImU32 , ImS32 , float > ( ImGuiDataType_U32 , & v32 , v_speed , v_min ? * ( const ImU8 * ) v_min : IM_U8_MIN , v_max ? * ( const ImU8 * ) v _max : IM_U8_MAX , format , power , flags ) ; if ( r ) * ( ImU8 * ) v = ( ImU8 ) v32 ; return r ; }
case ImGuiDataType_S16 : { ImS32 v32 = ( ImS32 ) * ( ImS16 * ) v; bool r = DragBehaviorT < ImS32 , ImS32 , float > ( ImGuiDataType_S32 , & v32 , v_speed , v_min ? * ( const ImS16 * ) v_min : IM_S16_MIN , v_max ? * ( const ImS16 * ) v _max : IM_S16_MAX , format , power , flags ) ; if ( r ) * ( ImS16 * ) v = ( ImS16 ) v32 ; return r ; }
case ImGuiDataType_U16 : { ImU32 v32 = ( ImU32 ) * ( ImU16 * ) v; bool r = DragBehaviorT < ImU32 , ImS32 , float > ( ImGuiDataType_U32 , & v32 , v_speed , v_min ? * ( const ImU16 * ) v_min : IM_U16_MIN , v_max ? * ( const ImU16 * ) v _max : IM_U16_MAX , format , power , flags ) ; if ( r ) * ( ImU16 * ) v = ( ImU16 ) v32 ; return r ; }
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 , 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 , 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 , 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 , 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 , flags ) ;
case ImGuiDataType_S8 : { ImS32 v32 = ( ImS32 ) * ( ImS8 * ) p_ v; bool r = DragBehaviorT < ImS32 , ImS32 , float > ( ImGuiDataType_S32 , & v32 , v_speed , p_min ? * ( const ImS8 * ) p_min : IM_S8_MIN , p_max ? * ( const ImS8 * ) p _max : IM_S8_MAX , format , power , flags ) ; if ( r ) * ( ImS8 * ) p_ v = ( ImS8 ) v32 ; return r ; }
case ImGuiDataType_U8 : { ImU32 v32 = ( ImU32 ) * ( ImU8 * ) p_ v; bool r = DragBehaviorT < ImU32 , ImS32 , float > ( ImGuiDataType_U32 , & v32 , v_speed , p_min ? * ( const ImU8 * ) p_min : IM_U8_MIN , p_max ? * ( const ImU8 * ) p _max : IM_U8_MAX , format , power , flags ) ; if ( r ) * ( ImU8 * ) p_ v = ( ImU8 ) v32 ; return r ; }
case ImGuiDataType_S16 : { ImS32 v32 = ( ImS32 ) * ( ImS16 * ) p_ v; bool r = DragBehaviorT < ImS32 , ImS32 , float > ( ImGuiDataType_S32 , & v32 , v_speed , p_min ? * ( const ImS16 * ) p_min : IM_S16_MIN , p_max ? * ( const ImS16 * ) p _max : IM_S16_MAX , format , power , flags ) ; if ( r ) * ( ImS16 * ) p_ v = ( ImS16 ) v32 ; return r ; }
case ImGuiDataType_U16 : { ImU32 v32 = ( ImU32 ) * ( ImU16 * ) p_ v; bool r = DragBehaviorT < ImU32 , ImS32 , float > ( ImGuiDataType_U32 , & v32 , v_speed , p_min ? * ( const ImU16 * ) p_min : IM_U16_MIN , p_max ? * ( const ImU16 * ) p _max : IM_U16_MAX , format , power , flags ) ; if ( r ) * ( ImU16 * ) p_ v = ( ImU16 ) v32 ; return r ; }
case ImGuiDataType_S32 : return DragBehaviorT < ImS32 , ImS32 , float > ( data_type , ( ImS32 * ) p_v, v_speed , p_min ? * ( const ImS32 * ) p_min : IM_S32_MIN , p_max ? * ( const ImS32 * ) p _max : IM_S32_MAX , format , power , flags ) ;
case ImGuiDataType_U32 : return DragBehaviorT < ImU32 , ImS32 , float > ( data_type , ( ImU32 * ) p_v, v_speed , p_min ? * ( const ImU32 * ) p_min : IM_U32_MIN , p_max ? * ( const ImU32 * ) p _max : IM_U32_MAX , format , power , flags ) ;
case ImGuiDataType_S64 : return DragBehaviorT < ImS64 , ImS64 , double > ( data_type , ( ImS64 * ) p_v, v_speed , p_min ? * ( const ImS64 * ) p_min : IM_S64_MIN , p_max ? * ( const ImS64 * ) p _max : IM_S64_MAX , format , power , flags ) ;
case ImGuiDataType_U64 : return DragBehaviorT < ImU64 , ImS64 , double > ( data_type , ( ImU64 * ) p_v, v_speed , p_min ? * ( const ImU64 * ) p_min : IM_U64_MIN , p_max ? * ( const ImU64 * ) p _max : IM_U64_MAX , format , power , flags ) ;
case ImGuiDataType_Float : return DragBehaviorT < float , float , float > ( data_type , ( float * ) p_v, v_speed , p_min ? * ( const float * ) p_min : - FLT_MAX , p_max ? * ( const float * ) p _max : FLT_MAX , format , power , flags ) ;
case ImGuiDataType_Double : return DragBehaviorT < double , double , double > ( data_type , ( double * ) p_v, v_speed , p_min ? * ( const double * ) p_min : - DBL_MAX , p_max ? * ( const double * ) p _max : DBL_MAX , format , power , flags ) ;
case ImGuiDataType_COUNT : break ;
}
IM_ASSERT ( 0 ) ;
return false ;
}
bool ImGui : : DragScalar ( const char * label , ImGuiDataType data_type , void * v , float v_speed , const void * v_min , const void * v_max , const char * format , float power )
// Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a Drag widget, p_min and p_max are optional.
// Read code of e.g. SliderFloat(), SliderInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly.
bool ImGui : : DragScalar ( const char * label , ImGuiDataType data_type , void * p_data , float v_speed , const void * p_min , const void * p_max , const char * format , float power )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
if ( power ! = 1.0f )
IM_ASSERT ( v_min ! = NULL & & v _max ! = NULL ) ; // When using a power curve the drag needs to have known bounds
IM_ASSERT ( p_min ! = NULL & & p _max ! = NULL ) ; // When using a power curve the drag needs to have known bounds
ImGuiContext & g = * GImGui ;
const ImGuiStyle & style = g . Style ;
@ -2104,7 +2106,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
}
}
if ( temp_input_is_active | | temp_input_start )
return TempInputTextScalar ( frame_bb , id , label , data_type , v , format ) ;
return TempInputTextScalar ( frame_bb , id , label , data_type , p_data , format ) ;
// Draw frame
const ImU32 frame_col = GetColorU32 ( g . ActiveId = = id ? ImGuiCol_FrameBgActive : g . HoveredId = = id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg ) ;
@ -2112,13 +2114,13 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
RenderFrame ( frame_bb . Min , frame_bb . Max , frame_col , true , style . FrameRounding ) ;
// Drag behavior
const bool value_changed = DragBehavior ( id , data_type , v, v_speed , v_min , v _max, format , power , ImGuiDragFlags_None ) ;
const bool value_changed = DragBehavior ( id , data_type , p_data, v_speed , p_min , p _max, format , power , ImGuiDragFlags_None ) ;
if ( value_changed )
MarkItemEdited ( id ) ;
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
char value_buf [ 64 ] ;
const char * value_buf_end = value_buf + DataTypeFormatString ( value_buf , IM_ARRAYSIZE ( value_buf ) , data_type , v , format ) ;
const char * value_buf_end = value_buf + DataTypeFormatString ( value_buf , IM_ARRAYSIZE ( value_buf ) , data_type , p_data , format ) ;
RenderTextClipped ( frame_bb . Min , frame_bb . Max , value_buf , value_buf_end , NULL , ImVec2 ( 0.5f , 0.5f ) ) ;
if ( label_size . x > 0.0f )
@ -2128,7 +2130,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
return value_changed ;
}
bool ImGui : : DragScalarN ( const char * label , ImGuiDataType data_type , void * v , int components , float v_speed , const void * v_min, const void * v _max, const char * format , float power )
bool ImGui : : DragScalarN ( const char * label , ImGuiDataType data_type , void * p_data , int components , float v_speed , const void * p_min, const void * p _max, const char * format , float power )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
@ -2145,10 +2147,10 @@ bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* v, int
PushID ( i ) ;
if ( i > 0 )
SameLine ( 0 , g . Style . ItemInnerSpacing . x ) ;
value_changed | = DragScalar ( " " , data_type , v, v_speed , v_min , v _max, format , power ) ;
value_changed | = DragScalar ( " " , data_type , p_data, v_speed , p_min , p _max, format , power ) ;
PopID ( ) ;
PopItemWidth ( ) ;
v = ( void * ) ( ( char * ) v + type_size ) ;
p_data = ( void * ) ( ( char * ) p_data + type_size ) ;
}
PopID ( ) ;
@ -2474,39 +2476,41 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
// For 32-bits and larger types, slider bounds are limited to half the natural type range.
// So e.g. an integer Slider between INT_MAX-10 and INT_MAX will fail, but an integer Slider between INT_MAX/2-10 and INT_MAX/2 will be ok.
// It would be possible to lift that limitation with some work but it doesn't seem to be worth it for sliders.
bool ImGui : : SliderBehavior ( const ImRect & bb , ImGuiID id , ImGuiDataType data_type , void * v, const void * v_min, const void * v _max, const char * format , float power , ImGuiSliderFlags flags , ImRect * out_grab_bb )
bool ImGui : : SliderBehavior ( const ImRect & bb , ImGuiID id , ImGuiDataType data_type , void * p_ v, const void * p_min, const void * p _max, const char * format , float power , ImGuiSliderFlags flags , ImRect * out_grab_bb )
{
switch ( data_type )
{
case ImGuiDataType_S8 : { ImS32 v32 = ( ImS32 ) * ( ImS8 * ) v; bool r = SliderBehaviorT < ImS32 , ImS32 , float > ( bb , id , ImGuiDataType_S32 , & v32 , * ( const ImS8 * ) v_min, * ( const ImS8 * ) v _max, format , power , flags , out_grab_bb ) ; if ( r ) * ( ImS8 * ) v = ( ImS8 ) v32 ; return r ; }
case ImGuiDataType_U8 : { ImU32 v32 = ( ImU32 ) * ( ImU8 * ) v; bool r = SliderBehaviorT < ImU32 , ImS32 , float > ( bb , id , ImGuiDataType_U32 , & v32 , * ( const ImU8 * ) v_min, * ( const ImU8 * ) v _max, format , power , flags , out_grab_bb ) ; if ( r ) * ( ImU8 * ) v = ( ImU8 ) v32 ; return r ; }
case ImGuiDataType_S16 : { ImS32 v32 = ( ImS32 ) * ( ImS16 * ) v; bool r = SliderBehaviorT < ImS32 , ImS32 , float > ( bb , id , ImGuiDataType_S32 , & v32 , * ( const ImS16 * ) v_min, * ( const ImS16 * ) v _max, format , power , flags , out_grab_bb ) ; if ( r ) * ( ImS16 * ) v = ( ImS16 ) v32 ; return r ; }
case ImGuiDataType_U16 : { ImU32 v32 = ( ImU32 ) * ( ImU16 * ) v; bool r = SliderBehaviorT < ImU32 , ImS32 , float > ( bb , id , ImGuiDataType_U32 , & v32 , * ( const ImU16 * ) v_min, * ( const ImU16 * ) v _max, format , power , flags , out_grab_bb ) ; if ( r ) * ( ImU16 * ) v = ( ImU16 ) v32 ; return r ; }
case ImGuiDataType_S8 : { ImS32 v32 = ( ImS32 ) * ( ImS8 * ) p_ v; bool r = SliderBehaviorT < ImS32 , ImS32 , float > ( bb , id , ImGuiDataType_S32 , & v32 , * ( const ImS8 * ) p_min, * ( const ImS8 * ) p _max, format , power , flags , out_grab_bb ) ; if ( r ) * ( ImS8 * ) p_ v = ( ImS8 ) v32 ; return r ; }
case ImGuiDataType_U8 : { ImU32 v32 = ( ImU32 ) * ( ImU8 * ) p_ v; bool r = SliderBehaviorT < ImU32 , ImS32 , float > ( bb , id , ImGuiDataType_U32 , & v32 , * ( const ImU8 * ) p_min, * ( const ImU8 * ) p _max, format , power , flags , out_grab_bb ) ; if ( r ) * ( ImU8 * ) p_ v = ( ImU8 ) v32 ; return r ; }
case ImGuiDataType_S16 : { ImS32 v32 = ( ImS32 ) * ( ImS16 * ) p_ v; bool r = SliderBehaviorT < ImS32 , ImS32 , float > ( bb , id , ImGuiDataType_S32 , & v32 , * ( const ImS16 * ) p_min, * ( const ImS16 * ) p _max, format , power , flags , out_grab_bb ) ; if ( r ) * ( ImS16 * ) p_ v = ( ImS16 ) v32 ; return r ; }
case ImGuiDataType_U16 : { ImU32 v32 = ( ImU32 ) * ( ImU16 * ) p_ v; bool r = SliderBehaviorT < ImU32 , ImS32 , float > ( bb , id , ImGuiDataType_U32 , & v32 , * ( const ImU16 * ) p_min, * ( const ImU16 * ) p _max, format , power , flags , out_grab_bb ) ; if ( r ) * ( ImU16 * ) p_ v = ( ImU16 ) v32 ; return r ; }
case ImGuiDataType_S32 :
IM_ASSERT ( * ( const ImS32 * ) v _min > = IM_S32_MIN / 2 & & * ( const ImS32 * ) v _max < = IM_S32_MAX / 2 ) ;
return SliderBehaviorT < ImS32 , ImS32 , float > ( bb , id , data_type , ( ImS32 * ) v, * ( const ImS32 * ) v_min, * ( const ImS32 * ) v _max, format , power , flags , out_grab_bb ) ;
IM_ASSERT ( * ( const ImS32 * ) p _min > = IM_S32_MIN / 2 & & * ( const ImS32 * ) p _max < = IM_S32_MAX / 2 ) ;
return SliderBehaviorT < ImS32 , ImS32 , float > ( bb , id , data_type , ( ImS32 * ) p_ v, * ( const ImS32 * ) p_min, * ( const ImS32 * ) p _max, format , power , flags , out_grab_bb ) ;
case ImGuiDataType_U32 :
IM_ASSERT ( * ( const ImU32 * ) v _max < = IM_U32_MAX / 2 ) ;
return SliderBehaviorT < ImU32 , ImS32 , float > ( bb , id , data_type , ( ImU32 * ) v, * ( const ImU32 * ) v_min, * ( const ImU32 * ) v _max, format , power , flags , out_grab_bb ) ;
IM_ASSERT ( * ( const ImU32 * ) p _max < = IM_U32_MAX / 2 ) ;
return SliderBehaviorT < ImU32 , ImS32 , float > ( bb , id , data_type , ( ImU32 * ) p_ v, * ( const ImU32 * ) p_min, * ( const ImU32 * ) p _max, format , power , flags , out_grab_bb ) ;
case ImGuiDataType_S64 :
IM_ASSERT ( * ( const ImS64 * ) v _min > = IM_S64_MIN / 2 & & * ( const ImS64 * ) v _max < = IM_S64_MAX / 2 ) ;
return SliderBehaviorT < ImS64 , ImS64 , double > ( bb , id , data_type , ( ImS64 * ) v, * ( const ImS64 * ) v_min, * ( const ImS64 * ) v _max, format , power , flags , out_grab_bb ) ;
IM_ASSERT ( * ( const ImS64 * ) p _min > = IM_S64_MIN / 2 & & * ( const ImS64 * ) p _max < = IM_S64_MAX / 2 ) ;
return SliderBehaviorT < ImS64 , ImS64 , double > ( bb , id , data_type , ( ImS64 * ) p_ v, * ( const ImS64 * ) p_min, * ( const ImS64 * ) p _max, format , power , flags , out_grab_bb ) ;
case ImGuiDataType_U64 :
IM_ASSERT ( * ( const ImU64 * ) v _max < = IM_U64_MAX / 2 ) ;
return SliderBehaviorT < ImU64 , ImS64 , double > ( bb , id , data_type , ( ImU64 * ) v, * ( const ImU64 * ) v_min, * ( const ImU64 * ) v _max, format , power , flags , out_grab_bb ) ;
IM_ASSERT ( * ( const ImU64 * ) p _max < = IM_U64_MAX / 2 ) ;
return SliderBehaviorT < ImU64 , ImS64 , double > ( bb , id , data_type , ( ImU64 * ) p_ v, * ( const ImU64 * ) p_min, * ( const ImU64 * ) p _max, format , power , flags , out_grab_bb ) ;
case ImGuiDataType_Float :
IM_ASSERT ( * ( const float * ) v _min > = - FLT_MAX / 2.0f & & * ( const float * ) v _max < = FLT_MAX / 2.0f ) ;
return SliderBehaviorT < float , float , float > ( bb , id , data_type , ( float * ) v, * ( const float * ) v_min, * ( const float * ) v _max, format , power , flags , out_grab_bb ) ;
IM_ASSERT ( * ( const float * ) p _min > = - FLT_MAX / 2.0f & & * ( const float * ) p _max < = FLT_MAX / 2.0f ) ;
return SliderBehaviorT < float , float , float > ( bb , id , data_type , ( float * ) p_ v, * ( const float * ) p_min, * ( const float * ) p _max, format , power , flags , out_grab_bb ) ;
case ImGuiDataType_Double :
IM_ASSERT ( * ( const double * ) v _min > = - DBL_MAX / 2.0f & & * ( const double * ) v _max < = DBL_MAX / 2.0f ) ;
return SliderBehaviorT < double , double , double > ( bb , id , data_type , ( double * ) v, * ( const double * ) v_min, * ( const double * ) v _max, format , power , flags , out_grab_bb ) ;
IM_ASSERT ( * ( const double * ) p _min > = - DBL_MAX / 2.0f & & * ( const double * ) p _max < = DBL_MAX / 2.0f ) ;
return SliderBehaviorT < double , double , double > ( bb , id , data_type , ( double * ) p_ v, * ( const double * ) p_min, * ( const double * ) p _max, format , power , flags , out_grab_bb ) ;
case ImGuiDataType_COUNT : break ;
}
IM_ASSERT ( 0 ) ;
return false ;
}
bool ImGui : : SliderScalar ( const char * label , ImGuiDataType data_type , void * v , const void * v_min , const void * v_max , const char * format , float power )
// Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a slider, they are all required.
// Read code of e.g. SliderFloat(), SliderInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly.
bool ImGui : : SliderScalar ( const char * label , ImGuiDataType data_type , void * p_data , const void * p_min , const void * p_max , const char * format , float power )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
@ -2553,7 +2557,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co
}
}
if ( temp_input_is_active | | temp_input_start )
return TempInputTextScalar ( frame_bb , id , label , data_type , v , format ) ;
return TempInputTextScalar ( frame_bb , id , label , data_type , p_data , format ) ;
// Draw frame
const ImU32 frame_col = GetColorU32 ( g . ActiveId = = id ? ImGuiCol_FrameBgActive : g . HoveredId = = id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg ) ;
@ -2562,7 +2566,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co
// Slider behavior
ImRect grab_bb ;
const bool value_changed = SliderBehavior ( frame_bb , id , data_type , v, v_min , v _max, format , power , ImGuiSliderFlags_None , & grab_bb ) ;
const bool value_changed = SliderBehavior ( frame_bb , id , data_type , p_data, p_min , p _max, format , power , ImGuiSliderFlags_None , & grab_bb ) ;
if ( value_changed )
MarkItemEdited ( id ) ;
@ -2572,7 +2576,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
char value_buf [ 64 ] ;
const char * value_buf_end = value_buf + DataTypeFormatString ( value_buf , IM_ARRAYSIZE ( value_buf ) , data_type , v , format ) ;
const char * value_buf_end = value_buf + DataTypeFormatString ( value_buf , IM_ARRAYSIZE ( value_buf ) , data_type , p_data , format ) ;
RenderTextClipped ( frame_bb . Min , frame_bb . Max , value_buf , value_buf_end , NULL , ImVec2 ( 0.5f , 0.5f ) ) ;
if ( label_size . x > 0.0f )
@ -2668,7 +2672,7 @@ bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const
return SliderScalarN ( label , ImGuiDataType_S32 , v , 4 , & v_min , & v_max , format ) ;
}
bool ImGui : : VSliderScalar ( const char * label , const ImVec2 & size , ImGuiDataType data_type , void * v, const void * v_min , const void * v _max, const char * format , float power )
bool ImGui : : VSliderScalar ( const char * label , const ImVec2 & size , ImGuiDataType data_type , void * p_data, const void * p_min , const void * p _max, const char * format , float power )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
@ -2708,7 +2712,7 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d
// Slider behavior
ImRect grab_bb ;
const bool value_changed = SliderBehavior ( frame_bb , id , data_type , v, v_min , v _max, format , power , ImGuiSliderFlags_Vertical , & grab_bb ) ;
const bool value_changed = SliderBehavior ( frame_bb , id , data_type , p_data, p_min , p _max, format , power , ImGuiSliderFlags_Vertical , & grab_bb ) ;
if ( value_changed )
MarkItemEdited ( id ) ;
@ -2719,7 +2723,7 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
// For the vertical slider we allow centered text to overlap the frame padding
char value_buf [ 64 ] ;
const char * value_buf_end = value_buf + DataTypeFormatString ( value_buf , IM_ARRAYSIZE ( value_buf ) , data_type , v , format ) ;
const char * value_buf_end = value_buf + DataTypeFormatString ( value_buf , IM_ARRAYSIZE ( value_buf ) , data_type , p_data , format ) ;
RenderTextClipped ( ImVec2 ( frame_bb . Min . x , frame_bb . Min . y + style . FramePadding . y ) , frame_bb . Max , value_buf , value_buf_end , NULL , ImVec2 ( 0.5f , 0.0f ) ) ;
if ( label_size . x > 0.0f )
RenderText ( ImVec2 ( frame_bb . Max . x + style . ItemInnerSpacing . x , frame_bb . Min . y + style . FramePadding . y ) , label ) ;
@ -2832,7 +2836,7 @@ int ImParseFormatPrecision(const char* fmt, int default_precision)
// Create text input in place of another active widget (e.g. used when doing a CTRL+Click on drag/slider widgets)
// FIXME: Facilitate using this in variety of other situations.
bool ImGui : : TempInputTextScalar ( const ImRect & bb , ImGuiID id , const char * label , ImGuiDataType data_type , void * data_ptr , const char * format )
bool ImGui : : TempInputTextScalar ( const ImRect & bb , ImGuiID id , const char * label , ImGuiDataType data_type , void * p_ data, const char * format )
{
ImGuiContext & g = * GImGui ;
@ -2845,7 +2849,7 @@ bool ImGui::TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label,
char fmt_buf [ 32 ] ;
char data_buf [ 32 ] ;
format = ImParseFormatTrimDecorations ( format , fmt_buf , IM_ARRAYSIZE ( fmt_buf ) ) ;
DataTypeFormatString ( data_buf , IM_ARRAYSIZE ( data_buf ) , data_type , data_ptr , format ) ;
DataTypeFormatString ( data_buf , IM_ARRAYSIZE ( data_buf ) , data_type , p_ data, format ) ;
ImStrTrimBlanks ( data_buf ) ;
g . CurrentWindow - > DC . CursorPos = bb . Min ;
@ -2860,14 +2864,16 @@ bool ImGui::TempInputTextScalar(const ImRect& bb, ImGuiID id, const char* label,
}
if ( value_changed )
{
value_changed = DataTypeApplyOpFromText ( data_buf , g . InputTextState . InitialTextA . Data , data_type , data_ptr , NULL ) ;
value_changed = DataTypeApplyOpFromText ( data_buf , g . InputTextState . InitialTextA . Data , data_type , p_ data, NULL ) ;
if ( value_changed )
MarkItemEdited ( id ) ;
}
return value_changed ;
}
bool ImGui : : InputScalar ( const char * label , ImGuiDataType data_type , void * data_ptr , const void * step , const void * step_fast , const char * format , ImGuiInputTextFlags flags )
// Note: p_data, p_step, p_step_fast are _pointers_ to a memory address holding the data. For an Input widget, p_step and p_step_fast are optional.
// Read code of e.g. InputFloat(), InputInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly.
bool ImGui : : InputScalar ( const char * label , ImGuiDataType data_type , void * p_data , const void * p_step , const void * p_step_fast , const char * format , ImGuiInputTextFlags flags )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
@ -2880,7 +2886,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
format = DataTypeGetInfo ( data_type ) - > PrintFmt ;
char buf [ 64 ] ;
DataTypeFormatString ( buf , IM_ARRAYSIZE ( buf ) , data_type , data_ptr , format ) ;
DataTypeFormatString ( buf , IM_ARRAYSIZE ( buf ) , data_type , p_ data, format ) ;
bool value_changed = false ;
if ( ( flags & ( ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific ) ) = = 0 )
@ -2888,7 +2894,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
flags | = ImGuiInputTextFlags_AutoSelectAll ;
flags | = ImGuiInputTextFlags_NoMarkEdited ; // We call MarkItemEdited() ourselve by comparing the actual data rather than the string.
if ( step ! = NULL )
if ( p_ step ! = NULL )
{
const float button_size = GetFrameHeight ( ) ;
@ -2896,7 +2902,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
PushID ( label ) ;
SetNextItemWidth ( ImMax ( 1.0f , CalcItemWidth ( ) - ( button_size + style . ItemInnerSpacing . x ) * 2 ) ) ;
if ( InputText ( " " , buf , IM_ARRAYSIZE ( buf ) , flags ) ) // PushId(label) + "" gives us the expected ID from outside point of view
value_changed = DataTypeApplyOpFromText ( buf , g . InputTextState . InitialTextA . Data , data_type , data_ptr , format ) ;
value_changed = DataTypeApplyOpFromText ( buf , g . InputTextState . InitialTextA . Data , data_type , p_ data, format ) ;
// Step buttons
const ImVec2 backup_frame_padding = style . FramePadding ;
@ -2907,13 +2913,13 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
SameLine ( 0 , style . ItemInnerSpacing . x ) ;
if ( ButtonEx ( " - " , ImVec2 ( button_size , button_size ) , button_flags ) )
{
DataTypeApplyOp ( data_type , ' - ' , data_ptr , data_ptr , g . IO . KeyCtrl & & step_fast ? step_fast : step) ;
DataTypeApplyOp ( data_type , ' - ' , p_ data, p_ data, g . IO . KeyCtrl & & p_ step_fast ? p_ step_fast : p_ step) ;
value_changed = true ;
}
SameLine ( 0 , style . ItemInnerSpacing . x ) ;
if ( ButtonEx ( " + " , ImVec2 ( button_size , button_size ) , button_flags ) )
{
DataTypeApplyOp ( data_type , ' + ' , data_ptr , data_ptr , g . IO . KeyCtrl & & step_fast ? step_fast : step) ;
DataTypeApplyOp ( data_type , ' + ' , p_ data, p_ data, g . IO . KeyCtrl & & p_ step_fast ? p_ step_fast : p_ step) ;
value_changed = true ;
}
@ -2931,7 +2937,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
else
{
if ( InputText ( label , buf , IM_ARRAYSIZE ( buf ) , flags ) )
value_changed = DataTypeApplyOpFromText ( buf , g . InputTextState . InitialTextA . Data , data_type , data_ptr , format ) ;
value_changed = DataTypeApplyOpFromText ( buf , g . InputTextState . InitialTextA . Data , data_type , p_ data, format ) ;
}
if ( value_changed )
MarkItemEdited ( window - > DC . LastItemId ) ;
@ -2939,7 +2945,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
return value_changed ;
}
bool ImGui : : InputScalarN ( const char * label , ImGuiDataType data_type , void * v , int components , const void * step, const void * step_fast, const char * format , ImGuiInputTextFlags flags )
bool ImGui : : InputScalarN ( const char * label , ImGuiDataType data_type , void * p_data , int components , const void * p_ step, const void * p_ step_fast, const char * format , ImGuiInputTextFlags flags )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
@ -2956,10 +2962,10 @@ bool ImGui::InputScalarN(const char* label, ImGuiDataType data_type, void* v, in
PushID ( i ) ;
if ( i > 0 )
SameLine ( 0 , g . Style . ItemInnerSpacing . x ) ;
value_changed | = InputScalar ( " " , data_type , v, step , step_fast, format , flags ) ;
value_changed | = InputScalar ( " " , data_type , p_data, p_step , p_ step_fast, format , flags ) ;
PopID ( ) ;
PopItemWidth ( ) ;
v = ( void * ) ( ( char * ) v + type_size ) ;
p_data = ( void * ) ( ( char * ) p_data + type_size ) ;
}
PopID ( ) ;