@ -5947,7 +5947,7 @@ float ImGui::RoundScalar(float value, int decimal_precision)
return negative ? - value : value ;
}
bool ImGui : : SliderBehavior ( const ImRect & frame_bb , ImGuiID id , float * v , float v_min , float v_max , float power , int decimal_precision , bool horizontal )
bool ImGui : : SliderBehavior ( const ImRect & frame_bb , ImGuiID id , float * v , float v_min , float v_max , float power , int decimal_precision , ImGuiSliderFlags flags )
{
ImGuiState & g = * GImGui ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
@ -5957,17 +5957,18 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
RenderFrame ( frame_bb . Min , frame_bb . Max , window - > Color ( ImGuiCol_FrameBg ) , true , style . FrameRounding ) ;
const bool is_non_linear = fabsf ( power - 1.0f ) > 0.0001f ;
const bool is_horizontal = ( flags & ImGuiSliderFlags_Vertical ) = = 0 ;
const float grab_padding = 2.0f ;
const float slider_sz = horizontal ? ( frame_bb . GetWidth ( ) - grab_padding * 2.0f ) : ( frame_bb . GetHeight ( ) - grab_padding * 2.0f ) ;
const float slider_sz = is_ horizontal ? ( frame_bb . GetWidth ( ) - grab_padding * 2.0f ) : ( frame_bb . GetHeight ( ) - grab_padding * 2.0f ) ;
float grab_sz ;
if ( decimal_precision > 0 )
grab_sz = ImMin ( style . GrabMinSize , slider_sz ) ;
else
grab_sz = ImMin ( ImMax ( 1.0f * ( slider_sz / ( v_max - v_min + 1.0f ) ) , style . GrabMinSize ) , slider_sz ) ; // Integer sliders, if possible have the grab size represent 1 unit
const float slider_usable_sz = slider_sz - grab_sz ;
const float slider_usable_pos_min = ( horizontal ? frame_bb . Min . x : frame_bb . Min . y ) + grab_padding + grab_sz * 0.5f ;
const float slider_usable_pos_max = ( horizontal ? frame_bb . Max . x : frame_bb . Max . y ) - grab_padding - grab_sz * 0.5f ;
const float slider_usable_pos_min = ( is_ horizontal ? frame_bb . Min . x : frame_bb . Min . y ) + grab_padding + grab_sz * 0.5f ;
const float slider_usable_pos_max = ( is_ horizontal ? frame_bb . Max . x : frame_bb . Max . y ) - grab_padding - grab_sz * 0.5f ;
// For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f
float linear_zero_pos = 0.0f ; // 0.0->1.0f
@ -5990,9 +5991,9 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
{
if ( g . IO . MouseDown [ 0 ] )
{
const float mouse_abs_pos = horizontal ? g . IO . MousePos . x : g . IO . MousePos . y ;
const float mouse_abs_pos = is_ horizontal ? g . IO . MousePos . x : g . IO . MousePos . y ;
float normalized_pos = ImClamp ( ( mouse_abs_pos - slider_usable_pos_min ) / slider_usable_sz , 0.0f , 1.0f ) ;
if ( ! horizontal )
if ( ! is_ horizontal)
normalized_pos = 1.0f - normalized_pos ;
float new_value ;
@ -6061,11 +6062,11 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
}
// Draw
if ( ! horizontal )
if ( ! is_ horizontal)
grab_t = 1.0f - grab_t ;
const float grab_pos = ImLerp ( slider_usable_pos_min , slider_usable_pos_max , grab_t ) ;
ImRect grab_bb ;
if ( horizontal )
if ( is_ horizontal)
grab_bb = ImRect ( ImVec2 ( grab_pos - grab_sz * 0.5f , frame_bb . Min . y + grab_padding ) , ImVec2 ( grab_pos + grab_sz * 0.5f , frame_bb . Max . y - grab_padding ) ) ;
else
grab_bb = ImRect ( ImVec2 ( frame_bb . Min . x + grab_padding , grab_pos - grab_sz * 0.5f ) , ImVec2 ( frame_bb . Max . x - grab_padding , grab_pos + grab_sz * 0.5f ) ) ;
@ -6129,7 +6130,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
ItemSize ( total_bb , style . FramePadding . y ) ;
// Actual slider behavior + render grab
const bool value_changed = SliderBehavior ( frame_bb , id , v , v_min , v_max , power , decimal_precision , true ) ;
const bool value_changed = SliderBehavior ( frame_bb , id , v , v_min , v_max , power , decimal_precision ) ;
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
char value_buf [ 64 ] ;
@ -6175,7 +6176,7 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float
}
// Actual slider behavior + render grab
bool value_changed = SliderBehavior ( frame_bb , id , v , v_min , v_max , power , decimal_precision , false ) ;
bool value_changed = SliderBehavior ( frame_bb , id , v , v_min , v_max , power , decimal_precision , ImGuiSliderFlags_Vertical ) ;
// 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