Browse Source

Slider: Respect setNumDecimalPlaces after setRange

v7.0.9
Tom Poole 3 years ago
parent
commit
2eee1c1bd9
1 changed files with 29 additions and 11 deletions
  1. +29
    -11
      modules/juce_gui_basics/widgets/juce_Slider.cpp

+ 29
- 11
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -122,20 +122,34 @@ public:
return 0.0f; return 0.0f;
} }
void updateRange()
void setNumDecimalPlacesToDisplay (int decimalPlacesToDisplay)
{
fixedNumDecimalPlaces = jmax (0, decimalPlacesToDisplay);
numDecimalPlaces = fixedNumDecimalPlaces;
}
int getNumDecimalPlacesToDisplay() const
{ {
// figure out the number of DPs needed to display all values at this
// interval setting.
numDecimalPlaces = 7;
return fixedNumDecimalPlaces == -1 ? numDecimalPlaces : fixedNumDecimalPlaces;
}
if (normRange.interval != 0.0)
void updateRange()
{
if (fixedNumDecimalPlaces == -1)
{ {
int v = std::abs (roundToInt (normRange.interval * 10000000));
// figure out the number of DPs needed to display all values at this
// interval setting.
numDecimalPlaces = 7;
while ((v % 10) == 0 && numDecimalPlaces > 0)
if (normRange.interval != 0.0)
{ {
--numDecimalPlaces;
v /= 10;
int v = std::abs (roundToInt (normRange.interval * 10000000));
while ((v % 10) == 0 && numDecimalPlaces > 0)
{
--numDecimalPlaces;
v /= 10;
}
} }
} }
@@ -1299,6 +1313,7 @@ public:
TextEntryBoxPosition textBoxPos; TextEntryBoxPosition textBoxPos;
String textSuffix; String textSuffix;
int numDecimalPlaces = 7; int numDecimalPlaces = 7;
int fixedNumDecimalPlaces = -1;
int textBoxWidth = 80, textBoxHeight = 20; int textBoxWidth = 80, textBoxHeight = 20;
IncDecButtonMode incDecButtonMode = incDecButtonsNotDraggable; IncDecButtonMode incDecButtonMode = incDecButtonsNotDraggable;
ModifierKeys::Flags modifierToSwapModes = ModifierKeys::ctrlAltCommandModifiers; ModifierKeys::Flags modifierToSwapModes = ModifierKeys::ctrlAltCommandModifiers;
@@ -1658,11 +1673,14 @@ double Slider::snapValue (double attemptedValue, DragMode)
return attemptedValue; return attemptedValue;
} }
int Slider::getNumDecimalPlacesToDisplay() const noexcept { return pimpl->numDecimalPlaces; }
int Slider::getNumDecimalPlacesToDisplay() const noexcept
{
return pimpl->getNumDecimalPlacesToDisplay();
}
void Slider::setNumDecimalPlacesToDisplay (int decimalPlacesToDisplay) void Slider::setNumDecimalPlacesToDisplay (int decimalPlacesToDisplay)
{ {
pimpl->numDecimalPlaces = decimalPlacesToDisplay;
pimpl->setNumDecimalPlacesToDisplay (decimalPlacesToDisplay);
updateText(); updateText();
} }


Loading…
Cancel
Save