Skip to content

Commit

Permalink
Implement missing [popmenu] features
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Feb 7, 2025
1 parent 008b0c3 commit 40fd4ec
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions Source/Objects/PopMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PopMenu final : public ObjectBase {
Value receiveSymbol = SynchronousValue();
Value parameterName = SynchronousValue();
Value variableName = SynchronousValue();
Value labelNoSelection = SynchronousValue();

Value outline = SynchronousValue();
Value savestate = SynchronousValue();
Expand All @@ -26,6 +27,7 @@ class PopMenu final : public ObjectBase {
NVGcolor bgCol;

StringArray items;
String currentText;
int currentItem = 0;

public:
Expand All @@ -39,7 +41,8 @@ class PopMenu final : public ObjectBase {
objectParameters.addParamReceiveSymbol(&receiveSymbol);
objectParameters.addParamString("Parameter", cGeneral, &parameterName);
objectParameters.addParamString("Variable", cGeneral, &variableName);
objectParameters.addParamBool("Outline", cGeneral, &outline, { "No", "Yes" });
objectParameters.addParamString("No selection label", cGeneral, &labelNoSelection);
//objectParameters.addParamBool("Outline", cGeneral, &outline, { "No", "Yes" });
objectParameters.addParamBool("Save state", cGeneral, &savestate, { "No", "Yes" });
objectParameters.addParamBool("Loadbang", cGeneral, &loadbang, { "No", "Yes" });

Expand Down Expand Up @@ -76,6 +79,7 @@ class PopMenu final : public ObjectBase {
menu.showMenuAsync(PopupMenu::Options().withTargetComponent(this), [_this = SafePointer(this)](int item) {
if (item && _this) {
_this->currentItem = item - 1;
_this->currentText = _this->items[item - 1];
_this->sendFloatValue(item - 1);
_this->updateTextLayout();
}
Expand Down Expand Up @@ -144,7 +148,9 @@ class PopMenu final : public ObjectBase {
savestate = menu->x_savestate;
loadbang = menu->x_lb;
outline = menu->x_outline;

currentItem = menu->x_idx;
labelNoSelection = menu->x_label->s_name;

sendSymbol = getSendSymbol();
receiveSymbol = getReceiveSymbol();

Expand Down Expand Up @@ -201,7 +207,7 @@ class PopMenu final : public ObjectBase {

void updateTextLayout()
{
auto const text = items[currentItem];
auto const text = currentItem >= 0 ? currentText : getValue<String>(labelNoSelection);
auto const colour = cnv->editor->getLookAndFeel().findColour(PlugDataColour::canvasTextColourId);
auto const font = Fonts::getCurrentFont().withHeight(getHeight() * 0.7f);

Expand Down Expand Up @@ -294,6 +300,11 @@ class PopMenu final : public ObjectBase {
} else if (value.refersToSameSourceAs(loadbang)) {
if (auto menu = ptr.get<t_fake_menu>())
menu->x_lb = getValue<bool>(loadbang);
} else if (value.refersToSameSourceAs(labelNoSelection)) {
if (auto menu = ptr.get<t_fake_menu>())
menu->x_label = pd->generateSymbol(getValue<String>(labelNoSelection));
updateTextLayout();
repaint();
}
}

Expand All @@ -302,8 +313,11 @@ class PopMenu final : public ObjectBase {
switch (symbol) {
case hash("float"):
case hash("set"): {
if (atoms.size() >= 1) {
currentItem = static_cast<int>(atoms[0].getFloat());
if (atoms.size() >= 1 && atoms[0].isFloat()) {
currentItem = std::clamp(static_cast<int>(atoms[0].getFloat()), -1, items.size() - 1);
if(currentItem >= 0) {
currentText = items[currentItem];
}
updateTextLayout();
}
break;
Expand All @@ -314,29 +328,35 @@ class PopMenu final : public ObjectBase {
break;
}
case hash("send"): {
if (atoms.size() >= 1)
if (atoms.size() >= 1 && atoms[0].isSymbol())
setParameterExcludingListener(sendSymbol, atoms[0].toString());
object->updateIolets();
break;
}
case hash("receive"): {
if (atoms.size() >= 1)
if (atoms.size() >= 1 && atoms[0].isSymbol())
setParameterExcludingListener(receiveSymbol, atoms[0].toString());
object->updateIolets();
break;
}
case hash("fgcolor"): {
if (atoms.size() >= 1) {
case hash("fg"): {
if (atoms.size() >= 1 && atoms[0].isSymbol()) {
primaryColour = convertTclColour(atoms[0].toString()).toString();
}
break;
}
case hash("bgcolor"): {
if (atoms.size() >= 1) {
case hash("bg"): {
if (atoms.size() >= 1 && atoms[0].isSymbol()) {
secondaryColour = convertTclColour(atoms[0].toString()).toString();
}
break;
}
case hash("label"): {
if (atoms.size() >= 1 && atoms[0].isSymbol()) {
labelNoSelection = atoms[0].toString();
}
break;
}
default:
break;
}
Expand Down

0 comments on commit 40fd4ec

Please sign in to comment.