gpui-rsx 0.2.2

A JSX-like macro for GPUI - simplify UI development with HTML-like syntax
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
#![allow(dead_code)]

//! 共享 Mock GPUI 类型
//!
//! 所有测试文件共用的 MockElement 和辅助函数,
//! 避免在 macro_tests.rs 和 coverage_tests.rs 中重复定义。

/// Mock Element,模拟 GPUI 的 Div / Stateful<Div>。
/// 所有 builder 方法返回 Self 以支持方法链。
#[derive(Debug)]
pub struct MockElement;

/// Styled trait,用于动态 class 的运行时解析
pub trait Styled: Sized {
    fn flex(self) -> Self;
    fn flex_col(self) -> Self;
    fn flex_row(self) -> Self;
    fn flex_1(self) -> Self;
    fn flex_wrap(self) -> Self;
    fn items_center(self) -> Self;
    fn items_start(self) -> Self;
    fn items_end(self) -> Self;
    fn justify_center(self) -> Self;
    fn justify_between(self) -> Self;
    fn justify_start(self) -> Self;
    fn justify_end(self) -> Self;
    fn gap<T>(self, v: T) -> Self;
    fn p<T>(self, v: T) -> Self;
    fn px<T>(self, v: T) -> Self;
    fn py<T>(self, v: T) -> Self;
    fn m<T>(self, v: T) -> Self;
    fn w_full(self) -> Self;
    fn h_full(self) -> Self;
    fn size_full(self) -> Self;
    fn text_xs(self) -> Self;
    fn text_sm(self) -> Self;
    fn text_base(self) -> Self;
    fn text_lg(self) -> Self;
    fn text_xl(self) -> Self;
    fn text_2xl(self) -> Self;
    fn text_3xl(self) -> Self;
    fn font_bold(self) -> Self;
    fn border_1(self) -> Self;
    fn border_2(self) -> Self;
    fn rounded_sm(self) -> Self;
    fn rounded_md(self) -> Self;
    fn rounded_lg(self) -> Self;
    fn rounded_full(self) -> Self;
    fn cursor_pointer(self) -> Self;
    fn overflow_hidden(self) -> Self;
    fn overflow_scroll(self) -> Self;
    fn absolute(self) -> Self;
    fn relative(self) -> Self;
    fn bg<T>(self, v: T) -> Self;
    fn text_color<T>(self, v: T) -> Self;
    fn border_color<T>(self, v: T) -> Self;
}

// 模拟 GPUI 构造函数
#[allow(dead_code)]
pub fn div() -> MockElement {
    MockElement
}
#[allow(dead_code)]
pub fn svg() -> MockElement {
    MockElement
}
#[allow(dead_code)]
pub fn img() -> MockElement {
    MockElement
}
#[allow(dead_code)]
pub fn canvas() -> MockElement {
    MockElement
}
pub fn rgb(_hex: u32) -> u32 {
    0
}
pub fn px(_val: f32) -> f32 {
    0.0
}

// 模拟自定义组件构造函数
#[allow(non_snake_case, dead_code)]
pub fn MyComponent() -> MockElement {
    MockElement
}
#[allow(non_snake_case, dead_code)]
pub fn CustomWidget() -> MockElement {
    MockElement
}

#[allow(dead_code)]
impl MockElement {
    // --- 身份 ---
    pub fn id<T>(self, _: T) -> Self {
        self
    }

    // --- 布局 ---
    pub fn flex_grow<T>(self, _: T) -> Self {
        self
    }
    pub fn flex_shrink<T>(self, _: T) -> Self {
        self
    }

    // --- 间距(参数化 + 预设) ---
    pub fn gap_2(self) -> Self {
        self
    }
    pub fn gap_3(self) -> Self {
        self
    }
    pub fn gap_4(self) -> Self {
        self
    }
    pub fn gap_6(self) -> Self {
        self
    }
    pub fn p_2(self) -> Self {
        self
    }
    pub fn p_3(self) -> Self {
        self
    }
    pub fn p_4(self) -> Self {
        self
    }
    pub fn pt<T>(self, _: T) -> Self {
        self
    }
    pub fn pb<T>(self, _: T) -> Self {
        self
    }
    pub fn pl<T>(self, _: T) -> Self {
        self
    }
    pub fn pr<T>(self, _: T) -> Self {
        self
    }
    pub fn px_2(self) -> Self {
        self
    }
    pub fn px_3(self) -> Self {
        self
    }
    pub fn px_4(self) -> Self {
        self
    }
    pub fn px_6(self) -> Self {
        self
    }
    pub fn py_1(self) -> Self {
        self
    }
    pub fn py_2(self) -> Self {
        self
    }
    pub fn mx<T>(self, _: T) -> Self {
        self
    }
    pub fn my<T>(self, _: T) -> Self {
        self
    }
    pub fn mt<T>(self, _: T) -> Self {
        self
    }
    pub fn mb<T>(self, _: T) -> Self {
        self
    }
    pub fn ml<T>(self, _: T) -> Self {
        self
    }
    pub fn mr<T>(self, _: T) -> Self {
        self
    }

