This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
forked from rpbpolis/spic-prj-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathButton.hpp
79 lines (66 loc) · 2.32 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef BUTTON_H_
#define BUTTON_H_
#include "UIObject.hpp"
#include <functional>
#if __has_include("Button_includes.hpp")
#include "Button_includes.hpp"
#endif
namespace spic {
/**
* @brief Instances of this class are clickable user interface items.
* @spicapi
*/
class Button : public UIObject {
public:
/**
* @brief Constructor.
* @param name The name for the game object.
* @param tag The tag for the game object.
* @param layer The layer for the game object.
* @param width The width of the UI object.
* @param height The height of the UI object.
* @sharedapi
*/
Button(const std::string& name, const std::string& tag, int layer, double width, double height);
/**
* @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; }
/**
* @brief Get if the button is interactable
* @return A boolean flag if the button is interactable or not
* @sharedapi
*/
bool Interactable() const;
/**
* @brief Set if the button is interactable
* @param isInteractable A new boolean value to define if the button should be interactable or not
* @sharedapi
*/
void Interactable(bool isInteractable);
private:
/**
* @brief When false, the button will not react to clicks.
* @spicapi
*/
bool interactable;
/**
* @brief The registered click handler.
* @spicapi
*/
std::function<void()> onClick;
#if __has_include("Button_private.hpp")
#include "Button_private.hpp"
#endif
};
}
#endif // BUTTON_H_