1- import { Renderer , View , Window , Image } from "./index" ;
2- import React from "react" ;
3- import { AspectRatioMode } from "@nodegui/nodegui" ;
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" ;
49
510const App = ( ) => {
11+ const winRef = useRef < QMainWindow > ( null ) ;
12+ const [ fileUrl , setFileUrl ] = useState ( ) ;
13+ const [ imageSrc , setImageSrc ] = useState ( ) ;
14+ useEffect ( ( ) => {
15+ if ( winRef . current ) {
16+ winRef . current . resize ( 800 , 450 ) ;
17+ }
18+ } , [ ] ) ;
19+ const lineEditHandler = useMemo (
20+ ( ) => ( {
21+ [ QLineEditEvents . textChanged ] : ( text : string ) => {
22+ setFileUrl ( text ) ;
23+ }
24+ } ) ,
25+ [ ]
26+ ) ;
27+
28+ const loadButtonHandler = useMemo (
29+ ( ) => ( {
30+ [ QPushButtonEvents . clicked ] : ( ) => {
31+ setImageSrc ( fileUrl ) ;
32+ }
33+ } ) ,
34+ [ fileUrl ]
35+ ) ;
36+
637 return (
738 < >
8- < Window styleSheet = { styleSheet } >
39+ < Window ref = { winRef } styleSheet = { styleSheet } >
940 < 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 >
1050 < Image
1151 id = "img"
1252 aspectRatioMode = { AspectRatioMode . KeepAspectRatio }
13- src = "/Users/atulr/Downloads/demo.png"
53+ src = { imageSrc }
1454 > </ Image >
1555 </ View >
1656 </ Window >
@@ -21,11 +61,21 @@ const App = () => {
2161const styleSheet = `
2262 #container {
2363 qproperty-flex: 1;
24- qproperty-flexDirection: column;
2564 qproperty-minHeight: '100%';
2665 }
66+ #controls {
67+ qproperty-flexDirection: 'row';
68+ qproperty-justifyContent: 'space-around';
69+ qproperty-alignItems: 'center';
70+ qproperty-paddingHorizontal: 20;
71+ qproperty-paddingVertical: 10;
72+ }
2773 #img {
2874 qproperty-flex: 1;
75+ qproperty-alignment: 'AlignCenter';
76+ }
77+ #textField {
78+ qproperty-flex: 1;
2979 }
3080` ;
3181
0 commit comments