Pattern to use when attaching a control and setting actions

Hi! Learning plenty with iPlug2. Thanks for this project.

So, I have become familiar with the pattern for attaching controls inside the graphics layout lambda function.

I can do something like AttachControl()->SetActionFunction( [] () { ... }

But whats the recommended way to for example set an animation end func as well. In the example above, SetActionFunction... doesn’t return a pointer to this , so the initialiser has to stop there? Meaning I should then grab the control again, and attach something like pGraphics->GetControl( kCtrlReScan )->SetAnimationEndActionFunction( [this](IControl * pCaller) {...

Or whats the way to do it?

Yep currently you need to get a pointer to the control if you want to set two functions, can’t do it in a one liner

Updated on master, so now you can do something like this…

pGraphics->AttachControl(new IVButtonControl(b.GetCentredInside(100)))
->SetActionFunction([](IControl* pCaller){
  SplashClickActionFunc(pCaller);
  pCaller->As<IVButtonControl>()->SetColor(kFG, IColor::GetRandomColor());
})
->SetAnimationEndActionFunction([pGraphics](IControl* pCaller){
  pGraphics->GetBackgroundControl()->As<IPanelControl>()->SetPattern(IColor::GetRandomColor());
});
1 Like