Skip to content

Commit bbafe18

Browse files
committed
Adds inline stylesheet and updates stylesheets for examples
1 parent 4cc7216 commit bbafe18

File tree

5 files changed

+47
-37
lines changed

5 files changed

+47
-37
lines changed

examples/calculator/index.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const App = () => {
118118
[QMainWindowEvents.KeyRelease]: onKeyRelease
119119
}}
120120
maxSize={{ width: 500, height: 700 }}
121-
minSize={{ width: 200, height: 300 }}
121+
minSize={{ width: 300, height: 400 }}
122122
styleSheet={styleSheet}
123123
>
124124
<View on={{ [QWidgetEvents.KeyRelease]: onKeyRelease }} id="container">
@@ -225,31 +225,27 @@ const App = () => {
225225
);
226226
};
227227

228-
// const win = new QMainWindow();
229-
// win.resize(230, 300);
230228
const styleSheet = `
231229
#container {
232-
qproperty-flex: 1;
233-
qproperty-flexDirection: column;
234-
qproperty-minHeight: '100%';
235-
background: blue;
230+
flex: 1;
231+
flex-direction: column;
232+
min-height: '100%';
236233
}
237234
#row, #row0, #row1 {
238-
qproperty-flex: 1;
239-
qproperty-alignItems: stretch;
240-
qproperty-justifyContent: space-between;
241-
qproperty-flexDirection: row;
235+
flex: 1;
236+
align-items: stretch;
237+
justify-content: space-between;
238+
flex-direction: row;
242239
background: #4B4B4B;
243240
}
244241
#row0 {
245242
background: #1E1E1E;
246243
}
247244
#row1 {
248-
background: #2E2E2E;
245+
background: #2E2E2E;
249246
}
250247
#valueBtn, #opBtn, #opBtnY {
251-
qproperty-minWidth: '25%';
252-
qproperty-border: 1;
248+
min-width: '25%';
253249
border: 1px solid black;
254250
font-size: 20px;
255251
color: white;
@@ -262,11 +258,9 @@ const styleSheet = `
262258
}
263259
#result {
264260
qproperty-alignment: 'AlignRight|AlignVCenter';
265-
padding-right: 5px;
266-
padding-left:5px;
267-
qproperty-paddingHorizontal: 5px;
261+
padding-horizontal: 5px;
268262
font-size: 40px;
269-
qproperty-flex: 1;
263+
flex: 1;
270264
color: white;
271265
}
272266
`;

examples/image-view/index.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,22 @@ const App = () => {
6767

6868
const styleSheet = `
6969
#container {
70-
qproperty-flex: 1;
71-
qproperty-minHeight: '100%';
70+
flex: 1;
71+
min-height: '100%';
7272
}
7373
#controls {
74-
qproperty-flexDirection: 'row';
75-
qproperty-justifyContent: 'space-around';
76-
qproperty-alignItems: 'center';
77-
qproperty-paddingHorizontal: 20;
78-
qproperty-paddingVertical: 10;
74+
flex-direction: 'row';
75+
justify-content: 'space-around';
76+
align-items: 'center';
77+
padding-horizontal: 20;
78+
padding-vertical: 10;
7979
}
8080
#img {
81-
qproperty-flex: 1;
81+
flex: 1;
8282
qproperty-alignment: 'AlignCenter';
8383
}
8484
#textField {
85-
qproperty-flex: 1;
85+
flex: 1;
8686
}
8787
`;
8888

src/components/Image/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const setProps = (
1414
) => {
1515
const setter: ImageProps = {
1616
set src(imageUrl: string) {
17+
if (!imageUrl) {
18+
return;
19+
}
1720
const pixMap = new QPixmap(imageUrl);
1821
widget.setPixmap(pixMap);
1922
const size = widget.size();

src/components/View/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface ListenerMap {
66
}
77
export interface ViewProps {
88
id?: string;
9+
style?: string; // Inline style from NodeGui
910
styleSheet?: string;
1011
visible?: boolean;
1112
ref?: any;
@@ -23,6 +24,12 @@ export const setProps = (
2324
set visible(shouldShow: boolean) {
2425
shouldShow ? widget.show() : widget.hide();
2526
},
27+
set style(inlineStyle: string) {
28+
if (newProps.styleSheet) {
29+
console.warn("Both styleSheet and inlineStyle can't be used together");
30+
}
31+
widget.setInlineStyle(inlineStyle);
32+
},
2633
set styleSheet(styleSheet: string) {
2734
widget.setStyleSheet(styleSheet);
2835
},

src/demo.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ const App = () => {
4545
text={fileUrl}
4646
placeholderText="Absolute path to an image"
4747
/>
48-
<Button text="Load Image" on={loadButtonHandler} />
48+
<Button
49+
style={`
50+
background-color: green;
51+
`}
52+
text="Load Image"
53+
on={loadButtonHandler}
54+
/>
4955
</View>
5056
<Image
5157
id="img"
@@ -60,22 +66,22 @@ const App = () => {
6066

6167
const styleSheet = `
6268
#container {
63-
qproperty-flex: 1;
64-
qproperty-minHeight: '100%';
69+
flex: 1;
70+
min-height: '100%';
6571
}
6672
#controls {
67-
qproperty-flexDirection: 'row';
68-
qproperty-justifyContent: 'space-around';
69-
qproperty-alignItems: 'center';
70-
qproperty-paddingHorizontal: 20;
71-
qproperty-paddingVertical: 10;
73+
flex-direction: 'row';
74+
justify-content: 'space-around';
75+
align-items: 'center';
76+
padding-horizontal: 20;
77+
padding-vertical: 10;
7278
}
7379
#img {
74-
qproperty-flex: 1;
80+
flex: 1;
7581
qproperty-alignment: 'AlignCenter';
7682
}
7783
#textField {
78-
qproperty-flex: 1;
84+
flex: 1;
7985
}
8086
`;
8187

0 commit comments

Comments
 (0)