9 enum class ButtonState {
16 ButtonState _state = ButtonState::NORMAL;
17 std::function<void()> _onClick;
19 std::string buttonLabel =
"";
20 glm::vec2 bDimensions{0,0};
21 Color bBackground{255,255,255,255};
24 Entity* buttonBackground =
nullptr;
27 : _state(ButtonState::NORMAL),
32 : _state(ButtonState::NORMAL), _onClick(onClick) {}
34 ButtonComponent(std::function<
void()> onClick, std::string button_label, glm::vec2 b_dimensions,
Color b_background)
35 : _state(ButtonState::NORMAL),
37 buttonLabel(button_label),
38 bDimensions(b_dimensions),
39 bBackground(b_background){
44 void init()
override {
45 if (buttonLabel.length() > 0) {
47 uiLabel = &entity->getManager()->addEntity<
Node>();
52 uiLabel->setParentEntity(entity);
54 uiLabel->addGroup(Manager::buttonLabels);
56 if (bDimensions != glm::vec2(0.0f, 0.0f)) {
57 buttonBackground = &entity->getManager()->addEntity<
Node>();
63 buttonBackground->setParentEntity(entity);
65 buttonBackground->addGroup(Manager::panelBackground);
69 void setOnClick(std::function<
void()> newOnClick) {
70 _onClick = newOnClick;
73 void setState(ButtonState state) {
77 void update(
float deltaTime)
override {
82 if (_state == ButtonState::PRESSED && _onClick) {
85 setState(ButtonState::NORMAL);
90 std::string GetComponentName()
override {
91 return "ButtonComponent";