Skip to content

Commit a09d61f

Browse files
committed
add window template
1 parent caf5ece commit a09d61f

3 files changed

Lines changed: 44 additions & 24 deletions

File tree

src/app/app.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import { Component } from '@angular/core';
33
@Component({
44
selector: 'app-root',
55
template: `
6-
Hello {{ name }}
7-
<button [style.color]="'green'">Button - {{ name }}</button>
6+
<window title="Angular app in window!">
7+
<text [style.font-size.px]="45">Hello, {{ name }}</text>
8+
9+
<button [style.background-color]="'green'">
10+
Green button
11+
</button>
12+
</window>
813
`
914
})
1015
export class AppComponent {

src/lib/renderer.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import {
55
RendererStyleFlags2,
66
RendererType2
77
} from '@angular/core';
8-
import { QWidget, QPushButton, QLabel, FlexLayout } from '@nodegui/nodegui';
8+
import {
9+
QWidget,
10+
QPushButton,
11+
QLabel,
12+
FlexLayout,
13+
QMainWindow
14+
} from '@nodegui/nodegui';
915
import { QWindowService } from './window';
1016
import { TextField } from './nodes';
1117

@@ -33,35 +39,37 @@ export class NodeguiRenderer implements Renderer2 {
3339
constructor(private window: QWindowService) {}
3440

3541
createElement(name: string, namespace?: string | null): any {
36-
const button = new QPushButton();
37-
button.setObjectName('button');
38-
return button;
42+
switch (name) {
43+
case 'button':
44+
return new QPushButton();
45+
case 'window':
46+
return new FlexLayout();
47+
case 'text':
48+
return new QLabel();
49+
}
3950
}
4051

4152
createText(value: string): any {
42-
// may be use Qwidget? need for set button to text
43-
44-
// const label = new QLabel();
45-
// label.setText(value);
46-
// label.setInlineStyle(`
47-
// color: red;
48-
// `);
4953
return new TextField(value);
5054
}
5155

5256
selectRootElement(): any {
53-
return this.window.rootLayout;
57+
return this.window.window;
5458
}
5559

5660
addClass(el: any, name: string): void {
5761
console.log(el, name);
5862
}
5963

6064
appendChild(parent: FlexLayout, newChild: any): void {
61-
// console.log(parent, newChild);
62-
6365
if (newChild) {
64-
if (parent instanceof FlexLayout && newChild instanceof TextField) {
66+
if (parent instanceof QMainWindow && newChild instanceof FlexLayout) {
67+
this.window.centralWidget.setLayout(newChild);
68+
this.window.window.setCentralWidget(this.window.centralWidget);
69+
} else if (
70+
parent instanceof FlexLayout &&
71+
newChild instanceof TextField
72+
) {
6573
const label = new QLabel();
6674
newChild.parent = label;
6775
label.setText(newChild.value);
@@ -72,6 +80,11 @@ export class NodeguiRenderer implements Renderer2 {
7280
) {
7381
newChild.parent = parent;
7482
parent.setText(newChild.value);
83+
} else if (newChild instanceof QLabel) {
84+
parent.addWidget(newChild);
85+
} else if (parent instanceof QLabel && newChild instanceof TextField) {
86+
newChild.parent = parent;
87+
parent.setText(newChild.value);
7588
} else {
7689
parent.addWidget(newChild);
7790
}
@@ -114,7 +127,9 @@ export class NodeguiRenderer implements Renderer2 {
114127
value: string,
115128
namespace?: string | null
116129
): void {
117-
el[name] = value;
130+
if (el instanceof FlexLayout && name === 'title') {
131+
this.window.window.setWindowTitle(value);
132+
}
118133
}
119134

120135
setProperty(el: any, name: string, value: any): void {
@@ -138,6 +153,8 @@ export class NodeguiRenderer implements Renderer2 {
138153
}
139154

140155
setValue(node: any, value: string): void {
156+
// console.log('setValue', node, value);
157+
141158
if (node instanceof TextField) {
142159
node.parent.setText(value);
143160
} else {

src/lib/window.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import { QMainWindow, FlexLayout, QWidget } from '@nodegui/nodegui';
55
export class QWindowService {
66
public window: QMainWindow;
77
public rootLayout: FlexLayout;
8+
public centralWidget: QWidget;
9+
810
constructor() {
911
this.window = new QMainWindow();
10-
const centralWidget = new QWidget();
11-
centralWidget.setObjectName('myroot');
12-
13-
this.rootLayout = new FlexLayout();
14-
centralWidget.setLayout(this.rootLayout);
15-
this.window.setCentralWidget(centralWidget);
12+
this.centralWidget = new QWidget();
13+
this.centralWidget.setObjectName('myroot');
1614
}
1715
}

0 commit comments

Comments
 (0)