@@ -15,7 +15,9 @@ class Slider<T:Float> extends Widget<T> {
1515
1616 /**
1717 Override the default step for editing the curve. Note that if min and max are set the step will be calculated accordingly, but setting
18- this will override the automaticaly calculated value.
18+ this will override the automatically calculated value.
19+ The step basically control how much each value is rounded each time the slider is moved. Note that at the moment,
20+ values pasted from the clipboard or manually entered by the user using the keyboard are allowed to bypass the step value.
1921 **/
2022 public var step : Null <T > = null ;
2123
@@ -81,7 +83,11 @@ class Slider<T:Float> extends Widget<T> {
8183 throw " Slider can't be both exp and poly" ;
8284 }
8385
86+ if (value == null )
87+ value = getDefaultFallback ();
88+
8489 #if js
90+
8591 var container = js. Browser .document .createElement (" kit-slider" );
8692 slider = js. Browser .document .createInputElement ();
8793 container .append (slider );
@@ -212,7 +218,7 @@ class Slider<T:Float> extends Widget<T> {
212218
213219 slider .addEventListener (" blur" , (e : js.html. FocusEvent ) -> {
214220 var newValue = Std .parseFloat (slider .value );
215- slideTo (cast newValue ?? value , false );
221+ slideTo (cast newValue ?? value , false , false );
216222 });
217223
218224 return container ;
@@ -230,13 +236,14 @@ class Slider<T:Float> extends Widget<T> {
230236 }
231237
232238 function snap (value : Float ) : T {
233- var snap : Float = ( step : Float ) ?? (int ? 1.0 : 0.01 );
234- return cast hxd. Math .round (value / snap ) * snap ;
239+ var snap : Float = step != null ? 1.0 / step : (int ? 1.0 : 100 );
240+ return cast hxd. Math .round (value * snap ) / snap ;
235241 }
236242
237- function slideTo (newValue : T , isTemporary : Bool ) {
243+ function slideTo (newValue : T , isTemporary : Bool , doSnap : Bool = true ) {
238244 var group = Std .downcast (parent , SliderGroup );
239- newValue = snap (newValue );
245+ if (doSnap || int )
246+ newValue = snap (newValue );
240247
241248 if (group != null && group .isLocked ) {
242249 var changeDelta : Float = (newValue : Float ) / (value : Float );
@@ -312,7 +319,7 @@ class Slider<T:Float> extends Widget<T> {
312319 return ;
313320 }
314321 #if js
315- slider .value = Std .string (hxd. Math . round ( value * 100 ) / 100 );
322+ slider .value = Std .string (value );
316323 #else
317324 slider .slider .value = value ;
318325 #end
0 commit comments