forked from Chatterino/chatterino2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayoutHelper.hpp
50 lines (37 loc) · 947 Bytes
/
LayoutHelper.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
#pragma once
#include <boost/variant.hpp>
#include <QLayout>
class QWidget;
class QScrollArea;
namespace chatterino {
using LayoutItem = boost::variant<QWidget *, QLayoutItem *>;
using WidgetOrLayout = boost::variant<QWidget *, QLayout *>;
QWidget *wrapLayout(QLayout *layout);
QScrollArea *makeScrollArea(WidgetOrLayout item);
template <typename T>
T *makeLayout(std::initializer_list<LayoutItem> items)
{
auto t = new T;
for (auto &item : items)
{
switch (item.which())
{
case 0:
t->addItem(new QWidgetItem(boost::get<QWidget *>(item)));
break;
case 1:
t->addItem(boost::get<QLayoutItem *>(item));
break;
}
}
t->setContentsMargins(0, 0, 0, 0);
return t;
}
template <typename T, typename With>
T *makeWidget(With with)
{
auto t = new T;
with(t);
return t;
}
} // namespace chatterino