| User | Message |
|
Posted : Saturday, 20 February 2010, 09:50 | Permalink | Mark Here |
HoboBen

 
WW Entries : 9
|
I think I'm too sleepy, can't get this to work...
For a slider gui element, I want to clip the slider to certain values, e.g. every tenth of the bar.
This works:
offset = offset - (offset mod (width/(divisions-1)))
However, this always clamps to the lower value. I'd like to clamp to the nearest value, meaning sometimes I need to clamp upwards.
Any ideas?
-----
github |
 | |
|
Posted : Saturday, 20 February 2010, 12:05 | Permalink | Mark Here |
JL235

 
WW Entries : 7
|
Something like...
-->
is what I think would work.
Index refers to which of the sections the slider is located in, from 0 (inclusive) to divisions (exclusive).
So if the width is 100, and there are 5 divisions, then the increment is 20. The first position (at index 0) is 10 (20/2 + 0*20) whilst the last position (at index 4) is 90 (20/2 + 4*20).
Hope that helps!
----- PlayMyCode.com - build and play in your browser, Blog, Twitter. |
 | |
|
Posted : Saturday, 20 February 2010, 12:34 | Permalink | Mark Here |
HoboBen

 
WW Entries : 9
|
Thanks very much!
I managed to work on it and got this
-->
Result!!!

-----
github |
 | |
|
Posted : Saturday, 20 February 2010, 16:00 | Permalink | Mark Here |
Sticky
 
|
Do you really need the else of the if-then-else there? Setting a value to itself is effectively a no-op.
----- last.fm |
 | |
|
Posted : Sunday, 21 February 2010, 00:33 | Permalink | Mark Here |
Jayenkai

 
WW Entries : 103
|
It was probably a leftover from a trial+error thing. I leave loads of those things all over the place!
-----
 |
 | |
|
Posted : Monday, 22 February 2010, 10:52 | Permalink | Mark Here |
HoboBen

 
WW Entries : 9
|
Oops, turns out it's "slider.sliOffset = slider.sliOffset - o3"... don't know how that disappeared!
-----
github |
 | |
|