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
47 lines (40 loc) · 1.67 KB
/
flexlayout.h
File metadata and controls
47 lines (40 loc) · 1.67 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
#pragma once
#include <QLayout>
#include "core/Events/eventwidget_macro.h"
#include "deps/yoga/YGNode.h"
/*
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, public EventWidget {
private:
YGNodeRef node;
YGNodeRef getRootNode(YGNodeRef node) const;
void calculateLayout() const;
void restoreNodeMinStyle(YGValue &previousMinWidth,
YGValue &previousMinHeight);
public:
FlexLayout(QWidget *parentWidget = nullptr, YGNodeRef parentNode = nullptr);
~FlexLayout() override;
QSize sizeHint() const override;
QSize minimumSize() 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);
bool hasHeightForWidth() const override;
EVENTWIDGET_IMPLEMENTATIONS(QLayout)
};