nodeguy/docs/api/synopsis.md
2019-08-08 22:39:14 +02:00

1.6 KiB

Synopsis

How to use Node.js and NodeGui's APIs.

All of Node.js's built-in modules are available in NodeGui and third-party node modules also fully supported as well (including the native modules).

NodeGui also provides some extra built-in modules for developing native desktop applications.

The app script is like a normal Node.js script:

const { QMainWindow } = require("@nodegui/nodegui");

const win = new QMainWindow();

win.show();

global.win = win; // To prevent win from being garbage collected.

To run your app, read Run your app.

Destructuring assignment

You can use destructuring assignment to make it easier to use built-in modules.

const {
  QMainWindow,
  QWidget,
  QLabel,
  FlexLayout,
  StyleSheet
} = require("@nodegui/nodegui");

const win = new QMainWindow();

const centralWidget = new QWidget();
centralWidget.setObjectName("myroot");
const rootLayout = new FlexLayout();
centralWidget.setLayout(rootLayout);

const label = new QLabel();
label.setObjectName("mylabel");
label.setText("Hello World");

rootLayout.addWidget(label);
win.setCentralWidget(centralWidget);
win.setStyleSheet(
  StyleSheet.create(
    `
    #myroot {
      background-color: #009688;
    }
    #mylabel {
      font-size: 16px;
      font-weight: bold;
    }
  `
  )
);
win.show();

global.win = win;