Skip to content

Commit 59e2cfa

Browse files
committed
Add view component
1 parent 3963713 commit 59e2cfa

3 files changed

Lines changed: 73 additions & 4 deletions

File tree

src/app/app.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { Component } from '@angular/core';
44
selector: 'app-root',
55
template: `
66
<window title="Angular app in window!">
7-
<text [style.font-size.px]="45">Hello, {{ name }}</text>
7+
<view>
8+
<text [style.font-size.px]="45">Hello, {{ name }}</text>
89
9-
<button [style.background-color]="'green'" (clicked)="setName()">
10-
Green button
11-
</button>
10+
<button [style.background-color]="'green'" (clicked)="setName()">
11+
Green button
12+
</button>
13+
</view>
1214
</window>
1315
`
1416
})

src/lib/components/components-map.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NgButton } from './button';
33
import { NgComponent } from './component';
44
import { NgWindow } from './window';
55
import { NgText } from './text';
6+
import { NgView } from './view';
67

78
export type Constructable<T> = new () => T;
89
export type NgComponentClass = Constructable<NgComponent>;
@@ -18,5 +19,6 @@ export class ComponentsMap {
1819
this.map.set(NgButton.nodeName, NgButton);
1920
this.map.set(NgWindow.nodeName, NgWindow);
2021
this.map.set(NgText.nodeName, NgText);
22+
this.map.set(NgView.nodeName, NgView);
2123
}
2224
}

src/lib/components/view.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { QWidget, FlexLayout } from '@nodegui/nodegui';
2+
import { NgComponent } from './component';
3+
import { RendererStyleFlags2 } from '@angular/core';
4+
5+
export class NgView extends QWidget implements NgComponent {
6+
public static nodeName = 'view';
7+
public parent: any;
8+
9+
public appendChild(newChild: any): void {
10+
if (!newChild) {
11+
return;
12+
}
13+
if (!this.layout) {
14+
const flexLayout = new FlexLayout();
15+
flexLayout.setFlexNode(this.getFlexNode());
16+
this.setLayout(flexLayout);
17+
this.layout = flexLayout;
18+
}
19+
20+
this.layout.addWidget(newChild);
21+
}
22+
23+
public insertBefore(newChild: any, refChild: any) {
24+
if (!this.layout) {
25+
console.warn('parent has no layout to insert child before another child');
26+
return;
27+
}
28+
(this.layout as FlexLayout).insertChildBefore(newChild, this);
29+
}
30+
31+
public setNgAttribute(
32+
name: string,
33+
value: string,
34+
namespace?: string | null
35+
): void {}
36+
37+
public setProperty(name: string, value: any): void {
38+
throw new Error('Method not implemented.');
39+
}
40+
41+
public setStyle(
42+
style: string,
43+
value: any,
44+
flags?: RendererStyleFlags2
45+
): void {
46+
this.setInlineStyle(`${style}:${value}`);
47+
}
48+
49+
public setValue(value: string): void {
50+
throw new Error('Method not implemented.');
51+
}
52+
53+
removeAttribute(name: string, namespace?: string): void {
54+
throw new Error('Method not implemented.');
55+
}
56+
removeChild(oldChild: any): void {
57+
throw new Error('Method not implemented.');
58+
}
59+
removeClass(name: string): void {
60+
throw new Error('Method not implemented.');
61+
}
62+
removeStyle(style: string, flags?: RendererStyleFlags2): void {
63+
throw new Error('Method not implemented.');
64+
}
65+
}

0 commit comments

Comments
 (0)