Corrects setLayout and layout when central widget is set on QMainWindow

This commit is contained in:
Atul R 2019-07-14 00:12:11 +02:00
parent 789d28ed99
commit 63685c88c4
2 changed files with 19 additions and 4 deletions

View File

@ -33,9 +33,9 @@ export abstract class NodeWidget extends EventWidget {
setMouseTracking = (isMouseTracked: boolean) => {
this.native.setMouseTracking(isMouseTracked);
};
setEnabled = (enabled: boolean)=>{
setEnabled = (enabled: boolean) => {
this.native.setEnabled(enabled);
}
};
}
export class QWidget extends NodeWidget {

View File

@ -3,13 +3,14 @@ import { NodeWidget } from "../../QtGui/QWidget";
import { BaseWidgetEvents } from "../../core/EventWidget";
import { FlexNode } from "../../core/YogaWidget";
import { NativeElement } from "../../core/Component";
import { NodeLayout } from "../QLayout";
export const QMainWindowEvents = Object.freeze({
...BaseWidgetEvents
});
export class QMainWindow extends NodeWidget {
native: NativeElement;
protected centralWidget?: NodeWidget;
public centralWidget?: NodeWidget;
constructor(parent?: NodeWidget) {
let native;
if (parent) {
@ -23,8 +24,8 @@ export class QMainWindow extends NodeWidget {
// bind member functions
this.setCentralWidget.bind(this);
this.setFixedSize.bind(this);
this.setLayout = this._setLayout.bind(this);
}
setCentralWidget(widget: NodeWidget) {
this.centralWidget = widget;
this.native.setCentralWidget(
@ -32,6 +33,20 @@ export class QMainWindow extends NodeWidget {
widget.getFlexNode()
);
}
get layout() {
if (this.centralWidget) {
return this.centralWidget.layout;
} else {
return super.layout;
}
}
private _setLayout(parentLayout: NodeLayout) {
if (this.centralWidget) {
return this.centralWidget.setLayout(parentLayout);
} else {
return super.setLayout(parentLayout);
}
}
setFixedSize(width: number, height: number) {
this.native.setFixedSize(width, height);
}