We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › how to snap controlP5 values
Page Index Toggle Pages: 1
how to snap controlP5 values (Read 433 times)
how to snap controlP5 values
Jan 25th, 2009, 3:28am
 
how can I snap, for example, a slider to 0.1 increments?  i can change the value after the fact but the control doesn't display the corrected value.  i can't set the correct value from the control function because that's recursive.

Code:

void Waves(float _W) {
// ** this snaps the value to 0.1 increments but the control doesn't reflect that **
W = round(_W*10.0)/10.0;
}
Re: how to snap controlP5 values
Reply #1 - Jan 27th, 2009, 11:01pm
 
to put this question another way:

how can you set the value of a controller without having it call the controller function?  this is necessary to avoid recursion.  


Re: how to snap controlP5 values
Reply #2 - Jan 27th, 2009, 11:15pm
 
or, if nobody has the answer to that either, how about this:

how can you format the controller value so it displays one decimal point instead of two?  e.g. 1.0 instead of 1.02.  i know about using nf(), but not sure how to overwrite/extend controller appearance.  


Re: how to snap controlP5 values
Reply #3 - Feb 9th, 2009, 5:10am
 
decimal places: new version of controlP5 has function setDecimalPrecision().

snapping to increments: might come in future version, until then, here's a workaround - you can use a "cheat" function called setValueLabel().   not pretty but it works.  

Code:

void sliderTest(int _x) {
// snap to increments of 10
// x is the real var, _x is what slider passes in
x = (_x/10)*10;
controlP5.controller("sliderTest").setValueLabel(str(x));
}
Page Index Toggle Pages: 1