If you have a second Window, with its own Component, is there a way to get a reference to the MainComponent? Or should you store a reference to it during creation of the second Component? Or maybe I don’t know what I’m talking about… I’m thinking I want a button in the second Window to call a function in the MainComponent…
in each class, add a lambda argument to their constructors and store them as members.
In the class that spawns/owns both components, pass in appropriate lambdas.
Make whatever GUI element you want call that lambda when clicked.
struct Foo : Component //or DocumentWindow or TopLevelWindow or...
{
Foo(std::function<void()> f) : func(std::move(f)) { }
void mouseDown(const MouseEvent& ) override { if( func ) func(); }
void memberFunc() { DBG( "this is a member func of Foo" ); }
std::function<void()> func;
}
struct MyApplication : JUCEApplication
{
std::unique_ptr<Foo> foo1, foo2;
//snip
void initialise(const String& commandLine) override
{
foo1 = std::make_unique<Foo>(nullptr);
foo2 = std::make_unique<Foo>(nullptr);
foo1->func = [this](){ foo2->memberFunc(); };
foo2->func = [this](){ foo1->memberFunc(); }
foo1->setVisible(true);
foo2->setVisible(true);
}
};
Untested, but you get the idea…