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" ;
8
9
9
10
const App = ( ) => {
10
11
const winRef = useRef < QMainWindow > ( null ) ;
12
+ const [ fileUrl , setFileUrl ] = useState ( ) ;
13
+ const [ imageSrc , setImageSrc ] = useState ( ) ;
11
14
useEffect ( ( ) => {
12
15
if ( winRef . current ) {
13
16
winRef . current . resize ( 800 , 450 ) ;
14
17
}
15
18
} , [ ] ) ;
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
+ ( ) => ( {
19
30
[ QPushButtonEvents . clicked ] : ( ) => {
20
- console . log ( "clicked" ) ;
21
- setResizeable ( ! resizeable ) ;
31
+ setImageSrc ( fileUrl ) ;
22
32
}
23
- } ,
24
- [ resizeable ]
33
+ } ) ,
34
+ [ fileUrl ]
25
35
) ;
26
- const size = { width : 200 , height : 200 , fixed : ! resizeable } ;
36
+
27
37
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
+ </ >
34
58
) ;
35
59
} ;
36
60
@@ -39,6 +63,20 @@ const styleSheet = `
39
63
flex: 1;
40
64
min-height: '100%';
41
65
}
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
+ }
42
80
` ;
43
81
44
82
Renderer . render ( < App /> ) ;
0 commit comments