fixes all flex layout issues
This commit is contained in:
parent
b537f763eb
commit
bf1aecfa8b
@ -9,25 +9,6 @@ class NMainWindow: public QMainWindow, public NodeWidget
|
||||
NODEWIDGET_IMPLEMENTATIONS(QMainWindow)
|
||||
public:
|
||||
using QMainWindow::QMainWindow; //inherit all constructors of QMainWindow
|
||||
private:
|
||||
void calculateLayout(){
|
||||
YGDirection direction = YGNodeStyleGetDirection(this->getFlexNode());
|
||||
YGNodeCalculateLayout(this->getFlexNode(),width(),height(),direction);
|
||||
}
|
||||
bool eventFilter(QObject *object, QEvent *event) { // This will be installed on mainwidgetwrap
|
||||
switch(event->type()) {
|
||||
case QEvent::LayoutRequest:
|
||||
case QEvent::ChildRemoved: {
|
||||
calculateLayout(); break;
|
||||
}
|
||||
default: ; // do nothing
|
||||
}
|
||||
return QMainWindow::eventFilter(object, event);
|
||||
}
|
||||
void resizeEvent(QResizeEvent * event){
|
||||
calculateLayout();
|
||||
QMainWindow::resizeEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -11,14 +11,14 @@ class NWidget: public QWidget, public NodeWidget
|
||||
public:
|
||||
using QWidget::QWidget;
|
||||
// https://doc.qt.io/qt-5/stylesheet-reference.html
|
||||
void paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QStyleOption opt;
|
||||
opt.init(this);
|
||||
QPainter p(this);
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
QWidget::paintEvent(e);
|
||||
}
|
||||
// void paintEvent(QPaintEvent *e)
|
||||
// {
|
||||
// QStyleOption opt;
|
||||
// opt.init(this);
|
||||
// QPainter p(this);
|
||||
// style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
// QWidget::paintEvent(e);
|
||||
// }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
|
||||
FlexLayout::NodeContext *FlexLayout::getNodeContext(YGNodeRef node)
|
||||
FlexLayout::NodeContext* FlexLayout::getNodeContext(YGNodeRef node)
|
||||
{
|
||||
if(!node){
|
||||
return nullptr;
|
||||
@ -16,7 +16,6 @@ FlexLayout::NodeContext *FlexLayout::getNodeContext(YGNodeRef node)
|
||||
|
||||
FlexLayout::FlexLayout(QWidget *parentWidget, YGNodeRef parentNode): QLayout(parentWidget)
|
||||
{
|
||||
// spdlog::set_level(spdlog::level::off);
|
||||
this->node = parentNode;
|
||||
}
|
||||
|
||||
@ -58,7 +57,6 @@ QLayoutItem *FlexLayout::itemAt(int index) const
|
||||
YGNodeRef childNode = YGNodeGetChild(this->node, static_cast<uint>(index));
|
||||
NodeContext *ctx = getNodeContext(childNode);
|
||||
if(!ctx){
|
||||
// spdlog::info("flexlayout: itemAt null context {}",index);
|
||||
return nullptr;
|
||||
}
|
||||
return ctx->item;
|
||||
@ -91,14 +89,13 @@ void FlexLayout::addWidget(QWidget* childWidget, YGNodeRef childNode)
|
||||
spdlog::warn("Flex layout's parent yoga node not set yet. Set it using setFlexNode. Child widget will not be added to Flex Layout");
|
||||
return;
|
||||
}
|
||||
// spdlog::info("flexlayout: addWidget Object: {}",childWidget->metaObject()->className());
|
||||
|
||||
uint count = YGNodeGetChildCount(this->node);
|
||||
YGNodeInsertChild(this->node,childNode, count);
|
||||
QLayoutItem* layoutItem = new QWidgetItem(childWidget);
|
||||
NodeContext* childContext = new NodeContext(layoutItem);
|
||||
YGNodeSetContext(childNode, static_cast<void *>(childContext));
|
||||
QLayout::addWidget(childWidget);
|
||||
this->invalidate();
|
||||
}
|
||||
|
||||
void FlexLayout::removeWidget(QWidget* childWidget, YGNodeRef childNode)
|
||||
@ -114,6 +111,7 @@ void FlexLayout::removeWidget(QWidget* childWidget, YGNodeRef childNode)
|
||||
}
|
||||
YGNodeRemoveChild(this->node, childNode);
|
||||
QLayout::removeWidget(childWidget);
|
||||
this->invalidate();
|
||||
}
|
||||
|
||||
void FlexLayout::insertChildBefore(QWidget* childWidget, YGNodeRef beforeChildNode, YGNodeRef childNode)
|
||||
@ -135,14 +133,30 @@ void FlexLayout::insertChildBefore(QWidget* childWidget, YGNodeRef beforeChildNo
|
||||
NodeContext* childContext = new NodeContext(layoutItem);
|
||||
YGNodeSetContext(childNode, static_cast<void *>(childContext));
|
||||
QLayout::addWidget(childWidget);
|
||||
this->invalidate();
|
||||
}
|
||||
|
||||
|
||||
YGNodeRef FlexLayout::getRootNode(YGNodeRef node){
|
||||
YGNodeRef parent = node->getOwner();
|
||||
if(!parent){
|
||||
return node;
|
||||
}else {
|
||||
return getRootNode(parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FlexLayout::setGeometry(const QRect &rect)
|
||||
{
|
||||
if(!this->node){
|
||||
return;
|
||||
}
|
||||
|
||||
YGNodeRef rootNode = getRootNode(this->node);
|
||||
QWidget* parentWidget = this->parentWidget();
|
||||
QWidget* window = parentWidget->window();
|
||||
YGDirection direction = YGNodeStyleGetDirection(rootNode);
|
||||
YGNodeCalculateLayout(rootNode,window->width(),window->height(),direction);
|
||||
uint count = YGNodeGetChildCount(this->node);
|
||||
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
|
||||
@ -24,6 +24,7 @@ class FlexLayout: public QLayout
|
||||
{
|
||||
private:
|
||||
YGNodeRef node;
|
||||
YGNodeRef getRootNode(YGNodeRef node);
|
||||
public:
|
||||
struct NodeContext
|
||||
{
|
||||
|
||||
@ -49,6 +49,11 @@ button.addEventListener("clicked", () => {
|
||||
const clipboard = QApplication.clipboard();
|
||||
console.log("clipboard: ", clipboard.text(QClipboardMode.Clipboard));
|
||||
clipboard.setText("yooooo", QClipboardMode.Clipboard);
|
||||
if (rootView.layout) {
|
||||
(rootView.layout as FlexLayout).removeWidget(dial);
|
||||
rootView.layout.invalidate();
|
||||
// rootView.update();
|
||||
}
|
||||
});
|
||||
|
||||
const nodeguiLogo = new QIcon(
|
||||
@ -111,7 +116,7 @@ win.setStyleSheet(`
|
||||
win.setWindowIcon(nodeguiLogo);
|
||||
win.setWindowTitle("NodeGUI Demo");
|
||||
|
||||
win.resize(400, 400);
|
||||
win.resize(400, 700);
|
||||
win.show();
|
||||
win.setWindowState(WindowState.WindowActive);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user