Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/sst/jucegui/components/MultiSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sst/jucegui/components/BaseStyles.h>

#include <string>
#include <unordered_map>

#include "ComponentBase.h"
#include "DiscreteParamEditor.h"
Expand Down Expand Up @@ -70,6 +71,12 @@ struct MultiSwitch : public DiscreteParamEditor,

void paint(juce::Graphics &g) override;

void setAbbreviatedLabelMap(const std::unordered_map<int, std::string> &m)
{
abbreviatedLabelMap = m;
repaint();
}

void setElementSize(int i)
{
elementSize = i;
Expand All @@ -81,6 +88,7 @@ struct MultiSwitch : public DiscreteParamEditor,
private:
int elementSize{std::numeric_limits<int>::max()};
void setValueFromMouse(const juce::MouseEvent &e);
std::unordered_map<int, std::string> abbreviatedLabelMap;
};

} // namespace sst::jucegui::components
Expand Down
9 changes: 7 additions & 2 deletions src/sst/jucegui/components/MultiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ void MultiSwitch::paint(juce::Graphics &g)
}
}
g.setFont(getFont(Styles::labelfont));
g.drawText(data->getValueAsStringFor(i + data->getMin()), txt,
juce::Justification::centred);
std::string ptxt{};
auto abf = abbreviatedLabelMap.find(i + data->getMin());
if (abf != abbreviatedLabelMap.end())
ptxt = abf->second;
else
ptxt = data->getValueAsStringFor(i + data->getMin());
g.drawText(ptxt, txt, juce::Justification::centred);
}

for (int i = 1; i < nItems; ++i)
Expand Down