# Is there a easy way to step sliders?

Hello,

i have a float slider for by ex : 0 to 5.

i would like to use it by step of 0.25 with the mouse

what i would say, is, when i slide the slider, i would like to move it by step of 0.25.

in the same way of Siider Int ( where the step is of 1 :))

i have explored the code, but im not sure how i can do that, or if there is a easy way to do that, without modify ImGui ?

thanks

in the function : ImGui::SliderBehaviorT

i can replace

`v_new = ImLerp(v_min, v_max, clicked_t);`

by

``````FLOATTYPE v_new_off_f = (v_max - v_min) * clicked_t;
FLOATTYPE v_new_off_floor = (int)(v_new_off_f / step) * step;
FLOATTYPE v_new_off_round = v_new_off_floor + step;
if (!is_decimal && v_new_off_floor < v_new_off_round)
v_new = v_min + v_new_off_round;
else
v_new = v_min + v_new_off_floor;
``````

in the `if (is_decimal)` test. and the var step is the `step` value

i would like to activate this stepped func, by maybe adding a step parameter. if this parameter is equal to zero, so we use the classical Imlerp, and if > 0.0f we use this one.

but i dont know if i need to rewrite all sliders for use my SliderBehaviorT ?

if you are interest i can propose a PL for all decimal slider and drag.

it can be nice also to have the possibility to step the SliderInt,by ex, if we have a range of 100, it can be nice to step by 10, 15, 20 or 25 if needed.

i thinkc it can be a useful feauture, with not big code modification

maybe we can simplify for use same code for float and int stepper also if perf are same a demo :

thanks The stepping code should be before `// Round to user desired precision based on format string:`

I think it could work if we exposed an extra parameter in the low-level DragBehavior/SliderBehavior and let the user create their own drag/slider function with it.

Also see some ideas in https://github.com/ocornut/imgui/issues/1183

1 Like

indeed do :

``````if (v_step)
{
FLOATTYPE v_new_off_f = v_new;
TYPE v_new_off_floor = (int)(v_new_off_f / v_step) * v_step;
TYPE v_new_off_round = v_new_off_floor + v_step;
v_new = v_min + (TYPE)v_new_off_floor;
}
``````

before

`// Round to user desired precision based on format string:`

work perfect.

currently i have changed the signature of SldierBeahvior to :

`SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, TYPE* v, const TYPE v_min, const TYPE v_max, const TYPE v_step, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb)`

and modified all sliders. i thinkc i will not break imgui, just implement my sliders and my behavior for my sliders instead and in same time i will implement my range slider 1 Like