[FR] Slider::setNumDecimalPlacesToDisplay method


#1

I know the suggested method to change the number of decimal places shown in a slider is to use Slider::getTextFromValue(), but for a simple Slider I don’t want to subclass the Slider class and I just want a simple method to change the number of decimal places… so if possible could you please add:

void Slider::setNumDecimalPlacesToDisplay (int numDecimalPlacesToDisplay)
{
    pimpl->numDecimalPlaces = numDecimalPlacesToDisplay;
    
    updateText();
}

A recent commit (bug fix to the String class) has changed the number of decimal places Slider is showing to 7, where it didn’t before.

Thanks,

Rail


#2

Thanks Rail, I’ve added this to develop and it should appear on the public repo shortly.


#3

Thanks Fabian!

Cheers,

Rail


#4

Note that when the slider’s range is changed, then the number of decimals is reset to 7 (or something else if you have a range interval) in Slider::Pimpl::updateRange()

So the following does not work :

slider.setNumDecimalPlacesToDisplay (0);
slider.setRange (0., 100.);

#5

setRange() resets it to 7 decimal places…

    void setRange (double newMin, double newMax, double newInt)
    {
        if (minimum != newMin || maximum != newMax || interval != newInt)
        {
           // blah, blah, blah...

           // figure out the number of DPs needed to display all values at this
            // interval setting.
            numDecimalPlaces = 7;

           // blah, blah, blah...

            updateText();
        }
    }

Rail