    // --- 尺寸 ---
    pub fn w<T>(self, _: T) -> Self {
        self
    }
    pub fn h<T>(self, _: T) -> Self {
        self
    }
    pub fn min_w<T>(self, _: T) -> Self {
        self
    }
    pub fn min_h<T>(self, _: T) -> Self {
        self
    }
    pub fn max_w<T>(self, _: T) -> Self {
        self
    }
    pub fn max_h<T>(self, _: T) -> Self {
        self
    }

    // --- 文本 ---
    pub fn text_4xl(self) -> Self {
        self
    }
    pub fn text_5xl(self) -> Self {
        self
    }

    // --- 边框 ---
    pub fn rounded<T>(self, _: T) -> Self {
        self
    }
    pub fn border_4(self) -> Self {
        self
    }

    // --- 定位 ---
    pub fn overflow<T>(self, _: T) -> Self {
        self
    }
    pub fn overflow_visible(self) -> Self {
        self
    }
    pub fn overflow_x<T>(self, _: T) -> Self {
        self
    }
    pub fn overflow_y<T>(self, _: T) -> Self {
        self
    }
    pub fn top<T>(self, _: T) -> Self {
        self
    }
    pub fn left<T>(self, _: T) -> Self {
        self
    }
    pub fn right<T>(self, _: T) -> Self {
        self
    }
    pub fn bottom<T>(self, _: T) -> Self {
        self
    }

    // --- 光标 ---
    pub fn cursor_default(self) -> Self {
        self
    }
    pub fn cursor_text(self) -> Self {
        self
    }

    // --- 层级和透明度 ---
    pub fn z_index<T>(self, _: T) -> Self {
        self
    }
    pub fn opacity<T>(self, _: T) -> Self {
        self
    }

    // --- 可见性 ---
    pub fn visible<T>(self, _: T) -> Self {
        self
    }

    // --- 事件 ---
    pub fn on_click<T>(self, _: T) -> Self {
        self
    }
    pub fn on_mouse_down<T>(self, _: T) -> Self {
        self
    }
    pub fn on_mouse_up<T>(self, _: T) -> Self {
        self
    }
    pub fn on_mouse_move<T>(self, _: T) -> Self {
        self
    }
    pub fn on_mouse_down_out<T>(self, _: T) -> Self {
        self
    }
    pub fn on_mouse_up_out<T>(self, _: T) -> Self {
        self
    }
    pub fn on_key_down<T>(self, _: T) -> Self {
        self
    }
    pub fn on_key_up<T>(self, _: T) -> Self {
        self
    }
    pub fn on_focus<T>(self, _: T) -> Self {
        self
    }
    pub fn on_blur<T>(self, _: T) -> Self {
        self
    }
    pub fn on_hover<T>(self, _: T) -> Self {
        self
    }
    pub fn on_scroll_wheel<T>(self, _: T) -> Self {
        self
    }
    pub fn on_drag<T>(self, _: T) -> Self {
        self
    }
    pub fn on_drop<T>(self, _: T) -> Self {
        self
    }
    pub fn on_action<T>(self, _: T) -> Self {
        self
    }

    // --- 状态样式 ---
    pub fn hover<F: FnOnce(Self) -> Self>(self, _f: F) -> Self {
        self
    }
    pub fn active<F: FnOnce(Self) -> Self>(self, _f: F) -> Self {
        self
    }
    pub fn focus<F: FnOnce(Self) -> Self>(self, _f: F) -> Self {
        self
    }
    pub fn tooltip<T>(self, _: T) -> Self {
        self
    }
    pub fn group<T>(self, _: T) -> Self {
        self
    }
    pub fn track_focus(self) -> Self {
        self
    }

    // --- 额外属性映射 ---
    pub fn font_size<T>(self, _: T) -> Self {
        self
    }
    pub fn line_height<T>(self, _: T) -> Self {
        self
    }
    pub fn font_weight<T>(self, _: T) -> Self {
        self
    }
    pub fn text_align<T>(self, _: T) -> Self {
        self
    }
    pub fn border_radius<T>(self, _: T) -> Self {
        self
    }
    pub fn shadow<T>(self, _: T) -> Self {
        self
    }

    // --- 子节点 ---
    pub fn child<T>(self, _: T) -> Self {
        self
    }
    pub fn children<I: IntoIterator>(self, _: I) -> Self {
        self
    }

    // --- 条件方法 ---
    pub fn when<F>(self, _condition: bool, _f: F) -> Self
    where
        F: FnOnce(Self) -> Self,
    {
        self
    }

