Skip to content

Commit eff6a9a

Browse files
authored
Support coord input (#11)
1 parent 3a0f8e6 commit eff6a9a

File tree

4 files changed

+92
-9
lines changed

4 files changed

+92
-9
lines changed

release/app/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "plainprinter",
33
"productName": "PlainPrinter",
4-
"version": "0.1.0",
4+
"version": "0.2.0",
55
"description": "Plain screen printer",
66
"main": "./dist/main/main.js",
77
"author": {

src/main/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ const createWindow = async () => {
9898

9999
mainWindow = new BrowserWindow({
100100
show: false,
101-
width: 512,
102-
height: 364,
101+
width: 800,
102+
height: 400,
103103
icon: getAssetPath('icon.png'),
104104
webPreferences: {
105105
preload: app.isPackaged

src/renderer/components/printer/Main.tsx

+87-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,43 @@ const Main = () => {
1818
const [pageNum, setPageNum] = useState(0);
1919
const [printing, setPrinting] = useState(false);
2020

21+
const setFrameCoordValue = (label: string, value: number) => {
22+
if (frameCoord) {
23+
switch (label) {
24+
case 'x0':
25+
setFrameCoord({ ...frameCoord, x0: value });
26+
break;
27+
case 'x1':
28+
setFrameCoord({ ...frameCoord, x1: value });
29+
break;
30+
case 'y0':
31+
frameCoord.y0 = value;
32+
setFrameCoord({ ...frameCoord, y0: value });
33+
break;
34+
case 'y1':
35+
setFrameCoord({ ...frameCoord, y1: value });
36+
break;
37+
default:
38+
break;
39+
}
40+
}
41+
};
42+
43+
const setNextCoordValue = (label: string, value: number) => {
44+
if (nextCoord) {
45+
switch (label) {
46+
case 'x':
47+
setNextCoord({ ...nextCoord, x0: value, x1: value });
48+
break;
49+
case 'y':
50+
setNextCoord({ ...nextCoord, y0: value, y1: value });
51+
break;
52+
default:
53+
break;
54+
}
55+
}
56+
};
57+
2158
const handleCloseScreen = (c: Coord) => {
2259
if (c.select === 'frame') {
2360
setFrameCoord({ ...c });
@@ -80,8 +117,39 @@ const Main = () => {
80117
{frameCoord ? (
81118
<span className="flex items-center justify-center space-x-2 opacity-70">
82119
<p>
83-
Rectangle: ({frameCoord.x0}, {frameCoord.y0}) ({frameCoord.x1},{' '}
84-
{frameCoord.y1})
120+
Rectangle: [
121+
<input
122+
className="w-16"
123+
value={frameCoord.x0}
124+
onChange={(e) =>
125+
setFrameCoordValue('x0', parseInt(e.target.value, 10))
126+
}
127+
/>
128+
,{' '}
129+
<input
130+
className="w-16"
131+
value={frameCoord.y0}
132+
onChange={(e) =>
133+
setFrameCoordValue('y0', parseInt(e.target.value, 10))
134+
}
135+
/>
136+
] [
137+
<input
138+
className="w-16"
139+
value={frameCoord.x1}
140+
onChange={(e) =>
141+
setFrameCoordValue('x1', parseInt(e.target.value, 10))
142+
}
143+
/>
144+
,{' '}
145+
<input
146+
className="w-16"
147+
value={frameCoord.y1}
148+
onChange={(e) =>
149+
setFrameCoordValue('y1', parseInt(e.target.value, 10))
150+
}
151+
/>
152+
]
85153
</p>
86154
<FaTimesCircle
87155
onClick={() => setFrameCoord(undefined)}
@@ -105,8 +173,23 @@ const Main = () => {
105173
{nextCoord ? (
106174
<span className="flex items-center justify-center space-x-2 opacity-70">
107175
<p>
108-
Point: ({(nextCoord.x0 + nextCoord.x1) / 2},{' '}
109-
{(nextCoord.y0 + nextCoord.y1) / 2})
176+
Point: [
177+
<input
178+
className="w-16"
179+
value={(nextCoord.x0 + nextCoord.x1) / 2}
180+
onChange={(e) =>
181+
setNextCoordValue('x', parseInt(e.target.value, 10))
182+
}
183+
/>
184+
,{' '}
185+
<input
186+
className="w-16"
187+
value={(nextCoord.y0 + nextCoord.y1) / 2}
188+
onChange={(e) =>
189+
setNextCoordValue('y', parseInt(e.target.value, 10))
190+
}
191+
/>
192+
]
110193
</p>
111194
<FaTimesCircle
112195
onClick={() => setNextCoord(undefined)}

0 commit comments

Comments
 (0)