-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.hpp
54 lines (45 loc) · 1.34 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
#pragma once
#include "Widget.hpp"
#include "Label.hpp"
namespace gGUI {
class Button : public Widget
{
private:
Slot press = Slot(this, SLOT_FUNC(Button::pressHandler));
Slot release;
Label *text = nullptr;
public:
Signal clicked;
void pressHandler(Event ev)
{
std::cerr << "Button pressed at (" << ev.pos.ker.x << ", " << ev.pos.ker.y << ")!\n"; //FIXME
}
Button(size_t x, size_t y, size_t w, size_t h, Widget *p, const char *str, std::string t = "buttonbg")
: Widget(x, y, w, h, p, t)
{
if (str != nullptr) {
text = new Label(w, h, w, h, this, str);
add_child(text);
}
}
Button(Widget *p, std::string t = "buttonbg")
: Widget(-1, -1, -1, -1, p, t) {}
virtual void postload() override
{
clicked.connect(press);
Widget::postload();
}
void emitSignals(Event ev) override
{
ev.widgetID = (uint64_t)this;
if (ev.type == Event::MousePress)
clicked.call(ev);
}
virtual void resize(size_t new_w, size_t new_h) override
{
Widget::resize(new_w, new_h);
if (text)
text->resize(w, h);
}
};
}