Browse Source

Added a method to create a ModalCallbackFunction from a lambda function

tags/2021-05-28
jules 9 years ago
parent
commit
3aee68ec5f
2 changed files with 30 additions and 0 deletions
  1. +19
    -0
      modules/juce_gui_basics/components/juce_ModalComponentManager.cpp
  2. +11
    -0
      modules/juce_gui_basics/components/juce_ModalComponentManager.h

+ 19
- 0
modules/juce_gui_basics/components/juce_ModalComponentManager.cpp 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

+ 11
- 0
modules/juce_gui_basics/components/juce_ModalComponentManager.h View File

@@ -187,6 +187,17 @@ public:
return new FunctionCaller1<ParamType> (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<void(int)>);
#endif
//==============================================================================
/** This is a utility function to create a ModalComponentManager::Callback that will
call a static function with two custom parameters.


Loading…
Cancel
Save