-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropOutMenu.hpp
66 lines (59 loc) · 1.87 KB
/
DropOutMenu.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
#pragma once
#include "Widget.hpp"
namespace gGUI {
class DropOutMenu : public Widget {
protected:
bool dropped = false;
public:
Slot dropOut = Slot(this, SLOT_FUNC(DropOutMenu::handleDropOut));
Slot pullUp = Slot(this, SLOT_FUNC(DropOutMenu::handlePullUp));
Slot toggle = Slot(this, SLOT_FUNC(DropOutMenu::handleToggle));
DropOutMenu(size_t in_x, size_t in_y, size_t in_w, size_t in_h, Widget *p, char *name) : Widget(in_x, in_y, in_w, in_h, p, "buttonbg")
{
Button *action = new Button(0, 0, w, h, nullptr, name);
action->setParent(this);
children.push_back(action);
action->clicked.connect(toggle);
}
virtual void add_child(Widget *ch) override
{
assert(ch != nullptr);
size_t ch_y;
if (not children.empty())
ch_y = children.back()->getY() + children.back()->getHeight();
else
ch_y = y;
children.push_back(ch);
ch->move(0, ch_y);
ch->resize(w, -1);
if (dropped)
ch->show();
else
ch->hide();
}
virtual void resize(size_t new_w, size_t new_h) override
{
Widget::resize(new_w, new_h);
children[0]->resize(w, h);
}
void handleToggle(Event ev)
{
if (dropped)
handlePullUp(ev);
else
handleDropOut(ev);
}
void handleDropOut(Event ev)
{
dropped = true;
for (size_t i = 1; i < children.size(); ++i)
children[i]->show();
}
void handlePullUp(Event ev)
{
dropped = false;
for (size_t i = 1; i < children.size(); ++i)
children[i]->hide();
}
};
}