Skip to content

Commit 5d7f05e

Browse files
committed
revert to old example for timebeing
1 parent dc1d0af commit 5d7f05e

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

src/demo.tsx

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,60 @@
1-
import { Renderer, Window } from "./index";
2-
import React, { useEffect, useRef, useState } from "react";
3-
import { QMainWindow, QPushButtonEvents } from "@nodegui/nodegui";
4-
import { Button } from "./components/Button";
5-
import { useEventHandler } from "./hooks";
6-
import { ScrollArea } from "./components/ScrollArea";
7-
import { View } from "./components/View";
1+
import { Renderer, View, Button, Window, Image, LineEdit } from "./index";
2+
import React, { useEffect, useRef, useMemo, useState } from "react";
3+
import {
4+
AspectRatioMode,
5+
QMainWindow,
6+
QLineEditEvents,
7+
QPushButtonEvents
8+
} from "@nodegui/nodegui";
89

910
const App = () => {
1011
const winRef = useRef<QMainWindow>(null);
12+
const [fileUrl, setFileUrl] = useState();
13+
const [imageSrc, setImageSrc] = useState();
1114
useEffect(() => {
1215
if (winRef.current) {
1316
winRef.current.resize(800, 450);
1417
}
1518
}, []);
16-
const [resizeable, setResizeable] = useState(true);
17-
const btnHandler = useEventHandler(
18-
{
19+
const lineEditHandler = useMemo(
20+
() => ({
21+
[QLineEditEvents.textChanged]: (text: string) => {
22+
setFileUrl(text);
23+
}
24+
}),
25+
[]
26+
);
27+
28+
const loadButtonHandler = useMemo(
29+
() => ({
1930
[QPushButtonEvents.clicked]: () => {
20-
console.log("clicked");
21-
setResizeable(!resizeable);
31+
setImageSrc(fileUrl);
2232
}
23-
},
24-
[resizeable]
33+
}),
34+
[fileUrl]
2535
);
26-
const size = { width: 200, height: 200, fixed: !resizeable };
36+
2737
return (
28-
<Window size={size} ref={winRef} styleSheet={styleSheet}>
29-
<Button text={resizeable ? "❌" : "✅"} on={btnHandler} />
30-
<ScrollArea>
31-
<View />
32-
</ScrollArea>
33-
</Window>
38+
<>
39+
<Window ref={winRef} styleSheet={styleSheet}>
40+
<View id="container">
41+
<View id="controls">
42+
<LineEdit
43+
on={lineEditHandler}
44+
id="textField"
45+
text={fileUrl}
46+
placeholderText="Absolute path to an image"
47+
/>
48+
<Button text="Load Image" on={loadButtonHandler} />
49+
</View>
50+
<Image
51+
id="img"
52+
aspectRatioMode={AspectRatioMode.KeepAspectRatio}
53+
src={imageSrc}
54+
/>
55+
</View>
56+
</Window>
57+
</>
3458
);
3559
};
3660

@@ -39,6 +63,20 @@ const styleSheet = `
3963
flex: 1;
4064
min-height: '100%';
4165
}
66+
#controls {
67+
flex-direction: 'row';
68+
justify-content: 'space-around';
69+
align-items: 'center';
70+
padding-horizontal: 20;
71+
padding-vertical: 10;
72+
}
73+
#img {
74+
flex: 1;
75+
qproperty-alignment: 'AlignCenter';
76+
}
77+
#textField {
78+
flex: 1;
79+
}
4280
`;
4381

4482
Renderer.render(<App />);

0 commit comments

Comments
 (0)