@@ -222,8 +222,16 @@ bool Toggle(const char *str_id, bool *v, const char *description)
222222 return status;
223223}
224224
225- void Slider (const char *str_id, float *v, const char *description)
225+ bool Slider (const char *str_id, float *v, const char *description)
226226{
227+ return Slider (str_id, v, 0 , 1 , description);
228+ }
229+
230+ bool Slider (const char *str_id, float *v, float min, float max, const char *description)
231+ {
232+ float initial = *v;
233+ float pos = (initial - min) / (max - min);
234+
227235 ImGui::PushStyleColor (ImGuiCol_Button, IM_COL32_BLACK_TRANS);
228236
229237 ImGuiStyle &style = ImGui::GetStyle ();
@@ -261,13 +269,13 @@ void Slider(const char *str_id, float *v, const char *description)
261269 ImGui::IsKeyPressed (ImGuiKey_GamepadDpadLeft) ||
262270 ImGui::IsKeyPressed (ImGuiKey_GamepadLStickLeft) ||
263271 ImGui::IsKeyPressed (ImGuiKey_GamepadRStickLeft)) {
264- *v -= 0.05 ;
272+ pos -= 0.05 ;
265273 }
266274 if (ImGui::IsKeyPressed (ImGuiKey_RightArrow) ||
267275 ImGui::IsKeyPressed (ImGuiKey_GamepadDpadRight) ||
268276 ImGui::IsKeyPressed (ImGuiKey_GamepadLStickRight) ||
269277 ImGui::IsKeyPressed (ImGuiKey_GamepadRStickRight)) {
270- *v += 0.05 ;
278+ pos += 0.05 ;
271279 }
272280
273281 if (
@@ -286,16 +294,19 @@ void Slider(const char *str_id, float *v, const char *description)
286294
287295 if (ImGui::IsItemActive ()) {
288296 ImVec2 mouse = ImGui::GetMousePos ();
289- *v = GetSliderValueForMousePos (mouse, slider_pos, slider_size);
297+ pos = GetSliderValueForMousePos (mouse, slider_pos, slider_size);
290298 }
291- *v = fmax (0 , fmin (*v , 1 ));
292- DrawSlider (*v , ImGui::IsItemHovered () || ImGui::IsItemActive (), slider_pos,
299+ pos = fmax (0 , fmin (pos , 1 ));
300+ DrawSlider (pos , ImGui::IsItemHovered () || ImGui::IsItemActive (), slider_pos,
293301 slider_size);
294302
295303 ImVec2 slider_max = ImVec2 (slider_pos.x + slider_size.x , slider_pos.y + slider_size.y );
296304 ImGui::RenderNavHighlight (ImRect (slider_pos, slider_max), window->GetID (" ###slider" ));
297305
298306 ImGui::PopStyleColor ();
307+
308+ *v = (pos * (max - min)) + min;
309+ return *v != initial;
299310}
300311
301312bool FilePicker (const char *str_id, const char **buf, const char *filters,
0 commit comments