From ab9b080fbd3b8776e95bd96476be9eed86b96676 Mon Sep 17 00:00:00 2001 From: Atul R Date: Tue, 19 Nov 2019 02:30:03 +0100 Subject: [PATCH] quick fix for layout (#209) --- src/cpp/lib/core/FlexLayout/flexlayout.cpp | 9 +++++++-- src/demo.ts | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cpp/lib/core/FlexLayout/flexlayout.cpp b/src/cpp/lib/core/FlexLayout/flexlayout.cpp index 01bacda7e..f029968ba 100644 --- a/src/cpp/lib/core/FlexLayout/flexlayout.cpp +++ b/src/cpp/lib/core/FlexLayout/flexlayout.cpp @@ -10,7 +10,6 @@ FlexLayout::FlexLayout(QWidget* parentWidget, YGNodeRef parentNode) : QLayout(parentWidget) { this->node = parentNode; - this->setSizeConstraint(QLayout::SetFixedSize); } FlexLayout::~FlexLayout() { @@ -148,7 +147,14 @@ void FlexLayout::setGeometry(const QRect& rect) { if (!this->node) { return; } + if (this->sizeConstraint() != QLayout::SetFixedSize) { + YGNodeStyleSetHeight(this->node, rect.height()); + YGNodeStyleSetWidth(this->node, rect.width()); + } + calculateLayout(); + QRect calculatedRect = flexutils::getFlexNodeGeometry(this->node); + QLayout::setGeometry(calculatedRect); uint count = YGNodeGetChildCount(this->node); @@ -159,7 +165,6 @@ void FlexLayout::setGeometry(const QRect& rect) { QLayoutItem* childItem = ctx->layoutItem(); childItem->setGeometry(childRect); } - QLayout::setGeometry(rect); } void FlexLayout::setFlexNode(YGNodeRef parentNode) { this->node = parentNode; } diff --git a/src/demo.ts b/src/demo.ts index 338d4d139..379c1e3f2 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -41,6 +41,7 @@ label.setInlineStyle(`border: 2px solid green;padding: 10;`); center.setLayout(new FlexLayout()); center.layout?.addWidget(label); +center.layout?.setProperty('sizeConstraint', 3); scrollArea.setWidget(center); win.setCentralWidget(scrollArea); win.show();