Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 15 additions & 6 deletions src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/lib/QtWidgets/QMainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down