mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-18 00:54:19 +00:00
Added a method to create a ModalCallbackFunction from a lambda function
This commit is contained in:
parent
12eeadec8b
commit
3aee68ec5f
2 changed files with 30 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue