refactored a bit and changed name

This commit is contained in:
Atul R 2019-05-21 20:55:49 +02:00
parent 6f8db2db1c
commit 40e8a0a743
10 changed files with 30 additions and 13 deletions

View File

@ -1,6 +1,6 @@
{
"targets": [{
"target_name": "node_desktop",
"target_name": "node_gui",
"cflags!": ["-fno-exceptions"],
"cflags_cc!": ["-fno-exceptions"],
"sources": [

View File

@ -1,6 +1,4 @@
const { QtGui, QtWidgets } = require(".");
// const app = new QtGui.QApplication();
import { QtGui, QtWidgets } from "./src";
const win = new QtWidgets.QMainWindow();
const view = new QtGui.QWidget();
win.setCentralWidget(view);
@ -16,6 +14,9 @@ label2.setStyleSheet("background-color:blue; color:white;");
const button1 = new QtWidgets.QPushButton();
button1.setText("Yolo");
// button1.setEventListener("click", () => {
// console.log("button clicked");
// });
gridLayout.addWidget(label);
gridLayout.addWidget(label2);
@ -26,4 +27,4 @@ view.setLayout(gridLayout);
win.show();
// app.exec();
global.win = win; //to keep gc from collecting
(global as any).win = win; //to keep gc from collecting

View File

@ -1,5 +1,5 @@
{
"name": "node_desktop",
"name": "node-gui",
"version": "1.0.0",
"description": "A cross platform library to build native desktop apps. Based on Qt5.",
"main": "dist/",
@ -15,7 +15,7 @@
"scripts": {
"build:addon": "node-gyp -j 8 rebuild",
"build:lib": "rm -rf ./dist/ && tsc",
"dev": "qode demo.js"
"dev": "yarn build:lib && qode dist/demo.js"
},
"dependencies": {
"node-addon-api": "^1.6.3"

View File

@ -67,3 +67,8 @@ Napi::Value QPushButtonWrap::setText(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QPushButtonWrap::setEventListener(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
return env.Null();
}

View File

@ -16,6 +16,7 @@ class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
//wrapped methods
Napi::Value setStyleSheet(const Napi::CallbackInfo& info);
Napi::Value setText(const Napi::CallbackInfo& info);
Napi::Value setEventListener(const Napi::CallbackInfo& info);
};
#endif

View File

@ -13,7 +13,7 @@ export class QGridLayout extends Component {
this.native = new addon.QGridLayout();
}
}
addWidget(widget: QWidget) {
addWidget(widget: Component) {
this.native.addWidget(widget.native);
this.children.add(widget);
}

View File

@ -1,9 +1,12 @@
import addon from "../../core/addon";
import { QWidget } from "../../QtGui/QWidget";
import { Component } from "../../core/Component";
import { EventComponent } from "../../core/EventComponent";
export class QPushButton extends Component {
export class QPushButton extends EventComponent {
native: any;
setEventListener(event: string, callback: () => void): void {
throw new Error("Method not implemented.");
}
constructor(parent?: QWidget) {
super();
if (parent) {

View File

@ -1,5 +1,5 @@
export abstract class Component {
children = new Set<Component>(); //TODO if react stub these as react will manage the instances from beings gc'ed better.
parent: Component | null = null;
protected children = new Set<Component>(); //TODO if react stub these as react will manage the instances from beings gc'ed better.
protected parent: Component | null = null;
abstract native: any;
}

View File

@ -0,0 +1,7 @@
import { Component } from "../Component";
type Callback = () => void;
export abstract class EventComponent extends Component {
abstract setEventListener(event: string, callback: Callback): void;
}

View File

@ -1,2 +1,2 @@
const addon = require("../../../build/Release/node_desktop.node");
const addon = require("../../../../build/Release/node_gui.node");
export default addon;