Mainwindow takeCentralWidget (#225)

* Adds takeCentralWidget to qmainwindow

* lint fix

* bump version to 0.6.7
This commit is contained in:
Atul R 2019-11-26 01:00:53 +01:00 committed by GitHub
parent 71c58db50e
commit 2b2d83d0a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 9 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@nodegui/nodegui",
"version": "0.6.6",
"version": "0.6.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@nodegui/nodegui",
"version": "0.6.6",
"version": "0.6.7",
"description": "A cross platform library to build native desktop apps.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",

View File

@ -21,6 +21,7 @@ class QMainWindowWrap : public Napi::ObjectWrap<QMainWindowWrap> {
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value setCentralWidget(const Napi::CallbackInfo& info);
Napi::Value takeCentralWidget(const Napi::CallbackInfo& info);
Napi::Value setMenuBar(const Napi::CallbackInfo& info);
Napi::Value menuBar(const Napi::CallbackInfo& info);
Napi::Value setMenuWidget(const Napi::CallbackInfo& info);

View File

@ -14,12 +14,13 @@ Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) {
char CLASSNAME[] = "QMainWindow";
Napi::Function func = DefineClass(
env, CLASSNAME,
{
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap) InstanceMethod(
"setCentralWidget", &QMainWindowWrap::setCentralWidget),
InstanceMethod("setMenuBar", &QMainWindowWrap::setMenuBar),
InstanceMethod("setMenuWidget", &QMainWindowWrap::setMenuWidget),
InstanceMethod("center", &QMainWindowWrap::center),
{InstanceMethod("setCentralWidget", &QMainWindowWrap::setCentralWidget),
InstanceMethod("takeCentralWidget", &QMainWindowWrap::takeCentralWidget),
InstanceMethod("setMenuBar", &QMainWindowWrap::setMenuBar),
InstanceMethod("setMenuWidget", &QMainWindowWrap::setMenuWidget),
InstanceMethod("center", &QMainWindowWrap::center),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -61,6 +62,14 @@ Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QMainWindowWrap::takeCentralWidget(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->takeCentralWidget();
// We will not return the value here since we are doing it in js side anyway
return env.Null();
}
Napi::Value QMainWindowWrap::setMenuBar(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

View File

@ -10,7 +10,7 @@ export const QMainWindowEvents = Object.freeze({
});
export class QMainWindow extends NodeWidget {
native: NativeElement;
public centralWidget?: NodeWidget;
public centralWidget?: NodeWidget | null;
private _menuBar?: QMenuBar;
constructor(parent?: NodeWidget) {
let native;
@ -38,6 +38,16 @@ export class QMainWindow extends NodeWidget {
this.centralWidget = widget;
this.centralWidget.setFlexNodeSizeControlled(true);
}
takeCentralWidget(): NodeWidget | null {
// react:✓
const centralWidget = this.centralWidget;
this.centralWidget = null;
if (centralWidget) {
this.native.takeCentralWidget();
return centralWidget;
}
return null;
}
setMenuBar(menuBar: QMenuBar): void {
this.native.setMenuBar(menuBar.native);
this._menuBar = menuBar;