sojamo / controlp5

A gui library for processing.org
GNU Lesser General Public License v2.1
490 stars 142 forks source link

setDecimalPrecision(0) breaks range #133

Closed hamoid closed 6 years ago

hamoid commented 6 years ago
import controlP5.*;

ControlP5 cp5;

int a = 56789;

void setup() {
  size(200, 100);
  cp5 = new ControlP5(this);

  cp5.addSlider("a")
     .setDecimalPrecision(0)
     .setRange(0, 100000);
}

void draw() {}

2018-08-27-123129_200x128_scrot

In this example, the range becomes 0 .. 10000 instead of 0 .. 100000 (one zero missing).

If I remove the int a variable declaration it works fine. If I set the decimal precision to 1 it also works fine. I'm using an automatic control panel generator which sets the precision for each variable, and it sounds logical to me to set it to 0 for ints, but it breaks the behavior.

sojamo commented 6 years ago

indeed a strange behaviour. If the type of variable a in your example is changed to a float and the decimalPrecision is set to 0, the number is displayed correctly, however if it is a int, the last digit goes missing. I am not able to fix this without being sure to cause another unexpected behaviour, hence I wont fix this.

If you work with values of type int, I assume that the precision does not have to be set and the problem of the missing last digit does not occur.

hamoid commented 6 years ago

So if anyone finds this thread in the future: don't set decimalPrecision to 0 on integers :)

In my case I can do something like if(requestedDecimalPrecision > 0) { slider.setDecimalPrecision(requestedDecimalPrecision); }