From 3fe8f17f94a9f5d14e20516a32308776f57ed6b7 Mon Sep 17 00:00:00 2001 From: Wyatt Kirby Date: Thu, 25 Feb 2021 16:43:45 -0500 Subject: [PATCH] Fix incorrect behavior of minimum size for yoga layout (#814) --- src/cpp/lib/core/FlexLayout/flexlayout.cpp | 52 +++++++++++----------- src/lib/QtWidgets/QWidget.ts | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/cpp/lib/core/FlexLayout/flexlayout.cpp b/src/cpp/lib/core/FlexLayout/flexlayout.cpp index e2ecfb7f7..e60917ce2 100644 --- a/src/cpp/lib/core/FlexLayout/flexlayout.cpp +++ b/src/cpp/lib/core/FlexLayout/flexlayout.cpp @@ -147,16 +147,18 @@ QSize FlexLayout::sizeHint() const { QSize FlexLayout::minimumSize() const { calculateLayout(); - QSize minSize = QSize(YGNodeLayoutGetWidth(this->node), - YGNodeLayoutGetHeight(this->node)); + QSize minSize = QSize(YGNodeStyleGetMinWidth(this->node).value, + YGNodeStyleGetMinHeight(this->node).value); return minSize; } void FlexLayout::setGeometry(const QRect& rect) { this->cachedRect = rect; + if (this->throttleTimer.isActive()) { return; } + this->throttleTimer.start(10); // This will call performLayout and throttle requests between 10ms. } @@ -165,32 +167,30 @@ void FlexLayout::performLayout() { if (!this->node) { return; } + QRect rect = this->cachedRect; - if (!rect.isValid() || rect != geometry()) { - bool isSizeControlled = flexutils::isFlexNodeSizeControlled(this->node); - YGValue prevStyleMinWidth = YGNodeStyleGetMinWidth(this->node); - YGValue prevStyleMinHeight = YGNodeStyleGetMinHeight(this->node); - if (isSizeControlled) { - YGNodeMarkDirtyAndPropogateToDescendants(this->node); - YGNodeStyleSetMinHeight(this->node, rect.height()); - YGNodeStyleSetMinWidth(this->node, rect.width()); - } - - calculateLayout(); - - uint count = YGNodeGetChildCount(this->node); - for (uint i = 0; i < count; ++i) { - YGNode* childNode = YGNodeGetChild(this->node, i); - QRect childRect = flexutils::getFlexNodeGeometry(childNode); - FlexNodeContext* ctx = flexutils::getFlexNodeContext(childNode); - QLayoutItem* childItem = ctx->layoutItem(); - childItem->setGeometry(childRect); - } - if (isSizeControlled) { - restoreNodeMinStyle(prevStyleMinWidth, prevStyleMinHeight); - } + if (flexutils::isFlexNodeSizeControlled(this->node)) { + YGNodeMarkDirtyAndPropogateToDescendants(this->node); + YGNodeStyleSetHeight(this->node, rect.height()); + YGNodeStyleSetWidth(this->node, rect.width()); + } + + calculateLayout(); + + QRect calculatedRect = flexutils::getFlexNodeGeometry(this->node); + + // Set our own geometry to calculated size + QLayout::setGeometry(calculatedRect); + + // Iterate over children and set their geometry + uint count = YGNodeGetChildCount(this->node); + for (uint i = 0; i < count; ++i) { + YGNode* childNode = YGNodeGetChild(this->node, i); + QRect childRect = flexutils::getFlexNodeGeometry(childNode); + FlexNodeContext* ctx = flexutils::getFlexNodeContext(childNode); + QLayoutItem* childItem = ctx->layoutItem(); + childItem->setGeometry(childRect); } - QLayout::setGeometry(rect); } void FlexLayout::setFlexNode(YGNodeRef parentNode) { this->node = parentNode; } diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index 32985730f..63793a1cc 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -19,7 +19,7 @@ import memoizeOne from 'memoize-one'; import { QGraphicsEffect } from './QGraphicsEffect'; /** - + > Abstract class to add functionalities common to all Widgets. **This class implements all methods, properties of Qt's [QWidget class](https://doc.qt.io/qt-5/qwidget.html) so that it can be inherited by all widgets**