Skip to content

Commit

Permalink
Allow custom mapping from value to string in LabelReadoutSlider
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-13 committed Feb 20, 2022
1 parent cdeb831 commit 3cecd2f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions WECore/CoreJUCEPlugin/LabelReadoutSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ namespace WECore::JUCEPlugin {
class LabelReadoutSlider : public SliderLabelUpdater {
public:
explicit LabelReadoutSlider(const juce::String& componentName) : SliderLabelUpdater(componentName),
_isRunning(false) {}
_isRunning(false),
_valueToString([](T value) { return juce::String(value, 2); }) {}

virtual ~LabelReadoutSlider() = default;

Expand All @@ -112,9 +113,12 @@ namespace WECore::JUCEPlugin {
*/
inline void stop();

void setValueToString(std::function<juce::String(T)> valueToString) { _valueToString = valueToString; }

protected:
std::function<void(const juce::String&)> _targetCallback;
bool _isRunning;
std::function<juce::String(T)> _valueToString;

private:
juce::String _defaultText;
Expand Down Expand Up @@ -154,8 +158,7 @@ namespace WECore::JUCEPlugin {
template <class T>
void LabelReadoutSlider<T>::_updateLabel(const juce::MouseEvent& /*event*/) {
if (_isRunning) {
const juce::String valueString(getValue(), 2);
_targetCallback(valueString);
_targetCallback(_valueToString(getValue()));
}
}

Expand Down

0 comments on commit 3cecd2f

Please sign in to comment.