Convert flexNode to Napi::External.
This commit is contained in:
parent
1bdf06c4c4
commit
c651775eca
@ -19,7 +19,6 @@
|
||||
# wrapped cpps
|
||||
"../src/cpp/QtGui/QApplication/qapplication_wrap.cpp",
|
||||
"../src/cpp/QtGui/QWidget/qwidget_wrap.cpp",
|
||||
'../src/cpp/core/FlexLayout/flexnode_wrap.cpp',
|
||||
'../src/cpp/core/FlexLayout/flexlayout_wrap.cpp',
|
||||
"../src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp",
|
||||
"../src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp",
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#include "qlabel_wrap.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
#include "src/cpp/core/FlexLayout/flexnode_wrap.h"
|
||||
#include <QWidget>
|
||||
|
||||
Napi::FunctionReference QLabelWrap::constructor;
|
||||
|
||||
@ -50,11 +50,11 @@ Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info){
|
||||
Napi::Object widgetObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* centralWidget = Napi::ObjectWrap<QWidgetWrap>::Unwrap(widgetObject);
|
||||
|
||||
Napi::Object flexNodeObject = info[1].As<Napi::Object>();
|
||||
FlexNodeWrap* flexNodeWrap = Napi::ObjectWrap<FlexNodeWrap>::Unwrap(flexNodeObject);
|
||||
Napi::External<YGNode> flexNodeObject = info[1].As<Napi::External<YGNode>>();
|
||||
YGNodeRef flexNodeRef = flexNodeObject.Data();
|
||||
|
||||
YGNodeRef node = this->instance->getFlexNode();
|
||||
YGNodeInsertChild(node, flexNodeWrap->getInternalInstance(), 0);
|
||||
YGNodeInsertChild(node, flexNodeRef, 0);
|
||||
this->instance->setCentralWidget(centralWidget->getInternalInstance());
|
||||
|
||||
return env.Null();
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#include "flexlayout_wrap.h"
|
||||
#include "flexnode_wrap.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
#include <QDebug>
|
||||
@ -50,10 +49,10 @@ Napi::Value FlexLayoutWrap::addWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object qwidgetObject = info[0].As<Napi::Object>();
|
||||
Napi::Object childFlexNodeObject = info[1].As<Napi::Object>();
|
||||
Napi::External<YGNode> childFlexNodeObject = info[1].As<Napi::External<YGNode>>();
|
||||
QWidgetWrap* widget = Napi::ObjectWrap<QWidgetWrap>::Unwrap(qwidgetObject);
|
||||
FlexNodeWrap* childFlexNodeWrap = Napi::ObjectWrap<FlexNodeWrap>::Unwrap(childFlexNodeObject);
|
||||
this->instance->addWidget(widget->getInternalInstance(),childFlexNodeWrap->getInternalInstance());
|
||||
YGNodeRef childNodeRef = childFlexNodeObject.Data();
|
||||
this->instance->addWidget(widget->getInternalInstance(),childNodeRef);
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
@ -62,9 +61,10 @@ Napi::Value FlexLayoutWrap::setFlexNode(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object flexNodeObject = info[0].As<Napi::Object>();
|
||||
FlexNodeWrap* flexNodeWrap = Napi::ObjectWrap<FlexNodeWrap>::Unwrap(flexNodeObject);
|
||||
this->instance->setFlexNode(flexNodeWrap->getInternalInstance());
|
||||
Napi::External<YGNode> flexNodeObject = info[0].As<Napi::External<YGNode>>();
|
||||
YGNodeRef flexNodeRef = flexNodeObject.Data();
|
||||
|
||||
this->instance->setFlexNode(flexNodeRef);
|
||||
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
#include "flexnode_wrap.h"
|
||||
#include <QDebug>
|
||||
|
||||
Napi::FunctionReference FlexNodeWrap::constructor;
|
||||
|
||||
void FlexNodeWrap::init(Napi::Env env) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "FlexNode";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("debugValue", &FlexNodeWrap::debugValue),
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
}
|
||||
|
||||
YGNodeRef FlexNodeWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
FlexNodeWrap::FlexNodeWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<FlexNodeWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
}
|
||||
|
||||
Napi::Value FlexNodeWrap::debugValue(const Napi::CallbackInfo& info) {
|
||||
uint64_t addr = reinterpret_cast<long>(this->getInternalInstance());
|
||||
return Napi::Number::New(info.Env(), addr);
|
||||
}
|
||||
|
||||
FlexNodeWrap::~FlexNodeWrap() {
|
||||
delete this->instance;
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
#include <napi.h>
|
||||
#include "deps/yoga/YGNode.h"
|
||||
|
||||
/*
|
||||
|
||||
NAPI Wrapper class to export YGNodeRef/Yoga/Flex Node of a Widget
|
||||
*/
|
||||
|
||||
|
||||
//ABSTRACT CLASS
|
||||
class FlexNodeWrap : public Napi::ObjectWrap<FlexNodeWrap>{
|
||||
public:
|
||||
YGNodeRef instance;
|
||||
static void init(Napi::Env env);
|
||||
FlexNodeWrap(const Napi::CallbackInfo& info);
|
||||
~FlexNodeWrap();
|
||||
YGNodeRef getInternalInstance();
|
||||
//class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
Napi::Value debugValue(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/cpp/core/FlexLayout/flexnode_wrap.h"
|
||||
|
||||
/*
|
||||
|
||||
This macro adds common YogaWidget's exported methods
|
||||
@ -12,12 +10,9 @@
|
||||
#define YOGAWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
Napi::Value getFlexNode(const Napi::CallbackInfo& info) {\
|
||||
Napi::EscapableHandleScope scope(info.Env());\
|
||||
Napi::Value arg = info[0];\
|
||||
Napi::Object flexNodeObject = FlexNodeWrap::constructor.New({ arg });\
|
||||
FlexNodeWrap* flexNodeWrap = FlexNodeWrap::Unwrap(flexNodeObject);\
|
||||
flexNodeWrap->instance = this->instance->getFlexNode();\
|
||||
return scope.Escape(napi_value(flexNodeObject)).ToObject();\
|
||||
YGNodeRef node = this->instance->getFlexNode(); \
|
||||
Napi::Value yogaNodeRef = Napi::External<YGNode>::New(info.Env(), node); \
|
||||
return yogaNodeRef; \
|
||||
}\
|
||||
|
||||
#endif //YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
@ -9,14 +9,12 @@
|
||||
#include "src/cpp/QtWidgets/QProgressBar/qprogressbar_wrap.h"
|
||||
#include "src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h"
|
||||
#include "src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.h"
|
||||
#include "src/cpp/core/FlexLayout/flexnode_wrap.h"
|
||||
#include "src/cpp/core/FlexLayout/flexlayout_wrap.h"
|
||||
#include <napi.h>
|
||||
|
||||
// These cant be instantiated in JS Side
|
||||
void InitPrivateHelpers(Napi::Env env){
|
||||
QLayoutWrap::init(env); //Abstact class wrapper for pointing to any layout
|
||||
FlexNodeWrap::init(env); //Abstact class wrapper for pointing to flex/yoga node
|
||||
}
|
||||
|
||||
Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { FlexNode } from "../../core/FlexLayout/FlexNode";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
import { FlexNode } from "../../core/YogaWidget";
|
||||
|
||||
export const QMainWindowEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
@ -9,7 +9,6 @@ export const QMainWindowEvents = Object.freeze({
|
||||
export class QMainWindow extends NodeWidget {
|
||||
native: any;
|
||||
protected centralWidget?: NodeWidget;
|
||||
protected centralWidgetFlexNode?: FlexNode;
|
||||
constructor(parent?: NodeWidget) {
|
||||
let native;
|
||||
if (parent) {
|
||||
@ -26,11 +25,10 @@ export class QMainWindow extends NodeWidget {
|
||||
}
|
||||
|
||||
setCentralWidget(widget: NodeWidget) {
|
||||
this.centralWidgetFlexNode = widget.getFlexNode();
|
||||
this.centralWidget = widget;
|
||||
this.native.setCentralWidget(
|
||||
this.centralWidget.native,
|
||||
this.centralWidgetFlexNode.native
|
||||
widget.getFlexNode()
|
||||
);
|
||||
}
|
||||
setFixedSize(width: number, height: number) {
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
import { Component } from "../../Component";
|
||||
|
||||
export class FlexNode extends Component {
|
||||
native: any;
|
||||
constructor(nativeNode: any) {
|
||||
super();
|
||||
this.native = nativeNode;
|
||||
}
|
||||
debugValue = (): void => {
|
||||
return this.native.debugValue();
|
||||
};
|
||||
}
|
||||
@ -1,21 +1,18 @@
|
||||
import addon from "../addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { FlexNode } from "./FlexNode";
|
||||
import { NodeLayout } from "../../QtWidgets/QLayout";
|
||||
import { FlexNode } from "../YogaWidget";
|
||||
|
||||
export class FlexLayout extends NodeLayout {
|
||||
native = new addon.FlexLayout();
|
||||
protected flexNode?: FlexNode;
|
||||
protected childFlexNodes = new Set<FlexNode>();
|
||||
|
||||
addWidget = (childWidget: NodeWidget, childFlexNode: FlexNode) => {
|
||||
this.children.add(childWidget);
|
||||
this.childFlexNodes.add(childFlexNode);
|
||||
|
||||
this.native.addWidget(childWidget.native, childFlexNode.native);
|
||||
this.native.addWidget(childWidget.native, childFlexNode);
|
||||
};
|
||||
setFlexNode = (flexNode: FlexNode) => {
|
||||
this.flexNode = flexNode;
|
||||
this.native.setFlexNode(flexNode.native);
|
||||
this.native.setFlexNode(flexNode);
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { Component } from "../Component";
|
||||
import { FlexNode } from "../FlexLayout/FlexNode";
|
||||
|
||||
export type FlexNode = {};
|
||||
export abstract class YogaWidget extends Component {
|
||||
getFlexNode = (): FlexNode => {
|
||||
return new FlexNode(this.native.getFlexNode());
|
||||
return this.native.getFlexNode();
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user