1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-28 02:30:05 +00:00

Added a method to create a ModalCallbackFunction from a lambda function

This commit is contained in:
jules 2016-05-10 09:34:40 +01:00
parent 12eeadec8b
commit 3aee68ec5f
2 changed files with 30 additions and 0 deletions

View file

@ -245,6 +245,7 @@ bool ModalComponentManager::cancelAllModalComponents()
return numModal > 0;
}
//==============================================================================
#if JUCE_MODAL_LOOPS_PERMITTED
class ModalComponentManager::ReturnValueRetriever : public ModalComponentManager::Callback
{
@ -292,3 +293,21 @@ int ModalComponentManager::runEventLoopForCurrentComponent()
return returnValue;
}
#endif
//==============================================================================
#if JUCE_COMPILER_SUPPORTS_LAMBDAS
struct LambdaCallback : public ModalComponentManager::Callback
{
LambdaCallback (std::function<void(int)> fn) noexcept : function (fn) {}
void modalStateFinished (int result) override { function (result); }
std::function<void(int)> function;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LambdaCallback)
};
ModalComponentManager::Callback* ModalCallbackFunction::create (std::function<void(int)> f)
{
return new LambdaCallback (f);
}
#endif