forked from rpbpolis/spic-prj-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.hpp
43 lines (35 loc) · 1.13 KB
/
Button.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef BUTTON_H_
#define BUTTON_H_
#include "UIObject.hpp"
#include <functional>
namespace spic {
/**
* @brief Instances of this class are clickable user interface items.
*/
class Button : public UIObject {
public:
/**
* @brief This function is called when the button is clicked, which
* will trigger a call to the registered onClick member.
* @spicapi
*/
void Click();
/**
* @brief Register the onClick handler to be used when the button is clicked.
* @param callback The function to register, usually a lambda. But this can be
* any kind of callable.
* @spicapi
*/
void OnClick(std::function<void()> callback) { onClick = callback; }
private:
/**
* @brief When false, the button will not react to clicks.
*/
bool interactable;
/**
* @brief The registered click handler.
*/
std::function<void()> onClick;
};
}
#endif // BUTTON_H_