forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflexlayout.h
More file actions
49 lines (43 loc) · 1.52 KB
/
flexlayout.h
File metadata and controls
49 lines (43 loc) · 1.52 KB
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
#pragma once
#include "deps/yoga/YGNode.h"
#include <QLayout>
/*
FlexLayout is a custom Layout built for QT. This layout will be used to layout qt widgets using facebook's yoga library.
Thus giving ability to layout Qt Widgets using Flexbox.
Usage:
QWidget *container = new QWidget();
YGNodeRef root = YGNodeNew();
YGNodeRef child1 = YGNodeNew();
YGNodeRef child2 = YGNodeNew();
FlexLayout * flayout = new FlexLayout(container,root);
// or FlexLayout * flayout = new FlexLayout(container);
// or FlexLayout *flayout = new FlexLayout();
flayout->addWidget(btn1, child1);
flayout->addWidget(btn2, child2);
*/
class FlexLayout: public QLayout
{
private:
YGNodeRef node;
public:
struct NodeContext
{
NodeContext(QLayoutItem *i) {
item = i;
}
QLayoutItem *item;
};
FlexLayout(QWidget* parentWidget=nullptr, YGNodeRef parentNode=nullptr);
~FlexLayout() override;
QSize sizeHint() const override;
void addItem(QLayoutItem *) override;
QLayoutItem *itemAt(int index) const override;
QLayoutItem *takeAt(int index) override;
int count() const override;
void addWidget(QWidget* childWidget, YGNodeRef childNode);
void insertChildBefore(QWidget* childWidget, YGNodeRef beforeChildNode, YGNodeRef childNode);
void removeWidget(QWidget* childWidget, YGNodeRef childNode);
void setGeometry(const QRect &rect) override;
void setFlexNode(YGNodeRef parentNode);
static NodeContext* getNodeContext(YGNodeRef node);
};