Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/cpp/lib/core/FlexLayout/flexlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand All @@ -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());
}
if (flexutils::isFlexNodeSizeControlled(this->node)) {
YGNodeMarkDirtyAndPropogateToDescendants(this->node);
YGNodeStyleSetHeight(this->node, rect.height());
YGNodeStyleSetWidth(this->node, rect.width());
}

calculateLayout();
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);
}
QRect calculatedRect = flexutils::getFlexNodeGeometry(this->node);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work!
This is what I have not done before

QRect calculatedRect = flexutils::getFlexNodeGeometry(this->node);

For some reason I thought rect passed into this function is the truth.


// 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; }
Expand Down
2 changes: 1 addition & 1 deletion src/lib/QtWidgets/QWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down