View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide

How do make sliders snap to steps?

Home   How To   Code Pool   Public Library   Theory   Events
snapping to an (invisible) grid is done internally by rounding.

compare these three pieces of code:

(

var w;
w = SCWindow("snapping", Rect(128, 64, 380, 190));
b = SCSlider(w, Rect(10,10, 330, 50));
c = SCSlider(w, Rect(10,90, 330, 50));

c.action = { b.step = c.value };
w.front; 

)

(

var w;
w = SCWindow("snapping", Rect(128, 64, 380, 190));
b = SCSlider(w, Rect(10,10, 330, 50));
c = SCSlider(w, Rect(10,90, 330, 50));

b.action = { b.value = b.value.round(c.value) };
w.front; 

)

(

var w, d;
w = SCWindow("snapping", Rect(128, 64, 380, 190));
b = SCSlider(w, Rect(10,10, 330, 50));
c = SCSlider(w, Rect(10,90, 330, 50));

d = ControlSpec(0, 1);

b.action = { b.value = d.map(b.value) };
c.action = { d.step = c.value };
w.front; 

)




Link to this Page