Adds yoga widget macro and nwidget
This commit is contained in:
parent
3b673b2ba3
commit
bd246c77ee
@ -16,6 +16,7 @@
|
||||
"../src/cpp/core/YogaWidget/yogawidget.cpp",
|
||||
# wrapped cpps
|
||||
"../src/cpp/QtGui/QApplication/qapplication_wrap.cpp",
|
||||
"../src/cpp/QtGui/QWidget/nwidget.cpp",
|
||||
"../src/cpp/QtGui/QWidget/qwidget_wrap.cpp",
|
||||
'../src/cpp/core/FlexLayout/flexnode_wrap.cpp',
|
||||
'../src/cpp/core/FlexLayout/flexlayout_wrap.cpp',
|
||||
|
||||
1
src/cpp/QtGui/QWidget/nwidget.cpp
Normal file
1
src/cpp/QtGui/QWidget/nwidget.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "nwidget_moc.h"
|
||||
15
src/cpp/QtGui/QWidget/nwidget.h
Normal file
15
src/cpp/QtGui/QWidget/nwidget.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QWidget>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
|
||||
class NWidget: public QWidget, public YogaWidget
|
||||
{
|
||||
|
||||
public:
|
||||
using QWidget::QWidget; //inherit all constructors of QWidget
|
||||
SET_YOGA_WIDGET_Q_PROPERTIES
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
||||
96
src/cpp/QtGui/QWidget/nwidget_moc.h
Normal file
96
src/cpp/QtGui/QWidget/nwidget_moc.h
Normal file
@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
** Meta object code from reading C++ file 'nwidget.h'
|
||||
**
|
||||
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.12.1)
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
#include "nwidget.h"
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qmetatype.h>
|
||||
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||
#error "The header file 'nwidget.h' doesn't include <QObject>."
|
||||
#elif Q_MOC_OUTPUT_REVISION != 67
|
||||
#error "This file was generated using the moc from 5.12.1. It"
|
||||
#error "cannot be used with the include files from this version of Qt."
|
||||
#error "(The moc has changed too much.)"
|
||||
#endif
|
||||
|
||||
QT_BEGIN_MOC_NAMESPACE
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
struct qt_meta_stringdata_NWidget_t {
|
||||
QByteArrayData data[1];
|
||||
char stringdata0[8];
|
||||
};
|
||||
#define QT_MOC_LITERAL(idx, ofs, len) \
|
||||
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
|
||||
qptrdiff(offsetof(qt_meta_stringdata_NWidget_t, stringdata0) + ofs \
|
||||
- idx * sizeof(QByteArrayData)) \
|
||||
)
|
||||
static const qt_meta_stringdata_NWidget_t qt_meta_stringdata_NWidget = {
|
||||
{
|
||||
QT_MOC_LITERAL(0, 0, 7) // "NWidget"
|
||||
|
||||
},
|
||||
"NWidget"
|
||||
};
|
||||
#undef QT_MOC_LITERAL
|
||||
|
||||
static const uint qt_meta_data_NWidget[] = {
|
||||
|
||||
// content:
|
||||
8, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
0, 0, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
0, // signalCount
|
||||
|
||||
0 // eod
|
||||
};
|
||||
|
||||
void NWidget::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
Q_UNUSED(_o);
|
||||
Q_UNUSED(_id);
|
||||
Q_UNUSED(_c);
|
||||
Q_UNUSED(_a);
|
||||
}
|
||||
|
||||
QT_INIT_METAOBJECT const QMetaObject NWidget::staticMetaObject = { {
|
||||
&QWidget::staticMetaObject,
|
||||
qt_meta_stringdata_NWidget.data,
|
||||
qt_meta_data_NWidget,
|
||||
qt_static_metacall,
|
||||
nullptr,
|
||||
nullptr
|
||||
} };
|
||||
|
||||
|
||||
const QMetaObject *NWidget::metaObject() const
|
||||
{
|
||||
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
|
||||
}
|
||||
|
||||
void *NWidget::qt_metacast(const char *_clname)
|
||||
{
|
||||
if (!_clname) return nullptr;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_NWidget.stringdata0))
|
||||
return static_cast<void*>(this);
|
||||
if (!strcmp(_clname, "YogaWidget"))
|
||||
return static_cast< YogaWidget*>(this);
|
||||
return QWidget::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
int NWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = QWidget::qt_metacall(_c, _id, _a);
|
||||
return _id;
|
||||
}
|
||||
QT_WARNING_POP
|
||||
QT_END_MOC_NAMESPACE
|
||||
@ -3,6 +3,12 @@
|
||||
|
||||
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
|
||||
|
||||
/*
|
||||
|
||||
This macro adds common QWidgets exported methods
|
||||
The exported methods are taken into this macro to avoid writing them in each and every widget we export.
|
||||
*/
|
||||
|
||||
#ifndef QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
\
|
||||
|
||||
@ -9,13 +9,14 @@ Napi::Object QWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
char CLASSNAME[] = "QWidget";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QWidget* QWidgetWrap::getInternalInstance() {
|
||||
NWidget* QWidgetWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
@ -27,12 +28,12 @@ QWidgetWrap::QWidgetWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QWidg
|
||||
if(info[0].IsObject()){
|
||||
Napi::Object object_parent = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* w_parent = Napi::ObjectWrap<QWidgetWrap>::Unwrap(object_parent);
|
||||
this->instance = new QWidget(w_parent->getInternalInstance()); //this sets the parent to current widget
|
||||
this->instance = new NWidget(w_parent->getInternalInstance()); //this sets the parent to current widget
|
||||
}else{
|
||||
extrautils::throwTypeError(env, "Wrong type of arguments");
|
||||
}
|
||||
}else if (info.Length() == 0){
|
||||
this->instance = new QWidget();
|
||||
this->instance = new NWidget();
|
||||
}else {
|
||||
extrautils::throwTypeError(env, "Wrong number of arguments");
|
||||
}
|
||||
|
||||
@ -1,22 +1,22 @@
|
||||
#ifndef QWIDGET_WRAP_H
|
||||
#define QWIDGET_WRAP_H
|
||||
#pragma once
|
||||
|
||||
#include "qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
#include <napi.h>
|
||||
#include <QWidget>
|
||||
#include "nwidget.h"
|
||||
|
||||
class QWidgetWrap : public Napi::ObjectWrap<QWidgetWrap>{
|
||||
private:
|
||||
QWidget* instance;
|
||||
NWidget* instance;
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QWidgetWrap(const Napi::CallbackInfo& info);
|
||||
~QWidgetWrap();
|
||||
QWidget* getInternalInstance();
|
||||
NWidget* getInternalInstance();
|
||||
//class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef N_LABEL_H
|
||||
#define N_LABEL_H
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include "src/cpp/core/YogaWidget/yogawidget.h"
|
||||
@ -14,4 +14,3 @@ public:
|
||||
};
|
||||
|
||||
|
||||
#endif // N_LABEL_H
|
||||
|
||||
@ -15,6 +15,7 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("setText", &QLabelWrap::setText),
|
||||
InstanceMethod("getFlexNode", &QLabelWrap::getFlexNode),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
@ -69,12 +70,3 @@ Napi::Value QLabelWrap::setText(const Napi::CallbackInfo& info) {
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
|
||||
Napi::Value QLabelWrap::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();
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
#ifndef QLABEL_WRAP_H
|
||||
#define QLABEL_WRAP_H
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
#include "nlabel.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
|
||||
class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
||||
private:
|
||||
@ -17,9 +18,8 @@ class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
||||
//wrapped methods
|
||||
Napi::Value setWordWrap(const Napi::CallbackInfo& info);
|
||||
Napi::Value setText(const Napi::CallbackInfo& info);
|
||||
Napi::Value getFlexNode(const Napi::CallbackInfo& info);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
#endif
|
||||
32
src/cpp/core/YogaWidget/yogawidget_macro.h
Normal file
32
src/cpp/core/YogaWidget/yogawidget_macro.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/cpp/core/FlexLayout/flexnode_wrap.h"
|
||||
|
||||
/*
|
||||
|
||||
This macro adds common YogaWidget's exported methods
|
||||
The exported methods are taken into this macro to avoid writing them in each and every widget we export.
|
||||
*/
|
||||
|
||||
#ifndef YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
#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();\
|
||||
}\
|
||||
|
||||
#endif //YOGAWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
#ifndef YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
#define YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
\
|
||||
InstanceMethod("getFlexNode", &WidgetWrapName::getFlexNode), \
|
||||
|
||||
|
||||
#endif // YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
|
||||
Loading…
Reference in New Issue
Block a user