Closed
Description
In particular, being able to use this useful little class with callbacks that are lambdas-with-context would make this much more useful for use with object member functions. For example:
class MyClass
{
public:
MyClass() : _button(7) {
_button.attachClick([this]() { this->_myFunc(); });
}
private:
void _myFunc() {
// ... do stuff when single clicked.
}
OneButton _button;
};
Something along the lines of what is already there, but just extrapolating it...
#include <functional>
...
class OneButton
{
public:
...
typedef std::function<void()> callbackLambda; // <== ADDED.
...
callbackLambda _clickLambda; // <== ADDED.
...
void attachClick(callbackLambda newLambda) { // <== ADDED new method.
_clickLambda = newLambda;
}
...
void OneButton::Tick(bool activeLevel)
{
...
case OneButton::OCS_COUNT:
...
if (_nClicks == 1) {
// this was 1 click only.
if (_clickFunc) _clickFunc();
if (_paramClickFunc) _paramClickFunc(_clickFuncParam);
if (_clickLambda) _clickLambda(); // <== ADDED.
etc..
Metadata
Metadata
Assignees
Labels
No labels
Activity