44#include " spdlog/spdlog.h"
55#include " src/cpp/core/YogaWidget/yogawidget.h"
66
7- FlexLayout::NodeContext * FlexLayout::getNodeContext (YGNodeRef node)
7+ FlexLayout::NodeContext* FlexLayout::getNodeContext (YGNodeRef node)
88{
99 if (!node){
1010 return nullptr ;
@@ -16,7 +16,6 @@ FlexLayout::NodeContext *FlexLayout::getNodeContext(YGNodeRef node)
1616
1717FlexLayout::FlexLayout (QWidget *parentWidget, YGNodeRef parentNode): QLayout(parentWidget)
1818{
19- // spdlog::set_level(spdlog::level::off);
2019 this ->node = parentNode;
2120}
2221
@@ -58,7 +57,6 @@ QLayoutItem *FlexLayout::itemAt(int index) const
5857 YGNodeRef childNode = YGNodeGetChild (this ->node , static_cast <uint>(index));
5958 NodeContext *ctx = getNodeContext (childNode);
6059 if (!ctx){
61- // spdlog::info("flexlayout: itemAt null context {}",index);
6260 return nullptr ;
6361 }
6462 return ctx->item ;
@@ -91,14 +89,13 @@ void FlexLayout::addWidget(QWidget* childWidget, YGNodeRef childNode)
9189 spdlog::warn (" Flex layout's parent yoga node not set yet. Set it using setFlexNode. Child widget will not be added to Flex Layout" );
9290 return ;
9391 }
94- // spdlog::info("flexlayout: addWidget Object: {}",childWidget->metaObject()->className());
95-
9692 uint count = YGNodeGetChildCount (this ->node );
9793 YGNodeInsertChild (this ->node ,childNode, count);
9894 QLayoutItem* layoutItem = new QWidgetItem (childWidget);
9995 NodeContext* childContext = new NodeContext (layoutItem);
10096 YGNodeSetContext (childNode, static_cast <void *>(childContext));
10197 QLayout::addWidget (childWidget);
98+ this ->invalidate ();
10299}
103100
104101void FlexLayout::removeWidget (QWidget* childWidget, YGNodeRef childNode)
@@ -114,6 +111,7 @@ void FlexLayout::removeWidget(QWidget* childWidget, YGNodeRef childNode)
114111 }
115112 YGNodeRemoveChild (this ->node , childNode);
116113 QLayout::removeWidget (childWidget);
114+ this ->invalidate ();
117115}
118116
119117void FlexLayout::insertChildBefore (QWidget* childWidget, YGNodeRef beforeChildNode, YGNodeRef childNode)
@@ -135,14 +133,30 @@ void FlexLayout::insertChildBefore(QWidget* childWidget, YGNodeRef beforeChildNo
135133 NodeContext* childContext = new NodeContext (layoutItem);
136134 YGNodeSetContext (childNode, static_cast <void *>(childContext));
137135 QLayout::addWidget (childWidget);
136+ this ->invalidate ();
138137}
139138
139+
140+ YGNodeRef FlexLayout::getRootNode (YGNodeRef node){
141+ YGNodeRef parent = node->getOwner ();
142+ if (!parent){
143+ return node;
144+ }else {
145+ return getRootNode (parent);
146+ }
147+ }
148+
149+
140150void FlexLayout::setGeometry (const QRect &rect)
141151{
142152 if (!this ->node ){
143153 return ;
144154 }
145-
155+ YGNodeRef rootNode = getRootNode (this ->node );
156+ QWidget* parentWidget = this ->parentWidget ();
157+ QWidget* window = parentWidget->window ();
158+ YGDirection direction = YGNodeStyleGetDirection (rootNode);
159+ YGNodeCalculateLayout (rootNode,window->width (),window->height (),direction);
146160 uint count = YGNodeGetChildCount (this ->node );
147161
148162 for (uint i = 0 ; i < count; ++i) {
0 commit comments