quickwin 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +204 -204
- package/README.md +203 -203
- package/examples/PdfCanvas.tsx +83 -83
- package/examples/exec_server.ts +35 -35
- package/examples/pdf_preview2.ts +375 -375
- package/examples/pdf_viewer.tsx +279 -279
- package/examples/test_gallery.tsx +285 -285
- package/examples/test_react_lazy.tsx +63 -63
- package/examples/test_react_listbox.tsx +71 -71
- package/examples/test_root_window.tsx +41 -41
- package/examples/test_tab.tsx +75 -75
- package/examples/tray_demo.tsx +81 -81
- package/lib/assert.ts +6 -6
- package/lib/cache-utils.ts +40 -40
- package/lib/dumpRects.ts +25 -25
- package/lib/fetch.ts +502 -502
- package/lib/http-common.ts +399 -399
- package/lib/http-server.ts +424 -424
- package/lib/polyfill.ts +171 -171
- package/lib/react-qw/components/index.ts +17 -17
- package/lib/react-qw/index.ts +90 -90
- package/lib/react-qw/jsx.d.ts +34 -34
- package/lib/react-qw/layout.ts +111 -111
- package/lib/react-qw/props.ts +36 -36
- package/lib/react-qw/reconciler.ts +373 -373
- package/lib/stream.ts +21 -21
- package/lib/text-codec.ts +171 -171
- package/lib/text-measure.ts +54 -54
- package/lib/url.ts +201 -201
- package/lib/vendor/web-streams/ponyfill.d.mts +829 -829
- package/lib/vendor/web-streams/ponyfill.mjs +8 -8
- package/lib/websocket.js +8 -0
- package/lib/websocket.ts +563 -555
- package/package.json +50 -44
- package/qwin-nowasm-x86.exe +0 -0
- package/qwin-nowasm.exe +0 -0
- package/qwin-x86.exe +0 -0
- package/qwin.exe +0 -0
- package/test/run.ts +96 -96
- package/test/test_basic.ts +9 -9
- package/test/test_basic_fetch.ts +33 -33
- package/test/test_brotli.ts +52 -52
- package/test/test_fetch_cache.ts +187 -187
- package/test/test_ffi.ts +174 -174
- package/test/test_frame_encoding.ts +132 -132
- package/test/test_helper.ts +80 -80
- package/test/test_http_import.ts +74 -74
- package/test/test_http_server.ts +136 -136
- package/test/test_import_dir.ts +5 -5
- package/test/test_ipv6.ts +129 -129
- package/test/test_meta_url.ts +4 -4
- package/test/test_mupdf_render.ts +74 -74
- package/test/test_mupdf_twice.ts +81 -81
- package/test/test_mupdf_wasm.ts +30 -30
- package/test/test_net_event.ts +55 -55
- package/test/test_net_fetch.ts +238 -238
- package/test/test_net_websocket.ts +164 -164
- package/test/test_polyfill.ts +159 -159
- package/test/test_url.ts +183 -183
- package/test/test_wasm_basic.ts +73 -73
- package/test/test_wasm_import_global.ts +45 -45
- package/test/test_wasm_sjlj.ts +125 -125
- package/test/test_wasm_types.ts +124 -124
- package/test/test_worker.ts +24 -24
- package/test/test_worker_fetch.ts +27 -27
- package/test/test_worker_net.ts +54 -54
- package/test/test_worker_wasm_concurrent.ts +45 -45
- package/test/worker_fetch.ts +13 -13
- package/test/worker_helper.ts +1 -1
- package/test/worker_http.ts +20 -20
- package/test/worker_import_lib.ts +13 -13
- package/test/worker_module.ts +17 -17
- package/test/worker_wasm_concurrent.ts +22 -22
- package/tsconfig.json +27 -27
- package/vendor/mupdf-wasm/mupdf-wasm.d.ts +571 -571
- package/vendor/mupdf-wasm/mupdf-wasm.js +2749 -2749
- package/vendor/mupdf-wasm/mupdf.d.ts +939 -939
- package/vendor/mupdf-wasm/mupdf.js +3317 -3317
|
@@ -1,285 +1,285 @@
|
|
|
1
|
-
import '../lib/polyfill.js'
|
|
2
|
-
import * as gui from 'gui'
|
|
3
|
-
import { useState } from 'react'
|
|
4
|
-
import {
|
|
5
|
-
render, Button, Input, CheckBox, ProgressBar, ComboBox, Tab,
|
|
6
|
-
ListView, type Column, ListBox, ScrollView, RadioButton, Slider,
|
|
7
|
-
TreeView, type TreeNode, DateTimePicker, Link, Tooltip, PathPicker,
|
|
8
|
-
} from '../lib/react-qw/index.js'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
gui.RegisterClass('Gallery', (hwnd, msg, wParam, lParam) => {
|
|
12
|
-
if (!hwnd) return gui.DefWindowProc(hwnd, msg, wParam, lParam)
|
|
13
|
-
if (msg === gui.WmMsg.DESTROY) {
|
|
14
|
-
gui.PostQuitMessage(0)
|
|
15
|
-
return 0
|
|
16
|
-
}
|
|
17
|
-
return gui.DefWindowProc(hwnd, msg, wParam, lParam)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const VISIBLE = gui.WindowStyle.VISIBLE
|
|
21
|
-
const CLIPCHILDREN = gui.WindowStyle.CLIPCHILDREN
|
|
22
|
-
|
|
23
|
-
interface Fruit {
|
|
24
|
-
name: string
|
|
25
|
-
color: string
|
|
26
|
-
origin: string
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const treeData: TreeNode[] = [
|
|
30
|
-
{
|
|
31
|
-
key: 'fruits', label: 'Fruits',
|
|
32
|
-
children: [
|
|
33
|
-
{ key: 'apple', label: 'Apple' },
|
|
34
|
-
{ key: 'banana', label: 'Banana' },
|
|
35
|
-
{ key: 'cherry', label: 'Cherry' },
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
key: 'veggies', label: 'Vegetables',
|
|
40
|
-
children: [
|
|
41
|
-
{ key: 'carrot', label: 'Carrot' },
|
|
42
|
-
{ key: 'broccoli', label: 'Broccoli' },
|
|
43
|
-
],
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
key: 'meats', label: 'Meats',
|
|
47
|
-
children: [
|
|
48
|
-
{ key: 'chicken', label: 'Chicken' },
|
|
49
|
-
{ key: 'beef', label: 'Beef' },
|
|
50
|
-
{ key: 'pork', label: 'Pork' },
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
function App({ svW, svH }: { svW: number; svH: number }) {
|
|
56
|
-
const [count, setCount] = useState(0)
|
|
57
|
-
const [disabled, setDisabled] = useState(true)
|
|
58
|
-
const [inputText, setInputText] = useState('')
|
|
59
|
-
const [checkA, setCheckA] = useState(true)
|
|
60
|
-
const [checkB, setCheckB] = useState(false)
|
|
61
|
-
const [progress, setProgress] = useState(30)
|
|
62
|
-
const [lbSel, setLbSel] = useState(0)
|
|
63
|
-
const [cbSel, setCbSel] = useState(-1)
|
|
64
|
-
const [radio, setRadio] = useState('a')
|
|
65
|
-
const [sliderVal, setSliderVal] = useState(50)
|
|
66
|
-
const [treeSel, setTreeSel] = useState<TreeNode | null>(null)
|
|
67
|
-
const [dtDate, setDtDate] = useState<Date | null>(new Date())
|
|
68
|
-
const [pickerPath, setPickerPath] = useState('')
|
|
69
|
-
const [listData, setListData] = useState<Fruit[]>([
|
|
70
|
-
{ name: 'Apple', color: 'Red', origin: 'China' },
|
|
71
|
-
{ name: 'Banana', color: 'Yellow', origin: 'Philippines' },
|
|
72
|
-
{ name: 'Cherry', color: 'Dark Red', origin: 'USA' },
|
|
73
|
-
{ name: 'Date', color: 'Brown', origin: 'Middle East' },
|
|
74
|
-
{ name: 'Elderberry', color: 'Purple', origin: 'Europe' },
|
|
75
|
-
{ name: 'Fig', color: 'Purple', origin: 'Turkey' },
|
|
76
|
-
{ name: 'Grape', color: 'Green', origin: 'Italy' },
|
|
77
|
-
])
|
|
78
|
-
const [listCols, setListCols] = useState<Column<Fruit>[]>([
|
|
79
|
-
{ name: 'Name', dataIndex: 'name' },
|
|
80
|
-
{ name: 'Color', dataIndex: 'color' },
|
|
81
|
-
{ name: 'Origin', dataIndex: 'origin' },
|
|
82
|
-
])
|
|
83
|
-
const lbItems = listData.map(f => f.name)
|
|
84
|
-
const cbItems = ['Red', 'Green', 'Blue', 'Yellow', 'Purple', 'Orange']
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<ScrollView style={{width:svW, height:svH}} contentHeight={1600}>
|
|
88
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN | gui.WindowStyle.BORDER} style={{flexDirection:'column', gap:8, alignSelf:'stretch', flexGrow:1, padding:8}}>
|
|
89
|
-
{/* ===== 三列上半区 ===== */}
|
|
90
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:10, height:345}}>
|
|
91
|
-
|
|
92
|
-
{/* --- 左列: Buttons + CheckBoxes --- */}
|
|
93
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6, flexGrow:1}}>
|
|
94
|
-
<w type="STATIC" ws={VISIBLE} text="Buttons" style={{height:24}} />
|
|
95
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:30}}>
|
|
96
|
-
<Tooltip text="Click to increment counter" balloon>
|
|
97
|
-
<Button onClick={() => setCount(c => c + 1)} style={{flexGrow:1}}>
|
|
98
|
-
{`Clicked ${count} times`}
|
|
99
|
-
</Button>
|
|
100
|
-
</Tooltip>
|
|
101
|
-
<Button onClick={() => setCount(0)} style={{width:70}}>
|
|
102
|
-
Reset
|
|
103
|
-
</Button>
|
|
104
|
-
</w>
|
|
105
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:30}}>
|
|
106
|
-
<Button onClick={() => setDisabled(d => !d)} style={{flexGrow:1}}>
|
|
107
|
-
{`Toggle disabled (${String(disabled)})`}
|
|
108
|
-
</Button>
|
|
109
|
-
<Button disabled={disabled} style={{width:80}}>
|
|
110
|
-
Disabled
|
|
111
|
-
</Button>
|
|
112
|
-
</w>
|
|
113
|
-
<w type="STATIC" ws={VISIBLE} text="CheckBoxes" style={{height:24}} />
|
|
114
|
-
<CheckBox checked={checkA} onChange={setCheckA} label={`Option A (${String(checkA)})`} style={{height:26}} />
|
|
115
|
-
<CheckBox checked={checkB} onChange={setCheckB} label={`Option B (${String(checkB)})`} style={{height:26}} />
|
|
116
|
-
<CheckBox label="Disabled checkbox" disabled style={{height:26}} />
|
|
117
|
-
<w type="STATIC" ws={VISIBLE} text={`RadioButtons (${radio})`} style={{height:24}} />
|
|
118
|
-
<RadioButton checked={radio === 'a'} onChange={() => setRadio('a')} label="Option A" style={{height:24}} />
|
|
119
|
-
<RadioButton checked={radio === 'b'} onChange={() => setRadio('b')} label="Option B" style={{height:24}} />
|
|
120
|
-
<RadioButton checked={radio === 'c'} onChange={() => setRadio('c')} label="Option C" style={{height:24}} />
|
|
121
|
-
</w>
|
|
122
|
-
|
|
123
|
-
{/* --- 中列: Input + ProgressBar --- */}
|
|
124
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6, flexGrow:1}}>
|
|
125
|
-
<w type="STATIC" ws={VISIBLE} text="Input" style={{height:24}} />
|
|
126
|
-
<Input value={inputText} onChange={setInputText} placeholder="Type here..." style={{height:28}} />
|
|
127
|
-
<Input placeholder="Password" password style={{height:28}} />
|
|
128
|
-
<Input value="Read only" readonly style={{height:28}} />
|
|
129
|
-
<w type="STATIC" ws={VISIBLE} text="ProgressBar" style={{height:24}} />
|
|
130
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:24}}>
|
|
131
|
-
<ProgressBar value={progress} max={100} smooth style={{flexGrow:1}} />
|
|
132
|
-
<w type="STATIC" ws={VISIBLE} text={`${progress}%`} style={{width:40}} />
|
|
133
|
-
</w>
|
|
134
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:30}}>
|
|
135
|
-
<Button onClick={() => setProgress(p => Math.min(100, p + 10))} style={{flexGrow:1}}>
|
|
136
|
-
+10
|
|
137
|
-
</Button>
|
|
138
|
-
<Button onClick={() => setProgress(p => Math.max(0, p - 10))} style={{flexGrow:1}}>
|
|
139
|
-
-10
|
|
140
|
-
</Button>
|
|
141
|
-
<Button onClick={() => setProgress(0)} style={{width:50}}>
|
|
142
|
-
0
|
|
143
|
-
</Button>
|
|
144
|
-
</w>
|
|
145
|
-
<w type="STATIC" ws={VISIBLE} text={`Slider (${sliderVal})`} style={{height:24}} />
|
|
146
|
-
<Slider value={sliderVal} onChange={setSliderVal} min={0} max={100} style={{height:30}} />
|
|
147
|
-
</w>
|
|
148
|
-
|
|
149
|
-
{/* --- 右列: ListBox + ComboBox --- */}
|
|
150
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6, flexGrow:1}}>
|
|
151
|
-
<w type="STATIC" ws={VISIBLE} text={`ListBox (sel=${lbSel >= 0 ? lbItems[lbSel] : 'none'})`} style={{height:24}} />
|
|
152
|
-
<ListBox items={lbItems} selectedIndex={lbSel} onChange={(i) => setLbSel(i)} style={{flexGrow:1}} />
|
|
153
|
-
<w type="STATIC" ws={VISIBLE} text="ComboBox" style={{height:24}} />
|
|
154
|
-
<ComboBox items={cbItems} selectedIndex={cbSel} onChange={(i) => setCbSel(i)} style={{height:26}} />
|
|
155
|
-
<w type="STATIC" ws={VISIBLE}
|
|
156
|
-
text={cbSel >= 0 ? `Selected: ${cbItems[cbSel]}` : '(none selected)'}
|
|
157
|
-
style={{height:24}} />
|
|
158
|
-
</w>
|
|
159
|
-
</w>
|
|
160
|
-
|
|
161
|
-
{/* ===== Auto-Size ===== */}
|
|
162
|
-
<w type="STATIC" ws={VISIBLE} text="Auto-Size" style={{height:24}} />
|
|
163
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN | gui.WindowStyle.BORDER} style={{flexDirection:'column', gap:6, alignSelf:'stretch', flexGrow:1}}>
|
|
164
|
-
<w type="STATIC" ws={VISIBLE} text="Buttons (auto width)" style={{height:24}} />
|
|
165
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:30}}>
|
|
166
|
-
<Button style={{width:'auto', height:30}}>OK</Button>
|
|
167
|
-
<Button style={{width:'auto', height:30}}>Cancel</Button>
|
|
168
|
-
<Button style={{width:'auto', height:30}}>A very long button text</Button>
|
|
169
|
-
</w>
|
|
170
|
-
<w type="STATIC" ws={VISIBLE} text="Statics (auto width)" style={{height:24}} />
|
|
171
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:24}}>
|
|
172
|
-
<w type="STATIC" ws={VISIBLE | gui.WindowStyle.BORDER} text="Short" style={{width:'auto', height:24}} />
|
|
173
|
-
<w type="STATIC" ws={VISIBLE | gui.WindowStyle.BORDER} text="A much longer label" style={{width:'auto', height:24}} />
|
|
174
|
-
</w>
|
|
175
|
-
<w type="STATIC" ws={VISIBLE} text="Mixed auto + fixed" style={{height:24}} />
|
|
176
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:30}}>
|
|
177
|
-
<Button style={{width:150, height:30}}>Fixed 150</Button>
|
|
178
|
-
<Button style={{width:'auto', height:30}}>Auto</Button>
|
|
179
|
-
</w>
|
|
180
|
-
</w>
|
|
181
|
-
|
|
182
|
-
{/* ===== Tab Demo ===== */}
|
|
183
|
-
<w type="STATIC" ws={VISIBLE} text="Tab" style={{height:24}} />
|
|
184
|
-
<Tab
|
|
185
|
-
tabs={[
|
|
186
|
-
{ title: 'Counter', content: (
|
|
187
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6}}>
|
|
188
|
-
<w type="STATIC" ws={VISIBLE} text={`Count: ${count}`} style={{height:24}} />
|
|
189
|
-
<Button onClick={() => setCount(c => c + 1)} style={{width:80}}>+1</Button>
|
|
190
|
-
</w>
|
|
191
|
-
)},
|
|
192
|
-
{ title: 'Typing', content: (
|
|
193
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6}}>
|
|
194
|
-
<Input value={inputText} onChange={setInputText} placeholder="Type here..." style={{height:28}} />
|
|
195
|
-
<w type="STATIC" ws={VISIBLE} text={inputText ? `You typed: ${inputText}` : '(empty)'} style={{height:24}} />
|
|
196
|
-
</w>
|
|
197
|
-
)},
|
|
198
|
-
]}
|
|
199
|
-
style={{height:120}}
|
|
200
|
-
/>
|
|
201
|
-
|
|
202
|
-
{/* ===== DateTimePicker ===== */}
|
|
203
|
-
<w type="STATIC" ws={VISIBLE} text={`DateTimePicker (${dtDate ? `${dtDate.getFullYear()}-${String(dtDate.getMonth()+1).padStart(2,'0')}-${String(dtDate.getDate()).padStart(2,'0')}` : 'none'})`} style={{height:24}} />
|
|
204
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:28}}>
|
|
205
|
-
<DateTimePicker value={dtDate} onChange={setDtDate} style={{flexGrow:1}} />
|
|
206
|
-
<DateTimePicker value={dtDate} onChange={setDtDate} format="long" style={{flexGrow:1}} />
|
|
207
|
-
<DateTimePicker value={dtDate} onChange={setDtDate} format="time" style={{flexGrow:1}} />
|
|
208
|
-
</w>
|
|
209
|
-
|
|
210
|
-
{/* ===== SysLink ===== */}
|
|
211
|
-
<w type="STATIC" ws={VISIBLE} text="SysLink" style={{height:24}} />
|
|
212
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:28}}>
|
|
213
|
-
<Link href="https://example.com" onClick={(url) => console.log('Link clicked:', url)} style={{flexGrow:1}}>
|
|
214
|
-
Example Link
|
|
215
|
-
</Link>
|
|
216
|
-
<Link href="https://github.com" onClick={(url) => console.log('Link clicked:', url)} style={{flexGrow:1}} />
|
|
217
|
-
</w>
|
|
218
|
-
|
|
219
|
-
{/* ===== PathPicker ===== */}
|
|
220
|
-
<w type="STATIC" ws={VISIBLE} text="PathPicker" style={{height:24}} />
|
|
221
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'column', gap:6, height:130}}>
|
|
222
|
-
<PathPicker type="file" title="Select a file" style={{height:28}} />
|
|
223
|
-
<PathPicker type="folder" title="Select a folder" style={{height:28}} />
|
|
224
|
-
<PathPicker type="file" value={pickerPath} onChange={setPickerPath} title="Controlled" style={{height:28}} />
|
|
225
|
-
<w type="STATIC" ws={VISIBLE} text={pickerPath ? `Selected: ${pickerPath}` : '(none)'} style={{height:20}} />
|
|
226
|
-
</w>
|
|
227
|
-
|
|
228
|
-
{/* ===== 下半区: ListView + ScrollView + TreeView ===== */}
|
|
229
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:400}}>
|
|
230
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:4, flexGrow:1}}>
|
|
231
|
-
<w type="STATIC" ws={VISIBLE} text={`ListView (${listData.length} items)`} style={{height:24}} />
|
|
232
|
-
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', flexGrow:1}}>
|
|
233
|
-
<ListView<Fruit>
|
|
234
|
-
columns={listCols}
|
|
235
|
-
data={listData}
|
|
236
|
-
style={{flexGrow:1}}
|
|
237
|
-
/>
|
|
238
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6, width:100}}>
|
|
239
|
-
<Button onClick={() => setListData(d => [...d, { name: 'NewItem ' + String(listData.length + 1), color: '', origin: '' }])} style={{height:28}}>
|
|
240
|
-
Add
|
|
241
|
-
</Button>
|
|
242
|
-
<Button onClick={() => setListCols(cols => [...cols, { name: 'Col' + (listCols.length + 1), dataIndex: 'name' as keyof Fruit }])} style={{height:28}}>
|
|
243
|
-
+Column
|
|
244
|
-
</Button>
|
|
245
|
-
</w>
|
|
246
|
-
</w>
|
|
247
|
-
</w>
|
|
248
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:4, flexGrow:1}}>
|
|
249
|
-
<w type="STATIC" ws={VISIBLE} text="ScrollView (scrollable)" style={{height:24}} />
|
|
250
|
-
<ScrollView style={{flexGrow:1}} contentWidth={500} contentHeight={560}>
|
|
251
|
-
{Array.from({ length: 20 }, (_, i) => (
|
|
252
|
-
<w type="STATIC" ws={VISIBLE}
|
|
253
|
-
key={i}
|
|
254
|
-
text={`Item ${i + 1} - ${i === 0 ? 'here is a line so wide that the horizontal scrollbar appears for demonstration' : ''}`}
|
|
255
|
-
style={{width: i === 0 ? 500 : 200, height:28}}
|
|
256
|
-
/>
|
|
257
|
-
))}
|
|
258
|
-
</ScrollView>
|
|
259
|
-
</w>
|
|
260
|
-
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:4, flexGrow:1}}>
|
|
261
|
-
<w type="STATIC" ws={VISIBLE} text={`TreeView (sel=${treeSel?.label ?? 'none'})`} style={{height:24}} />
|
|
262
|
-
<TreeView data={treeData} onSelect={setTreeSel} style={{flexGrow:1}} />
|
|
263
|
-
</w>
|
|
264
|
-
</w>
|
|
265
|
-
</w>
|
|
266
|
-
</ScrollView>
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const hwnd = gui.CreateWindow(
|
|
271
|
-
'Gallery', 'Component Gallery',
|
|
272
|
-
gui.WindowStyle.OVERLAPPEDWINDOW,
|
|
273
|
-
100, 100, 1400, 1200, null, null
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
if (hwnd) {
|
|
277
|
-
const cr = gui.GetClientRect(hwnd)!
|
|
278
|
-
const scale = gui.GetScaleFactor()
|
|
279
|
-
const svW = Math.round((cr.right - cr.left) / scale)
|
|
280
|
-
const svH = Math.round((cr.bottom - cr.top) / scale)
|
|
281
|
-
render(<App svW={svW} svH={svH} />, hwnd)
|
|
282
|
-
setTimeout(() => {
|
|
283
|
-
gui.ShowWindow(hwnd)
|
|
284
|
-
}, 0)
|
|
285
|
-
}
|
|
1
|
+
import '../lib/polyfill.js'
|
|
2
|
+
import * as gui from 'gui'
|
|
3
|
+
import { useState } from 'react'
|
|
4
|
+
import {
|
|
5
|
+
render, Button, Input, CheckBox, ProgressBar, ComboBox, Tab,
|
|
6
|
+
ListView, type Column, ListBox, ScrollView, RadioButton, Slider,
|
|
7
|
+
TreeView, type TreeNode, DateTimePicker, Link, Tooltip, PathPicker,
|
|
8
|
+
} from '../lib/react-qw/index.js'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
gui.RegisterClass('Gallery', (hwnd, msg, wParam, lParam) => {
|
|
12
|
+
if (!hwnd) return gui.DefWindowProc(hwnd, msg, wParam, lParam)
|
|
13
|
+
if (msg === gui.WmMsg.DESTROY) {
|
|
14
|
+
gui.PostQuitMessage(0)
|
|
15
|
+
return 0
|
|
16
|
+
}
|
|
17
|
+
return gui.DefWindowProc(hwnd, msg, wParam, lParam)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const VISIBLE = gui.WindowStyle.VISIBLE
|
|
21
|
+
const CLIPCHILDREN = gui.WindowStyle.CLIPCHILDREN
|
|
22
|
+
|
|
23
|
+
interface Fruit {
|
|
24
|
+
name: string
|
|
25
|
+
color: string
|
|
26
|
+
origin: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const treeData: TreeNode[] = [
|
|
30
|
+
{
|
|
31
|
+
key: 'fruits', label: 'Fruits',
|
|
32
|
+
children: [
|
|
33
|
+
{ key: 'apple', label: 'Apple' },
|
|
34
|
+
{ key: 'banana', label: 'Banana' },
|
|
35
|
+
{ key: 'cherry', label: 'Cherry' },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
key: 'veggies', label: 'Vegetables',
|
|
40
|
+
children: [
|
|
41
|
+
{ key: 'carrot', label: 'Carrot' },
|
|
42
|
+
{ key: 'broccoli', label: 'Broccoli' },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
key: 'meats', label: 'Meats',
|
|
47
|
+
children: [
|
|
48
|
+
{ key: 'chicken', label: 'Chicken' },
|
|
49
|
+
{ key: 'beef', label: 'Beef' },
|
|
50
|
+
{ key: 'pork', label: 'Pork' },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
function App({ svW, svH }: { svW: number; svH: number }) {
|
|
56
|
+
const [count, setCount] = useState(0)
|
|
57
|
+
const [disabled, setDisabled] = useState(true)
|
|
58
|
+
const [inputText, setInputText] = useState('')
|
|
59
|
+
const [checkA, setCheckA] = useState(true)
|
|
60
|
+
const [checkB, setCheckB] = useState(false)
|
|
61
|
+
const [progress, setProgress] = useState(30)
|
|
62
|
+
const [lbSel, setLbSel] = useState(0)
|
|
63
|
+
const [cbSel, setCbSel] = useState(-1)
|
|
64
|
+
const [radio, setRadio] = useState('a')
|
|
65
|
+
const [sliderVal, setSliderVal] = useState(50)
|
|
66
|
+
const [treeSel, setTreeSel] = useState<TreeNode | null>(null)
|
|
67
|
+
const [dtDate, setDtDate] = useState<Date | null>(new Date())
|
|
68
|
+
const [pickerPath, setPickerPath] = useState('')
|
|
69
|
+
const [listData, setListData] = useState<Fruit[]>([
|
|
70
|
+
{ name: 'Apple', color: 'Red', origin: 'China' },
|
|
71
|
+
{ name: 'Banana', color: 'Yellow', origin: 'Philippines' },
|
|
72
|
+
{ name: 'Cherry', color: 'Dark Red', origin: 'USA' },
|
|
73
|
+
{ name: 'Date', color: 'Brown', origin: 'Middle East' },
|
|
74
|
+
{ name: 'Elderberry', color: 'Purple', origin: 'Europe' },
|
|
75
|
+
{ name: 'Fig', color: 'Purple', origin: 'Turkey' },
|
|
76
|
+
{ name: 'Grape', color: 'Green', origin: 'Italy' },
|
|
77
|
+
])
|
|
78
|
+
const [listCols, setListCols] = useState<Column<Fruit>[]>([
|
|
79
|
+
{ name: 'Name', dataIndex: 'name' },
|
|
80
|
+
{ name: 'Color', dataIndex: 'color' },
|
|
81
|
+
{ name: 'Origin', dataIndex: 'origin' },
|
|
82
|
+
])
|
|
83
|
+
const lbItems = listData.map(f => f.name)
|
|
84
|
+
const cbItems = ['Red', 'Green', 'Blue', 'Yellow', 'Purple', 'Orange']
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<ScrollView style={{width:svW, height:svH}} contentHeight={1600}>
|
|
88
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN | gui.WindowStyle.BORDER} style={{flexDirection:'column', gap:8, alignSelf:'stretch', flexGrow:1, padding:8}}>
|
|
89
|
+
{/* ===== 三列上半区 ===== */}
|
|
90
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:10, height:345}}>
|
|
91
|
+
|
|
92
|
+
{/* --- 左列: Buttons + CheckBoxes --- */}
|
|
93
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6, flexGrow:1}}>
|
|
94
|
+
<w type="STATIC" ws={VISIBLE} text="Buttons" style={{height:24}} />
|
|
95
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:30}}>
|
|
96
|
+
<Tooltip text="Click to increment counter" balloon>
|
|
97
|
+
<Button onClick={() => setCount(c => c + 1)} style={{flexGrow:1}}>
|
|
98
|
+
{`Clicked ${count} times`}
|
|
99
|
+
</Button>
|
|
100
|
+
</Tooltip>
|
|
101
|
+
<Button onClick={() => setCount(0)} style={{width:70}}>
|
|
102
|
+
Reset
|
|
103
|
+
</Button>
|
|
104
|
+
</w>
|
|
105
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:30}}>
|
|
106
|
+
<Button onClick={() => setDisabled(d => !d)} style={{flexGrow:1}}>
|
|
107
|
+
{`Toggle disabled (${String(disabled)})`}
|
|
108
|
+
</Button>
|
|
109
|
+
<Button disabled={disabled} style={{width:80}}>
|
|
110
|
+
Disabled
|
|
111
|
+
</Button>
|
|
112
|
+
</w>
|
|
113
|
+
<w type="STATIC" ws={VISIBLE} text="CheckBoxes" style={{height:24}} />
|
|
114
|
+
<CheckBox checked={checkA} onChange={setCheckA} label={`Option A (${String(checkA)})`} style={{height:26}} />
|
|
115
|
+
<CheckBox checked={checkB} onChange={setCheckB} label={`Option B (${String(checkB)})`} style={{height:26}} />
|
|
116
|
+
<CheckBox label="Disabled checkbox" disabled style={{height:26}} />
|
|
117
|
+
<w type="STATIC" ws={VISIBLE} text={`RadioButtons (${radio})`} style={{height:24}} />
|
|
118
|
+
<RadioButton checked={radio === 'a'} onChange={() => setRadio('a')} label="Option A" style={{height:24}} />
|
|
119
|
+
<RadioButton checked={radio === 'b'} onChange={() => setRadio('b')} label="Option B" style={{height:24}} />
|
|
120
|
+
<RadioButton checked={radio === 'c'} onChange={() => setRadio('c')} label="Option C" style={{height:24}} />
|
|
121
|
+
</w>
|
|
122
|
+
|
|
123
|
+
{/* --- 中列: Input + ProgressBar --- */}
|
|
124
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6, flexGrow:1}}>
|
|
125
|
+
<w type="STATIC" ws={VISIBLE} text="Input" style={{height:24}} />
|
|
126
|
+
<Input value={inputText} onChange={setInputText} placeholder="Type here..." style={{height:28}} />
|
|
127
|
+
<Input placeholder="Password" password style={{height:28}} />
|
|
128
|
+
<Input value="Read only" readonly style={{height:28}} />
|
|
129
|
+
<w type="STATIC" ws={VISIBLE} text="ProgressBar" style={{height:24}} />
|
|
130
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:24}}>
|
|
131
|
+
<ProgressBar value={progress} max={100} smooth style={{flexGrow:1}} />
|
|
132
|
+
<w type="STATIC" ws={VISIBLE} text={`${progress}%`} style={{width:40}} />
|
|
133
|
+
</w>
|
|
134
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:30}}>
|
|
135
|
+
<Button onClick={() => setProgress(p => Math.min(100, p + 10))} style={{flexGrow:1}}>
|
|
136
|
+
+10
|
|
137
|
+
</Button>
|
|
138
|
+
<Button onClick={() => setProgress(p => Math.max(0, p - 10))} style={{flexGrow:1}}>
|
|
139
|
+
-10
|
|
140
|
+
</Button>
|
|
141
|
+
<Button onClick={() => setProgress(0)} style={{width:50}}>
|
|
142
|
+
0
|
|
143
|
+
</Button>
|
|
144
|
+
</w>
|
|
145
|
+
<w type="STATIC" ws={VISIBLE} text={`Slider (${sliderVal})`} style={{height:24}} />
|
|
146
|
+
<Slider value={sliderVal} onChange={setSliderVal} min={0} max={100} style={{height:30}} />
|
|
147
|
+
</w>
|
|
148
|
+
|
|
149
|
+
{/* --- 右列: ListBox + ComboBox --- */}
|
|
150
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6, flexGrow:1}}>
|
|
151
|
+
<w type="STATIC" ws={VISIBLE} text={`ListBox (sel=${lbSel >= 0 ? lbItems[lbSel] : 'none'})`} style={{height:24}} />
|
|
152
|
+
<ListBox items={lbItems} selectedIndex={lbSel} onChange={(i) => setLbSel(i)} style={{flexGrow:1}} />
|
|
153
|
+
<w type="STATIC" ws={VISIBLE} text="ComboBox" style={{height:24}} />
|
|
154
|
+
<ComboBox items={cbItems} selectedIndex={cbSel} onChange={(i) => setCbSel(i)} style={{height:26}} />
|
|
155
|
+
<w type="STATIC" ws={VISIBLE}
|
|
156
|
+
text={cbSel >= 0 ? `Selected: ${cbItems[cbSel]}` : '(none selected)'}
|
|
157
|
+
style={{height:24}} />
|
|
158
|
+
</w>
|
|
159
|
+
</w>
|
|
160
|
+
|
|
161
|
+
{/* ===== Auto-Size ===== */}
|
|
162
|
+
<w type="STATIC" ws={VISIBLE} text="Auto-Size" style={{height:24}} />
|
|
163
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN | gui.WindowStyle.BORDER} style={{flexDirection:'column', gap:6, alignSelf:'stretch', flexGrow:1}}>
|
|
164
|
+
<w type="STATIC" ws={VISIBLE} text="Buttons (auto width)" style={{height:24}} />
|
|
165
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:30}}>
|
|
166
|
+
<Button style={{width:'auto', height:30}}>OK</Button>
|
|
167
|
+
<Button style={{width:'auto', height:30}}>Cancel</Button>
|
|
168
|
+
<Button style={{width:'auto', height:30}}>A very long button text</Button>
|
|
169
|
+
</w>
|
|
170
|
+
<w type="STATIC" ws={VISIBLE} text="Statics (auto width)" style={{height:24}} />
|
|
171
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:24}}>
|
|
172
|
+
<w type="STATIC" ws={VISIBLE | gui.WindowStyle.BORDER} text="Short" style={{width:'auto', height:24}} />
|
|
173
|
+
<w type="STATIC" ws={VISIBLE | gui.WindowStyle.BORDER} text="A much longer label" style={{width:'auto', height:24}} />
|
|
174
|
+
</w>
|
|
175
|
+
<w type="STATIC" ws={VISIBLE} text="Mixed auto + fixed" style={{height:24}} />
|
|
176
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:30}}>
|
|
177
|
+
<Button style={{width:150, height:30}}>Fixed 150</Button>
|
|
178
|
+
<Button style={{width:'auto', height:30}}>Auto</Button>
|
|
179
|
+
</w>
|
|
180
|
+
</w>
|
|
181
|
+
|
|
182
|
+
{/* ===== Tab Demo ===== */}
|
|
183
|
+
<w type="STATIC" ws={VISIBLE} text="Tab" style={{height:24}} />
|
|
184
|
+
<Tab
|
|
185
|
+
tabs={[
|
|
186
|
+
{ title: 'Counter', content: (
|
|
187
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6}}>
|
|
188
|
+
<w type="STATIC" ws={VISIBLE} text={`Count: ${count}`} style={{height:24}} />
|
|
189
|
+
<Button onClick={() => setCount(c => c + 1)} style={{width:80}}>+1</Button>
|
|
190
|
+
</w>
|
|
191
|
+
)},
|
|
192
|
+
{ title: 'Typing', content: (
|
|
193
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6}}>
|
|
194
|
+
<Input value={inputText} onChange={setInputText} placeholder="Type here..." style={{height:28}} />
|
|
195
|
+
<w type="STATIC" ws={VISIBLE} text={inputText ? `You typed: ${inputText}` : '(empty)'} style={{height:24}} />
|
|
196
|
+
</w>
|
|
197
|
+
)},
|
|
198
|
+
]}
|
|
199
|
+
style={{height:120}}
|
|
200
|
+
/>
|
|
201
|
+
|
|
202
|
+
{/* ===== DateTimePicker ===== */}
|
|
203
|
+
<w type="STATIC" ws={VISIBLE} text={`DateTimePicker (${dtDate ? `${dtDate.getFullYear()}-${String(dtDate.getMonth()+1).padStart(2,'0')}-${String(dtDate.getDate()).padStart(2,'0')}` : 'none'})`} style={{height:24}} />
|
|
204
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:28}}>
|
|
205
|
+
<DateTimePicker value={dtDate} onChange={setDtDate} style={{flexGrow:1}} />
|
|
206
|
+
<DateTimePicker value={dtDate} onChange={setDtDate} format="long" style={{flexGrow:1}} />
|
|
207
|
+
<DateTimePicker value={dtDate} onChange={setDtDate} format="time" style={{flexGrow:1}} />
|
|
208
|
+
</w>
|
|
209
|
+
|
|
210
|
+
{/* ===== SysLink ===== */}
|
|
211
|
+
<w type="STATIC" ws={VISIBLE} text="SysLink" style={{height:24}} />
|
|
212
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:8, alignItems:'stretch', height:28}}>
|
|
213
|
+
<Link href="https://example.com" onClick={(url) => console.log('Link clicked:', url)} style={{flexGrow:1}}>
|
|
214
|
+
Example Link
|
|
215
|
+
</Link>
|
|
216
|
+
<Link href="https://github.com" onClick={(url) => console.log('Link clicked:', url)} style={{flexGrow:1}} />
|
|
217
|
+
</w>
|
|
218
|
+
|
|
219
|
+
{/* ===== PathPicker ===== */}
|
|
220
|
+
<w type="STATIC" ws={VISIBLE} text="PathPicker" style={{height:24}} />
|
|
221
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'column', gap:6, height:130}}>
|
|
222
|
+
<PathPicker type="file" title="Select a file" style={{height:28}} />
|
|
223
|
+
<PathPicker type="folder" title="Select a folder" style={{height:28}} />
|
|
224
|
+
<PathPicker type="file" value={pickerPath} onChange={setPickerPath} title="Controlled" style={{height:28}} />
|
|
225
|
+
<w type="STATIC" ws={VISIBLE} text={pickerPath ? `Selected: ${pickerPath}` : '(none)'} style={{height:20}} />
|
|
226
|
+
</w>
|
|
227
|
+
|
|
228
|
+
{/* ===== 下半区: ListView + ScrollView + TreeView ===== */}
|
|
229
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', height:400}}>
|
|
230
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:4, flexGrow:1}}>
|
|
231
|
+
<w type="STATIC" ws={VISIBLE} text={`ListView (${listData.length} items)`} style={{height:24}} />
|
|
232
|
+
<w type="STATIC" ws={VISIBLE} style={{flexDirection:'row', gap:6, alignItems:'stretch', flexGrow:1}}>
|
|
233
|
+
<ListView<Fruit>
|
|
234
|
+
columns={listCols}
|
|
235
|
+
data={listData}
|
|
236
|
+
style={{flexGrow:1}}
|
|
237
|
+
/>
|
|
238
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:6, width:100}}>
|
|
239
|
+
<Button onClick={() => setListData(d => [...d, { name: 'NewItem ' + String(listData.length + 1), color: '', origin: '' }])} style={{height:28}}>
|
|
240
|
+
Add
|
|
241
|
+
</Button>
|
|
242
|
+
<Button onClick={() => setListCols(cols => [...cols, { name: 'Col' + (listCols.length + 1), dataIndex: 'name' as keyof Fruit }])} style={{height:28}}>
|
|
243
|
+
+Column
|
|
244
|
+
</Button>
|
|
245
|
+
</w>
|
|
246
|
+
</w>
|
|
247
|
+
</w>
|
|
248
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:4, flexGrow:1}}>
|
|
249
|
+
<w type="STATIC" ws={VISIBLE} text="ScrollView (scrollable)" style={{height:24}} />
|
|
250
|
+
<ScrollView style={{flexGrow:1}} contentWidth={500} contentHeight={560}>
|
|
251
|
+
{Array.from({ length: 20 }, (_, i) => (
|
|
252
|
+
<w type="STATIC" ws={VISIBLE}
|
|
253
|
+
key={i}
|
|
254
|
+
text={`Item ${i + 1} - ${i === 0 ? 'here is a line so wide that the horizontal scrollbar appears for demonstration' : ''}`}
|
|
255
|
+
style={{width: i === 0 ? 500 : 200, height:28}}
|
|
256
|
+
/>
|
|
257
|
+
))}
|
|
258
|
+
</ScrollView>
|
|
259
|
+
</w>
|
|
260
|
+
<w type="STATIC" ws={VISIBLE | CLIPCHILDREN} style={{flexDirection:'column', gap:4, flexGrow:1}}>
|
|
261
|
+
<w type="STATIC" ws={VISIBLE} text={`TreeView (sel=${treeSel?.label ?? 'none'})`} style={{height:24}} />
|
|
262
|
+
<TreeView data={treeData} onSelect={setTreeSel} style={{flexGrow:1}} />
|
|
263
|
+
</w>
|
|
264
|
+
</w>
|
|
265
|
+
</w>
|
|
266
|
+
</ScrollView>
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const hwnd = gui.CreateWindow(
|
|
271
|
+
'Gallery', 'Component Gallery',
|
|
272
|
+
gui.WindowStyle.OVERLAPPEDWINDOW,
|
|
273
|
+
100, 100, 1400, 1200, null, null
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
if (hwnd) {
|
|
277
|
+
const cr = gui.GetClientRect(hwnd)!
|
|
278
|
+
const scale = gui.GetScaleFactor()
|
|
279
|
+
const svW = Math.round((cr.right - cr.left) / scale)
|
|
280
|
+
const svH = Math.round((cr.bottom - cr.top) / scale)
|
|
281
|
+
render(<App svW={svW} svH={svH} />, hwnd)
|
|
282
|
+
setTimeout(() => {
|
|
283
|
+
gui.ShowWindow(hwnd)
|
|
284
|
+
}, 0)
|
|
285
|
+
}
|