adds web defaults for flex layout and int cleanups

This commit is contained in:
Atul R 2019-06-09 23:43:17 +02:00
parent a2bbc24f3d
commit 3b4ec63771
5 changed files with 13 additions and 14 deletions

View File

@ -108,6 +108,7 @@ rootViewFlexLayout.addWidget(row0, row0.getFlexNode());
rootViewFlexLayout.addWidget(row1, row1.getFlexNode());
rootViewFlexLayout.addWidget(row2, row2.getFlexNode());
rootViewFlexLayout.addWidget(row3, row3.getFlexNode());
rootViewFlexLayout.addWidget(row4, row4.getFlexNode());
rootView.setLayout(rootViewFlexLayout);
win.show();

View File

@ -39,8 +39,8 @@ Napi::Value setLayout(const Napi::CallbackInfo& info){ \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
Napi::Object layoutObject = info[0].As<Napi::Object>(); \
QLayoutWrap* layoutParent = Napi::ObjectWrap<QLayoutWrap>::Unwrap(layoutObject); \
this->instance->setLayout(layoutParent->getInternalInstance()); \
QLayoutWrap* layoutWrap = Napi::ObjectWrap<QLayoutWrap>::Unwrap(layoutObject); \
this->instance->setLayout(layoutWrap->getInternalInstance()); \
return env.Null(); \
} \
\

View File

@ -3,6 +3,7 @@
FlexItem::FlexItem()
{
this->node = YGNodeNew();
YGConfigSetUseWebDefaults(this->node->getConfig(),true);
}
YGNodeRef FlexItem::getFlexNode() const

View File

@ -1,5 +1,4 @@
#ifndef FLEX_ITEM_H
#define FLEX_ITEM_H
#pragma once
#include "deps/yoga/YGNode.h"
@ -8,7 +7,6 @@
In most cases you will use YogaWidget class instead of this one since it inherits from FlexItem.
*/
class FlexItem
{
YGNodeRef node;
@ -18,4 +16,3 @@ public:
~FlexItem();
};
#endif // FLEX_ITEM_H

View File

@ -40,8 +40,9 @@ QSize FlexLayout::sizeHint() const{
return QSize(0,0);
}
QSize size;
int width = static_cast<int>(YGNodeLayoutGetWidth(this->node));
int height = static_cast<int>(YGNodeLayoutGetHeight(this->node));
int width = static_cast<uint>(YGNodeLayoutGetWidth(this->node));
int height = static_cast<uint>(YGNodeLayoutGetHeight(this->node));
spdlog::info("flexlayout: sizeHint {}x{}",width, height);
size.setWidth(width);
size.setHeight(height);
return size;
@ -89,8 +90,7 @@ int FlexLayout::count() const
}
float childCount = YGNodeGetChildCount(this->node);
spdlog::info("flexlayout: count {}",childCount);
return static_cast<int>(childCount);
return static_cast<uint>(childCount);
}
void FlexLayout::addWidget(QWidget* childWidget, YGNodeRef childNode)
@ -123,10 +123,10 @@ void FlexLayout::setGeometry(const QRect &rect)
for (uint i = 0; i < count; ++i) {
YGNode *childNode = YGNodeGetChild(this->node, i);
int width = static_cast<int>(YGNodeLayoutGetWidth(childNode));
int height = static_cast<int>(YGNodeLayoutGetHeight(childNode));
int left = static_cast<int>(YGNodeLayoutGetLeft(childNode));
int top = static_cast<int>(YGNodeLayoutGetTop(childNode));
int width = static_cast<uint>(YGNodeLayoutGetWidth(childNode));
int height = static_cast<uint>(YGNodeLayoutGetHeight(childNode));
int left = static_cast<uint>(YGNodeLayoutGetLeft(childNode));
int top = static_cast<uint>(YGNodeLayoutGetTop(childNode));
QRect childRect(left, top,width, height);
NodeContext *ctx = getNodeContext(childNode);