    pub fn when_some<T, F>(self, _option: Option<T>, _f: F) -> Self
    where
        F: FnOnce(Self, T) -> Self,
    {
        self
    }

    // --- 转换方法 ---
    pub fn map<F>(self, _f: F) -> Self
    where
        F: FnOnce(Self) -> Self,
    {
        self
    }

    // --- 新增属性映射 ---
    pub fn gap_x<T>(self, _: T) -> Self {
        self
    }
    pub fn gap_y<T>(self, _: T) -> Self {
        self
    }
    pub fn basis<T>(self, _: T) -> Self {
        self
    }
    pub fn order<T>(self, _: T) -> Self {
        self
    }
    pub fn inset<T>(self, _: T) -> Self {
        self
    }
    pub fn text_decoration<T>(self, _: T) -> Self {
        self
    }
    pub fn border_t<T>(self, _: T) -> Self {
        self
    }
    pub fn border_b<T>(self, _: T) -> Self {
        self
    }
    pub fn border_l<T>(self, _: T) -> Self {
        self
    }
    pub fn border_r<T>(self, _: T) -> Self {
        self
    }
    pub fn rounded_t<T>(self, _: T) -> Self {
        self
    }
    pub fn rounded_b<T>(self, _: T) -> Self {
        self
    }
    pub fn rounded_tl<T>(self, _: T) -> Self {
        self
    }
    pub fn rounded_tr<T>(self, _: T) -> Self {
        self
    }
    pub fn rounded_bl<T>(self, _: T) -> Self {
        self
    }
    pub fn rounded_br<T>(self, _: T) -> Self {
        self
    }
    pub fn flex_none(self) -> Self {
        self
    }
    pub fn flex_auto(self) -> Self {
        self
    }

    // --- 新增尺寸 ---
    pub fn shadow_sm(self) -> Self {
        self
    }
    pub fn shadow_md(self) -> Self {
        self
    }
    pub fn shadow_lg(self) -> Self {
        self
    }
    pub fn rounded_xl(self) -> Self {
        self
    }
    pub fn rounded_none(self) -> Self {
        self
    }

    // --- 杂项 ---
    pub fn placeholder<T>(self, _: T) -> Self {
        self
    }
}

// Styled trait 实现 — 供动态 class 运行时 match 表使用
impl Styled for MockElement {
    fn flex(self) -> Self {
        self
    }
    fn flex_col(self) -> Self {
        self
    }
    fn flex_row(self) -> Self {
        self
    }
    fn flex_1(self) -> Self {
        self
    }
    fn flex_wrap(self) -> Self {
        self
    }
    fn items_center(self) -> Self {
        self
    }
    fn items_start(self) -> Self {
        self
    }
    fn items_end(self) -> Self {
        self
    }
    fn justify_center(self) -> Self {
        self
    }
    fn justify_between(self) -> Self {
        self
    }
    fn justify_start(self) -> Self {
        self
    }
    fn justify_end(self) -> Self {
        self
    }
    fn gap<T>(self, _: T) -> Self {
        self
    }
    fn p<T>(self, _: T) -> Self {
        self
    }
    fn px<T>(self, _: T) -> Self {
        self
    }
    fn py<T>(self, _: T) -> Self {
        self
    }
    fn m<T>(self, _: T) -> Self {
        self
    }
    fn w_full(self) -> Self {
        self
    }
    fn h_full(self) -> Self {
        self
    }
    fn size_full(self) -> Self {
        self
    }
    fn text_xs(self) -> Self {
        self
    }
    fn text_sm(self) -> Self {
        self
    }
    fn text_base(self) -> Self {
        self
    }
    fn text_lg(self) -> Self {
        self
    }
    fn text_xl(self) -> Self {
        self
    }
    fn text_2xl(self) -> Self {
        self
    }
    fn text_3xl(self) -> Self {
        self
    }
    fn font_bold(self) -> Self {
        self
    }
    fn border_1(self) -> Self {
        self
    }
    fn border_2(self) -> Self {
        self
    }
    fn rounded_sm(self) -> Self {
        self
    }
    fn rounded_md(self) -> Self {
        self
    }
    fn rounded_lg(self) -> Self {
        self
    }
    fn rounded_full(self) -> Self {
        self
    }
    fn cursor_pointer(self) -> Self {
        self
    }
    fn overflow_hidden(self) -> Self {
        self
    }
    fn overflow_scroll(self) -> Self {
        self
    }
    fn absolute(self) -> Self {
        self
    }
    fn relative(self) -> Self {
        self
    }
    fn bg<T>(self, _: T) -> Self {
        self
    }
    fn text_color<T>(self, _: T) -> Self {
        self
    }
    fn border_color<T>(self, _: T) -> Self {
        self
    }
}