diff --git a/demo.ts b/demo.ts index 3d2cbe578..73c82c7da 100644 --- a/demo.ts +++ b/demo.ts @@ -94,12 +94,11 @@ const testFlexLayout = () => { color:white; qproperty-alignSelf: 'stretch'; `); + view.setLayout(flayout); flayout.addWidget(label2, label2.getFlexNode()); flayout.addWidget(label, label.getFlexNode()); - view.setLayout(flayout); - win.show(); return win; }; diff --git a/examples/calculator/index.ts b/examples/calculator/index.ts index ec7921260..88512fbdb 100644 --- a/examples/calculator/index.ts +++ b/examples/calculator/index.ts @@ -6,10 +6,6 @@ import { QLabel } from "../../src/lib/QtWidgets/QLabel"; const globals = global as any; -// Main Window -const win = new QMainWindow(); -win.resize(400, 600); - const getButton = ( label: string, value: number | string, @@ -24,6 +20,10 @@ const getButton = ( }; }; +// Main Window +const win = new QMainWindow(); +win.resize(400, 600); + // Top Row const btnClear = getButton("AC", "AC", "command"); const resultText = new QLabel(); @@ -34,9 +34,9 @@ row0.setStyleSheet(` `); const row0Layout = new FlexLayout(); row0Layout.setFlexNode(row0.getFlexNode()); +row0.setLayout(row0Layout); row0Layout.addWidget(btnClear.ui, btnClear.ui.getFlexNode()); row0Layout.addWidget(resultText, resultText.getFlexNode()); -row0.setLayout(row0Layout); // First Row const btn7 = getButton("7", 7, "value"); diff --git a/src/cpp/core/FlexLayout/flexlayout.cpp b/src/cpp/core/FlexLayout/flexlayout.cpp index c95f1dff9..b709cfe4f 100644 --- a/src/cpp/core/FlexLayout/flexlayout.cpp +++ b/src/cpp/core/FlexLayout/flexlayout.cpp @@ -2,6 +2,7 @@ #include #include #include "spdlog/spdlog.h" +#include "src/cpp/core/YogaWidget/yogawidget.h" FlexLayout::NodeContext *FlexLayout::getNodeContext(YGNodeRef node) { @@ -47,7 +48,12 @@ QSize FlexLayout::sizeHint() const{ } void FlexLayout::addItem(QLayoutItem * item){ - spdlog::warn("Unsupported method addItem. item: {}. Use FlexLayout::addWidget instead", reinterpret_cast(item)); + QWidget* childWidget = item->widget(); + if(childWidget){ + spdlog::info("flexlayout: addItem - noop for: {}",childWidget->metaObject()->className()); + return; + } + spdlog::info("flexlayout: addItem - noop for: {}", reinterpret_cast(item)); } QLayoutItem *FlexLayout::itemAt(int index) const @@ -55,9 +61,11 @@ QLayoutItem *FlexLayout::itemAt(int index) const if(!this->node){ return nullptr; } + spdlog::info("flexlayout: itemAt {}",index); YGNodeRef childNode = YGNodeGetChild(this->node, static_cast(index)); NodeContext *ctx = getNodeContext(childNode); if(!ctx){ + spdlog::info("flexlayout: itemAt null context {}",index); return nullptr; } return ctx->item; @@ -69,6 +77,7 @@ QLayoutItem *FlexLayout::takeAt(int index) NodeContext *ctx = getNodeContext(childNode); QLayoutItem* childLayoutItem = ctx->item; YGNodeRemoveChild(this->node, childNode); + spdlog::info("flexlayout: takeAt ",index); delete ctx; return childLayoutItem; } @@ -79,6 +88,7 @@ int FlexLayout::count() const return 0; } float childCount = YGNodeGetChildCount(this->node); + spdlog::info("flexlayout: count {}",childCount); return static_cast(childCount); } @@ -89,11 +99,14 @@ 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(childContext)); + QLayout::addWidget(childWidget); } void FlexLayout::setGeometry(const QRect &rect) @@ -122,7 +135,7 @@ void FlexLayout::setGeometry(const QRect &rect) QWidget* childWidget = childLayoutItem->widget(); if(childWidget){ childWidget->setGeometry(childRect); - spdlog::info("Object: {}, rect: w:{}, h:{}, l:{}, t:{}",childWidget->metaObject()->className(),width,height,left,top); + spdlog::info("flexlayout setGeometry: {}, rect: w:{}, h:{}, l:{}, t:{}",childWidget->metaObject()->className(),width,height,left,top); }else { childLayoutItem->setGeometry(childRect); } diff --git a/src/cpp/core/FlexLayout/flexnode_wrap.h b/src/cpp/core/FlexLayout/flexnode_wrap.h index 4681c0be6..49fd5c705 100644 --- a/src/cpp/core/FlexLayout/flexnode_wrap.h +++ b/src/cpp/core/FlexLayout/flexnode_wrap.h @@ -1,5 +1,4 @@ -#ifndef FLEXNODE_WRAP_H -#define FLEXNODE_WRAP_H +#pragma once #include #include "deps/yoga/YGNode.h" @@ -22,4 +21,4 @@ class FlexNodeWrap : public Napi::ObjectWrap{ Napi::Value debugValue(const Napi::CallbackInfo& info); }; -#endif \ No newline at end of file +