Remove NodeLayout, use QLayout instead
This commit is contained in:
parent
b7476a4ea1
commit
83e9c09690
@ -40,7 +40,7 @@ export { QWindow } from './lib/QtGui/QWindow';
|
||||
export { WidgetEventTypes } from './lib/core/EventWidget';
|
||||
// Abstract:
|
||||
export { QWidget, QWidgetSignals } from './lib/QtWidgets/QWidget';
|
||||
export { NodeLayout, QLayoutSignals, SizeConstraint } from './lib/QtWidgets/QLayout';
|
||||
export { QLayout, QLayoutSignals, SizeConstraint } from './lib/QtWidgets/QLayout';
|
||||
export { QAbstractScrollArea } from './lib/QtWidgets/QAbstractScrollArea';
|
||||
export { QAbstractSlider, QAbstractSliderSignals, SliderAction } from './lib/QtWidgets/QAbstractSlider';
|
||||
export { QAbstractButton, QAbstractButtonSignals } from './lib/QtWidgets/QAbstractButton';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import addon from '../utils/addon';
|
||||
import { QWidget } from './QWidget';
|
||||
import { NodeLayout, QLayoutSignals } from './QLayout';
|
||||
import { QLayout, QLayoutSignals } from './QLayout';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { AlignmentFlag, Direction } from '../QtEnums';
|
||||
|
||||
@ -25,8 +25,8 @@ boxLayout.addWidget(new QCalendarWidget());
|
||||
centralWidget.setLayout(boxLayout);
|
||||
```
|
||||
*/
|
||||
export class QBoxLayout extends NodeLayout<QBoxLayoutSignals> {
|
||||
childLayouts: Set<NodeLayout<any>>;
|
||||
export class QBoxLayout extends QLayout<QBoxLayoutSignals> {
|
||||
childLayouts: Set<QLayout>;
|
||||
constructor(dir: Direction, parent?: QWidget) {
|
||||
let native: NativeElement;
|
||||
if (parent) {
|
||||
@ -38,7 +38,7 @@ export class QBoxLayout extends NodeLayout<QBoxLayoutSignals> {
|
||||
this.setNodeParent(parent);
|
||||
this.childLayouts = new Set();
|
||||
}
|
||||
addLayout(layout: NodeLayout<any>, stretch = 0): void {
|
||||
addLayout(layout: QLayout<any>, stretch = 0): void {
|
||||
this.native.addLayout(layout.native, stretch);
|
||||
this.childLayouts.add(layout);
|
||||
}
|
||||
@ -62,7 +62,7 @@ export class QBoxLayout extends NodeLayout<QBoxLayoutSignals> {
|
||||
direction(): Direction {
|
||||
return this.native.direction();
|
||||
}
|
||||
insertLayout(index: number, layout: NodeLayout<any>, stretch = 0): void {
|
||||
insertLayout(index: number, layout: QLayout, stretch = 0): void {
|
||||
this.native.insertLayout(index, layout.native, stretch);
|
||||
this.childLayouts.add(layout);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import addon from '../utils/addon';
|
||||
import { QWidget } from './QWidget';
|
||||
import { NodeLayout, QLayoutSignals } from './QLayout';
|
||||
import { QLayout, QLayoutSignals } from './QLayout';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { AlignmentFlag } from '../QtEnums';
|
||||
|
||||
@ -29,7 +29,7 @@ layout.addWidget(label2);
|
||||
```
|
||||
|
||||
*/
|
||||
export class QGridLayout extends NodeLayout<QGridLayoutSignals> {
|
||||
export class QGridLayout extends QLayout<QGridLayoutSignals> {
|
||||
constructor(parent?: QWidget) {
|
||||
let native: NativeElement;
|
||||
if (parent) {
|
||||
@ -42,7 +42,7 @@ export class QGridLayout extends NodeLayout<QGridLayoutSignals> {
|
||||
}
|
||||
|
||||
addLayout(
|
||||
layout: NodeLayout<any>,
|
||||
layout: QLayout,
|
||||
row: number,
|
||||
column: number,
|
||||
rowSpan = 1,
|
||||
|
||||
@ -9,21 +9,21 @@ import { QObject, QObjectSignals } from '../QtCore/QObject';
|
||||
|
||||
**This class implements all methods, properties of Qt's [QLayout class](https://doc.qt.io/qt-5/qlayout.html) so that it can be inherited by all layouts**
|
||||
|
||||
`NodeLayout` is an abstract class and hence no instances of the same should be created. It exists so that we can add similar functionalities to all layout's easily. Additionally it helps in typechecking process.
|
||||
`QLayout` is an abstract class and hence no instances of the same should be created.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const {
|
||||
NodeLayout,
|
||||
QLayout,
|
||||
FlexLayout,
|
||||
GridLayout,
|
||||
QPushButton,
|
||||
QWidget
|
||||
} = require("@nodegui/nodegui");
|
||||
|
||||
// addChildToLayout can accept any layout since it expects NodeLayout
|
||||
const addChildToLayout = (layout: NodeLayout, widget: QWidget) => {
|
||||
// addChildToLayout can accept any layout since it expects QLayout
|
||||
const addChildToLayout = (layout: QLayout, widget: QWidget) => {
|
||||
layout.addWidget(widget);
|
||||
};
|
||||
|
||||
@ -31,7 +31,7 @@ addChildToLayout(new FlexLayout(), new QPushButton());
|
||||
addChildToLayout(new GridLayout(), new QWidget());
|
||||
```
|
||||
*/
|
||||
export abstract class NodeLayout<Signals extends QLayoutSignals> extends QObject<Signals> {
|
||||
export abstract class QLayout<Signals extends QLayoutSignals = QLayoutSignals> extends QObject<Signals> {
|
||||
type = 'layout';
|
||||
abstract addWidget(childWidget: QWidget, ...args: any[]): void;
|
||||
abstract removeWidget(childWidget: QWidget): void;
|
||||
@ -67,10 +67,6 @@ export abstract class NodeLayout<Signals extends QLayoutSignals> extends QObject
|
||||
}
|
||||
}
|
||||
|
||||
// export class QLayout extends NodeLayout { //Dont need QLayout for now
|
||||
// native: any;
|
||||
// }
|
||||
|
||||
export enum SizeConstraint {
|
||||
SetDefaultConstraint = 0,
|
||||
SetNoConstraint = 1,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import addon from '../utils/addon';
|
||||
import { QWidget, QWidgetSignals } from './QWidget';
|
||||
import { NodeLayout } from './QLayout';
|
||||
import { QLayout } from './QLayout';
|
||||
import { QMenuBar } from './QMenuBar';
|
||||
import { QStatusBar } from './QStatusBar';
|
||||
import { NativeElement } from '../core/Component';
|
||||
@ -46,7 +46,7 @@ export class QMainWindow extends QWidget<QMainWindowSignals> {
|
||||
super(native);
|
||||
this.setNodeParent(parent);
|
||||
|
||||
this.setLayout = (parentLayout: NodeLayout<any>): void => {
|
||||
this.setLayout = (parentLayout: QLayout): void => {
|
||||
if (this.centralWidget) {
|
||||
this.centralWidget.setLayout(parentLayout);
|
||||
} else {
|
||||
@ -80,7 +80,7 @@ export class QMainWindow extends QWidget<QMainWindowSignals> {
|
||||
setMenuWidget(menuWidget: QWidget): void {
|
||||
this.native.setMenuWidget(menuWidget.native);
|
||||
}
|
||||
get layout(): NodeLayout<any> | undefined {
|
||||
get layout(): QLayout | undefined {
|
||||
if (this.centralWidget) {
|
||||
return this.centralWidget.layout;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeLayout } from './QLayout';
|
||||
import { QLayout } from './QLayout';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { FlexLayout } from '../core/FlexLayout';
|
||||
import { WidgetAttribute, WindowType, ContextMenuPolicy, FocusReason, FocusPolicy } from '../QtEnums';
|
||||
@ -41,7 +41,7 @@ view.setLayout(new FlexLayout());
|
||||
```
|
||||
*/
|
||||
export class QWidget<Signals extends QWidgetSignals = QWidgetSignals> extends YogaWidget<Signals> {
|
||||
_layout?: NodeLayout<Signals>;
|
||||
_layout?: QLayout;
|
||||
_rawInlineStyle: string;
|
||||
type: string;
|
||||
private _effect?: QGraphicsEffect<any> | null;
|
||||
@ -68,10 +68,10 @@ export class QWidget<Signals extends QWidgetSignals = QWidgetSignals> extends Yo
|
||||
this.setObjectName = memoizeOne(this.setObjectName);
|
||||
}
|
||||
|
||||
get layout(): NodeLayout<Signals> | undefined {
|
||||
get layout(): QLayout | undefined {
|
||||
return this._layout;
|
||||
}
|
||||
set layout(l: NodeLayout<Signals> | undefined) {
|
||||
set layout(l: QLayout | undefined) {
|
||||
this._layout = l;
|
||||
}
|
||||
// *** Public Functions ***
|
||||
@ -380,7 +380,7 @@ export class QWidget<Signals extends QWidgetSignals = QWidgetSignals> extends Yo
|
||||
this.native.setStyleSheet(style);
|
||||
}
|
||||
}
|
||||
setLayout(parentLayout: NodeLayout<Signals>): void {
|
||||
setLayout(parentLayout: QLayout): void {
|
||||
const flexLayout = parentLayout as FlexLayout;
|
||||
this.native.setLayout(parentLayout.native);
|
||||
if (flexLayout.setFlexNode) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import addon from '../utils/addon';
|
||||
import { QWidget } from '../QtWidgets/QWidget';
|
||||
import { NodeLayout, QLayoutSignals } from '../QtWidgets/QLayout';
|
||||
import { QLayout, QLayoutSignals } from '../QtWidgets/QLayout';
|
||||
import { FlexNode } from './YogaWidget';
|
||||
|
||||
export type FlexLayoutSignals = QLayoutSignals;
|
||||
@ -31,7 +31,7 @@ layout.addWidget(label);
|
||||
layout.addWidget(label2);
|
||||
```
|
||||
*/
|
||||
export class FlexLayout extends NodeLayout<FlexLayoutSignals> {
|
||||
export class FlexLayout extends QLayout<FlexLayoutSignals> {
|
||||
protected flexNode?: FlexNode;
|
||||
|
||||
constructor(parent?: QWidget) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user