diff --git a/libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h b/libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h index c9e1c46ba85..cc086418859 100644 --- a/libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h +++ b/libs/escape-from-vstgui/include/efvg/escape_from_vstgui.h @@ -1832,6 +1832,7 @@ struct COptionMenu : public CControl SEP, COLBK, SECT, + CUSTOM, ROOT } type = ROOT; @@ -1840,6 +1841,8 @@ struct COptionMenu : public CControl std::string label = ""; std::function op = []() {}; std::vector children; + //std::unique_ptr customComponent; + juce::PopupMenu::CustomComponent *customComponent; bool checked = false; bool enabled = true; } rootNode; @@ -1881,6 +1884,19 @@ struct COptionMenu : public CControl r->nodeIndex = rootNode.children.size() - 1; return r; } + std::shared_ptr addEntry(juce::PopupMenu::CustomComponent *compPtr, // I own + const std::function &callback ) + { + auto q = MenuNode{MenuNode::CUSTOM}; + q.customComponent = compPtr; + q.op = callback; + rootNode.children.push_back(q); + + auto res = std::make_shared(); + res->weakPtr = this; + res->nodeIndex = rootNode.children.size() - 1; + return res; + } std::shared_ptr addEntry(COptionMenu *m, const std::string &nm) { m->remember(); @@ -1948,6 +1964,11 @@ struct COptionMenu : public CControl case MenuNode::SECT: m.addSectionHeader(k.label); break; + case MenuNode::CUSTOM: + auto rr = std::unique_ptr(k.customComponent); + + m.addCustomItem(-1, std::move(rr)); + break; } ct++; if (nbi > 0 && ct % nbi == 0) diff --git a/src/gui/SurgeGUIEditor.cpp b/src/gui/SurgeGUIEditor.cpp index 569c7feaf02..3e869ff497b 100644 --- a/src/gui/SurgeGUIEditor.cpp +++ b/src/gui/SurgeGUIEditor.cpp @@ -2641,6 +2641,56 @@ int32_t SurgeGUIEditor::controlModifierClicked(CControl *control, CButtonState b eid++; } + struct BS : public juce::PopupMenu::CustomComponent, + public juce::Button::Listener + { + BS(){ + std::cout << "Made a BS" << std::endl; + flarg = std::make_unique("Foo"); + flarg->setButtonText("Cool" ); + flarg->addListener(this); + addAndMakeVisible(*flarg); + }; + ~BS() {std::cout << "Killed a BS" << std::endl; }; + std::unique_ptr flarg; + void getIdealSize(int &idealWidth, int &idealHeight) override { + idealWidth = 200; + idealHeight = 25; + } + void buttonClicked(juce::Button *button1) override { + std::cout << "BUtton Clicked" << std::endl; + } + void paint(juce::Graphics &g) override { + g.fillAll(juce::Colour(255,0,255)); + g.setColour(juce::Colour(isDown * 255,255,isDown * 255)); + auto w = getWidth(); + auto h = getHeight(); + int v = startP; + for( int i=0; isetBounds(button); + } + void mouseDown(const juce::MouseEvent &event) override + { + std::cout << "mouseDown" << std::endl; + isDown = true; + repaint(); + } + void mouseUp(const juce::MouseEvent &event) override { + std::cout << "mouseUp" << std::endl; + } + bool isDown = false; + int startP = 0; + }; + contextMenu->addEntry(new BS(), [](){}); + contextMenu->addSeparator(eid++); char txt[TXT_SIZE], txt2[512];