Adds type = native property to all wrapped elements in the nodegui world. Also fixes scaled QPixmap
This commit is contained in:
parent
401b99dc85
commit
3694215fcb
@ -1,4 +1,5 @@
|
||||
#include "qapplication_wrap.h"
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
|
||||
Napi::FunctionReference QApplicationWrap::constructor;
|
||||
int QApplicationWrap::argc = 0;
|
||||
@ -8,11 +9,11 @@ Napi::Object QApplicationWrap::init(Napi::Env env, Napi::Object exports)
|
||||
{
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QApplication";
|
||||
Napi::Function func =
|
||||
DefineClass(env, CLASSNAME,
|
||||
{InstanceMethod("processEvents", &QApplicationWrap::processEvents),
|
||||
InstanceMethod("exec", &QApplicationWrap::exec)});
|
||||
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("processEvents", &QApplicationWrap::processEvents),
|
||||
InstanceMethod("exec", &QApplicationWrap::exec),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
#include <QString>
|
||||
#include "deps/spdlog/spdlog.h"
|
||||
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
|
||||
Napi::FunctionReference QKeyEventWrap::constructor;
|
||||
|
||||
@ -10,7 +10,8 @@ Napi::Object QKeyEventWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QKeyEvent";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("text", &QKeyEventWrap::text),
|
||||
InstanceMethod("text", &QKeyEventWrap::text),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "qpixmap_wrap.h"
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
#include "deps/spdlog/spdlog.h"
|
||||
|
||||
Napi::FunctionReference QPixmapWrap::constructor;
|
||||
|
||||
@ -10,6 +11,7 @@ Napi::Object QPixmapWrap::init(Napi::Env env, Napi::Object exports)
|
||||
Napi::Function func = DefineClass(env, CLASSNAME,{
|
||||
InstanceMethod("load", &QPixmapWrap::load),
|
||||
InstanceMethod("scaled",&QPixmapWrap::scaled),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <napi.h>
|
||||
#include <QPixmap>
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
|
||||
class QPixmapWrap : public Napi::ObjectWrap<QPixmapWrap> {
|
||||
private:
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
|
||||
#include "src/cpp/core/YogaWidget/yogawidget_macro.h"
|
||||
#include "src/cpp/core/Events/eventwidget_macro.h"
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
/*
|
||||
|
||||
This macro adds common QWidgets exported methods
|
||||
@ -128,6 +129,7 @@ Napi::Value update(const Napi::CallbackInfo& info){ \
|
||||
\
|
||||
YOGAWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE \
|
||||
InstanceMethod("show", &WidgetWrapName::show), \
|
||||
InstanceMethod("resize",&WidgetWrapName::resize), \
|
||||
InstanceMethod("close",&WidgetWrapName::close), \
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "qgridlayout_wrap.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
|
||||
Napi::FunctionReference QGridLayoutWrap::constructor;
|
||||
|
||||
@ -8,7 +9,8 @@ Napi::Object QGridLayoutWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QGridLayout";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("addWidget", &QGridLayoutWrap::addWidget)
|
||||
InstanceMethod("addWidget", &QGridLayoutWrap::addWidget),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
#include "qlayout_wrap.h"
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
|
||||
Napi::FunctionReference QLayoutWrap::constructor;
|
||||
|
||||
void QLayoutWrap::init(Napi::Env env) {
|
||||
char CLASSNAME[] = "QLayout";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {});
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
}
|
||||
|
||||
|
||||
7
src/cpp/core/Component/component_macro.h
Normal file
7
src/cpp/core/Component/component_macro.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
#define COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE \
|
||||
\
|
||||
InstanceValue("type", Napi::String::New(env, "native")), \
|
||||
|
||||
#endif // COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
@ -1,6 +1,7 @@
|
||||
#include "flexlayout_wrap.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
#include "src/cpp/core/Component/component_macro.h"
|
||||
|
||||
Napi::FunctionReference FlexLayoutWrap::constructor;
|
||||
|
||||
@ -12,6 +13,7 @@ Napi::Object FlexLayoutWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("insertChildBefore", &FlexLayoutWrap::insertChildBefore),
|
||||
InstanceMethod("removeWidget", &FlexLayoutWrap::removeWidget),
|
||||
InstanceMethod("setFlexNode", &FlexLayoutWrap::setFlexNode),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import addon from "../../core/addon";
|
||||
import { Component, NativeElement } from "../../core/Component";
|
||||
|
||||
type arg = string | NativeElement;
|
||||
export class QPixmap extends Component {
|
||||
native: NativeElement;
|
||||
constructor(imageUrl?: string) {
|
||||
constructor(arg?: arg) {
|
||||
super();
|
||||
if (imageUrl) {
|
||||
if (typeof arg === "string") {
|
||||
const imageUrl = arg;
|
||||
this.native = new addon.QPixmap(imageUrl);
|
||||
} else if ((arg as NativeElement).type === "native") {
|
||||
this.native = arg as NativeElement;
|
||||
} else {
|
||||
this.native = new addon.QPixmap();
|
||||
}
|
||||
@ -14,7 +18,8 @@ export class QPixmap extends Component {
|
||||
load = (imageUrl: string) => {
|
||||
return this.native.load(imageUrl);
|
||||
};
|
||||
scaled = (width: number, height: number) => {
|
||||
return this.native.scaled(width, height);
|
||||
scaled = (width: number, height: number): QPixmap => {
|
||||
const nativePixmap = this.native.scaled(width, height);
|
||||
return new QPixmap(nativePixmap);
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export type NativeElement = any;
|
||||
export type NativeElement = { type: "native"; [key: string]: any };
|
||||
export abstract class Component {
|
||||
protected children = new Set<Component>();
|
||||
protected parent?: Component;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user