Skip to content

Commit caf5ece

Browse files
committed
Add inline styles
1 parent d809aa6 commit caf5ece

3 files changed

Lines changed: 42 additions & 12 deletions

File tree

src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Component } from '@angular/core';
44
selector: 'app-root',
55
template: `
66
Hello {{ name }}
7-
<button>text - {{ name }}</button>
7+
<button [style.color]="'green'">Button - {{ name }}</button>
88
`
99
})
1010
export class AppComponent {

src/lib/nodes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { QWidget } from '@nodegui/nodegui';
2+
3+
export class TextField extends QWidget {
4+
public parent: any;
5+
constructor(public value: string) {
6+
super();
7+
}
8+
}

src/lib/renderer.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@angular/core';
88
import { QWidget, QPushButton, QLabel, FlexLayout } from '@nodegui/nodegui';
99
import { QWindowService } from './window';
10+
import { TextField } from './nodes';
1011

1112
@Injectable()
1213
export class NodeguiRendererFactory implements RendererFactory2 {
@@ -38,24 +39,39 @@ export class NodeguiRenderer implements Renderer2 {
3839
}
3940

4041
createText(value: string): any {
41-
const label = new QLabel(); // may be use Qwidget? need for set button to text
42-
label.setText(value);
43-
label.setInlineStyle(`
44-
color: red;
45-
`);
46-
return label;
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+
// `);
49+
return new TextField(value);
4750
}
4851

4952
selectRootElement(): any {
5053
return this.window.rootLayout;
5154
}
5255

53-
addClass(el: any, name: string): void {}
56+
addClass(el: any, name: string): void {
57+
console.log(el, name);
58+
}
5459

5560
appendChild(parent: FlexLayout, newChild: any): void {
61+
// console.log(parent, newChild);
62+
5663
if (newChild) {
57-
if (parent instanceof QPushButton && newChild instanceof QLabel) {
58-
parent.setText(newChild.text);
64+
if (parent instanceof FlexLayout && newChild instanceof TextField) {
65+
const label = new QLabel();
66+
newChild.parent = label;
67+
label.setText(newChild.value);
68+
parent.addWidget(label);
69+
} else if (
70+
parent instanceof QPushButton &&
71+
newChild instanceof TextField
72+
) {
73+
newChild.parent = parent;
74+
parent.setText(newChild.value);
5975
} else {
6076
parent.addWidget(newChild);
6177
}
@@ -102,6 +118,7 @@ export class NodeguiRenderer implements Renderer2 {
102118
}
103119

104120
setProperty(el: any, name: string, value: any): void {
121+
console.log('setProperty', el, name, value);
105122
if (name === 'styles') {
106123
name = 'style';
107124
} else {
@@ -116,10 +133,15 @@ export class NodeguiRenderer implements Renderer2 {
116133
flags?: RendererStyleFlags2
117134
): void {
118135
el[style] = value;
136+
// console.log('setStyle', el, style, value);
137+
el.setInlineStyle(`${style}:${value}`);
119138
}
120139

121140
setValue(node: any, value: string): void {
122-
// use new values may be button not set text, may be use widget for text?
123-
node.setText(value);
141+
if (node instanceof TextField) {
142+
node.parent.setText(value);
143+
} else {
144+
node.setText(value);
145+
}
124146
}
125147
}

0 commit comments

Comments
 (0)