Slider::setRange quietly changes text precision to display


#1

Title pretty much says it all…The Slider pimpl (maybe other components, didn’t check) recalculates and replaces the numDecimalPlaces field inside of setRange. The intent is clear from looking at the code, but the way it is now wrecks sliders with changed decimal precision unexpectedly. Example:

addAndMakeVisible(gainSlider = new Slider("gainSlider");
gainSlider->setNumDecimalPlacesToDisplay(2);
gainSlider->setRange(processor.gainParam->getMinDecibels(), processor.gainParam->getMaxDecibels());

setRange immediately resets numDecimalPlaces from 2 to 7 (or whatever it ends up calculating) with no warning. It’s not that big of a deal in my example since you can just switch the last 2 lines, but it seems kinda iffy for Slider to require a call to setNumDecimalPlacesToDisplay after every setRange in order to work as expected. Since setRange is tucked away in a pimpl, it’s not even something that can be overridden and fixed.

Any chance of getting this changed? Either have the recalculation only occur in setRange if numDecimalPlaces is still set to the default value, have it only recalculate if the range’s interval changed (since that’s mostly the intent), or even just removing it from setRange altogether are all better than current. If there are reasons it needs to stay the way it is now, maybe at least mention in setRange’s documentation that it’s going to overwrite numDecimalPlaces?