diff --git a/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp b/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp index 73095cc8ff..908c4d1f9c 100644 --- a/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp +++ b/modules/juce_gui_basics/components/juce_ModalComponentManager.cpp @@ -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 fn) noexcept : function (fn) {} + void modalStateFinished (int result) override { function (result); } + + std::function function; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LambdaCallback) +}; + +ModalComponentManager::Callback* ModalCallbackFunction::create (std::function f) +{ + return new LambdaCallback (f); +} +#endif diff --git a/modules/juce_gui_basics/components/juce_ModalComponentManager.h b/modules/juce_gui_basics/components/juce_ModalComponentManager.h index 149163b605..03b2990d93 100644 --- a/modules/juce_gui_basics/components/juce_ModalComponentManager.h +++ b/modules/juce_gui_basics/components/juce_ModalComponentManager.h @@ -187,6 +187,17 @@ public: return new FunctionCaller1 (functionToCall, parameterValue); } + #if JUCE_COMPILER_SUPPORTS_LAMBDAS + /** This is a utility function to create a ModalComponentManager::Callback that will + call a lambda function. + The lambda that you supply must take an integer parameter, which is the result code that + was returned when the modal component was dismissed. + + @see ModalComponentManager::Callback + */ + static ModalComponentManager::Callback* create (std::function); + #endif + //============================================================================== /** This is a utility function to create a ModalComponentManager::Callback that will call a static function with two custom parameters.