gpui-ui-kit 0.5.10

A reusable UI component library for GPUI applications
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
//! Integration tests for Stack layout components
//!
//! Tests the stack layout components including:
//! - VStack (vertical stack)
//! - HStack (horizontal stack)
//! - Spacer
//! - Divider
//! - Spacing variants
//! - Alignment options
//! - Justify options
//! - Flex properties
//! - Overflow handling
//! - Size constraints

use gpui::{Context, Rgba, TestAppContext, Window, div, prelude::*, px};
use gpui_ui_kit::stack::{
    Divider, HStack, Spacer, StackAlign, StackJustify, StackOverflow, StackSize, StackSpacing,
    VStack,
};

// ============================================================================
// VStack Tests
// ============================================================================

struct VStackTestView;

impl Render for VStackTestView {
    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
        VStack::new()
            .child(div().child("Item 1"))
            .child(div().child("Item 2"))
            .child(div().child("Item 3"))
    }
}

#[gpui::test]
async fn test_vstack_renders(cx: &mut TestAppContext) {
    let _window = cx.add_window(|_window, _cx| VStackTestView);
}

#[gpui::test]
async fn test_vstack_with_spacing(cx: &mut TestAppContext) {
    struct SpacingView;

    impl Render for SpacingView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            div()
                .flex()
                .gap_4()
                .child(
                    VStack::new()
                        .spacing(StackSpacing::None)
                        .child(div().child("No space"))
                        .child(div().child("Between")),
                )
                .child(
                    VStack::new()
                        .spacing(StackSpacing::Xs)
                        .child(div().child("XS"))
                        .child(div().child("Space")),
                )
                .child(
                    VStack::new()
                        .spacing(StackSpacing::Sm)
                        .child(div().child("SM"))
                        .child(div().child("Space")),
                )
                .child(
                    VStack::new()
                        .spacing(StackSpacing::Md)
                        .child(div().child("MD"))
                        .child(div().child("Space")),
                )
                .child(
                    VStack::new()
                        .spacing(StackSpacing::Lg)
                        .child(div().child("LG"))
                        .child(div().child("Space")),
                )
                .child(
                    VStack::new()
                        .spacing(StackSpacing::Xl)
                        .child(div().child("XL"))
                        .child(div().child("Space")),
                )
                .child(
                    VStack::new()
                        .spacing(StackSpacing::Xxl)
                        .child(div().child("XXL"))
                        .child(div().child("Space")),
                )
        }
    }

    let _window = cx.add_window(|_window, _cx| SpacingView);
}

#[gpui::test]
async fn test_vstack_custom_spacing(cx: &mut TestAppContext) {
    struct CustomSpacingView;

    impl Render for CustomSpacingView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .spacing(StackSpacing::Custom(px(12.0)))
                .child(div().child("Custom"))
                .child(div().child("Spacing"))
        }
    }

    let _window = cx.add_window(|_window, _cx| CustomSpacingView);
}

#[gpui::test]
async fn test_vstack_alignment(cx: &mut TestAppContext) {
    struct AlignmentView;

    impl Render for AlignmentView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            div()
                .flex()
                .gap_4()
                .child(
                    VStack::new()
                        .align(StackAlign::Start)
                        .width(StackSize::Fixed(px(100.0)))
                        .child(div().child("Start")),
                )
                .child(
                    VStack::new()
                        .align(StackAlign::Center)
                        .width(StackSize::Fixed(px(100.0)))
                        .child(div().child("Center")),
                )
                .child(
                    VStack::new()
                        .align(StackAlign::End)
                        .width(StackSize::Fixed(px(100.0)))
                        .child(div().child("End")),
                )
                .child(
                    VStack::new()
                        .align(StackAlign::Stretch)
                        .width(StackSize::Fixed(px(100.0)))
                        .child(div().child("Stretch")),
                )
        }
    }

    let _window = cx.add_window(|_window, _cx| AlignmentView);
}

#[gpui::test]
async fn test_vstack_justify(cx: &mut TestAppContext) {
    struct JustifyView;

    impl Render for JustifyView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            div()
                .flex()
                .gap_4()
                .child(
                    VStack::new()
                        .justify(StackJustify::Start)
                        .height(StackSize::Fixed(px(200.0)))
                        .child(div().child("Start"))
                        .child(div().child("Justify")),
                )
                .child(
                    VStack::new()
                        .justify(StackJustify::Center)
                        .height(StackSize::Fixed(px(200.0)))
                        .child(div().child("Center"))
                        .child(div().child("Justify")),
                )
                .child(
                    VStack::new()
                        .justify(StackJustify::End)
                        .height(StackSize::Fixed(px(200.0)))
                        .child(div().child("End"))
                        .child(div().child("Justify")),
                )
                .child(
                    VStack::new()
                        .justify(StackJustify::SpaceBetween)
                        .height(StackSize::Fixed(px(200.0)))
                        .child(div().child("Space"))
                        .child(div().child("Between")),
                )
        }
    }

    let _window = cx.add_window(|_window, _cx| JustifyView);
}

#[gpui::test]
async fn test_vstack_size_options(cx: &mut TestAppContext) {
    struct SizeView;

    impl Render for SizeView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            div()
                .flex()
                .gap_4()
                .h(px(300.0))
                .child(
                    VStack::new()
                        .width(StackSize::Fixed(px(100.0)))
                        .height(StackSize::Full)
                        .child(div().child("Fixed width, full height")),
                )
                .child(VStack::new().full().child(div().child("Full size")))
        }
    }

    let _window = cx.add_window(|_window, _cx| SizeView);
}

#[gpui::test]
async fn test_vstack_flex_properties(cx: &mut TestAppContext) {
    struct FlexView;

    impl Render for FlexView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            div()
                .flex()
                .h(px(300.0))
                .child(VStack::new().flex_1().child(div().child("Flex 1")))
                .child(VStack::new().grow(2.0).child(div().child("Grow 2")))
        }
    }

    let _window = cx.add_window(|_window, _cx| FlexView);
}

#[gpui::test]
async fn test_vstack_overflow(cx: &mut TestAppContext) {
    struct OverflowView;

    impl Render for OverflowView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            div()
                .flex()
                .gap_4()
                .child(
                    VStack::new()
                        .overflow(StackOverflow::Hidden)
                        .height(StackSize::Fixed(px(50.0)))
                        .child(div().child("Hidden overflow"))
                        .child(div().child("More content"))
                        .child(div().child("Even more")),
                )
                .child(
                    VStack::new()
                        .overflow(StackOverflow::Visible)
                        .height(StackSize::Fixed(px(50.0)))
                        .child(div().child("Visible overflow"))
                        .child(div().child("More content")),
                )
        }
    }

    let _window = cx.add_window(|_window, _cx| OverflowView);
}

#[gpui::test]
async fn test_vstack_min_max_constraints(cx: &mut TestAppContext) {
    struct ConstraintsView;

    impl Render for ConstraintsView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .min_w(px(100.0))
                .max_w(px(300.0))
                .min_h(px(50.0))
                .max_h(px(200.0))
                .child(div().child("Constrained"))
        }
    }

    let _window = cx.add_window(|_window, _cx| ConstraintsView);
}

#[gpui::test]
async fn test_vstack_children_method(cx: &mut TestAppContext) {
    struct ChildrenView;

    impl Render for ChildrenView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            let items = vec!["A", "B", "C", "D"];
            VStack::new().children(items.iter().map(|item| div().child(*item)))
        }
    }

    let _window = cx.add_window(|_window, _cx| ChildrenView);
}

// ============================================================================
// HStack Tests
// ============================================================================

struct HStackTestView;

impl Render for HStackTestView {
    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
        HStack::new()
            .child(div().child("Left"))
            .child(div().child("Center"))
            .child(div().child("Right"))
    }
}

#[gpui::test]
async fn test_hstack_renders(cx: &mut TestAppContext) {
    let _window = cx.add_window(|_window, _cx| HStackTestView);
}

#[gpui::test]
async fn test_hstack_with_spacing(cx: &mut TestAppContext) {
    struct HSpacingView;

    impl Render for HSpacingView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            HStack::new()
                .spacing(StackSpacing::Lg)
                .child(div().child("A"))
                .child(div().child("B"))
                .child(div().child("C"))
        }
    }

    let _window = cx.add_window(|_window, _cx| HSpacingView);
}

#[gpui::test]
async fn test_hstack_wrap(cx: &mut TestAppContext) {
    struct WrapView;

    impl Render for WrapView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            HStack::new()
                .wrap(true)
                .width(StackSize::Fixed(px(200.0)))
                .children((1..=10).map(|i| div().w(px(50.0)).child(format!("{}", i))))
        }
    }

    let _window = cx.add_window(|_window, _cx| WrapView);
}

#[gpui::test]
async fn test_hstack_alignment(cx: &mut TestAppContext) {
    struct HAlignView;

    impl Render for HAlignView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            div()
                .flex()
                .flex_col()
                .gap_4()
                .child(
                    HStack::new()
                        .align(StackAlign::Start)
                        .height(StackSize::Fixed(px(60.0)))
                        .child(div().h(px(20.0)).child("Start"))
                        .child(div().h(px(40.0)).child("Align")),
                )
                .child(
                    HStack::new()
                        .align(StackAlign::Center)
                        .height(StackSize::Fixed(px(60.0)))
                        .child(div().h(px(20.0)).child("Center"))
                        .child(div().h(px(40.0)).child("Align")),
                )
                .child(
                    HStack::new()
                        .align(StackAlign::End)
                        .height(StackSize::Fixed(px(60.0)))
                        .child(div().h(px(20.0)).child("End"))
                        .child(div().h(px(40.0)).child("Align")),
                )
        }
    }

    let _window = cx.add_window(|_window, _cx| HAlignView);
}

#[gpui::test]
async fn test_hstack_justify(cx: &mut TestAppContext) {
    struct HJustifyView;

    impl Render for HJustifyView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            div()
                .flex()
                .flex_col()
                .gap_4()
                .child(
                    HStack::new()
                        .justify(StackJustify::SpaceAround)
                        .width(StackSize::Full)
                        .child(div().child("Space"))
                        .child(div().child("Around")),
                )
                .child(
                    HStack::new()
                        .justify(StackJustify::SpaceEvenly)
                        .width(StackSize::Full)
                        .child(div().child("Space"))
                        .child(div().child("Evenly")),
                )
        }
    }

    let _window = cx.add_window(|_window, _cx| HJustifyView);
}

// ============================================================================
// Spacer Tests
// ============================================================================

#[gpui::test]
async fn test_spacer_renders(cx: &mut TestAppContext) {
    struct SpacerView;

    impl Render for SpacerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            HStack::new()
                .width(StackSize::Full)
                .child(div().child("Left"))
                .child(Spacer::new())
                .child(div().child("Right"))
        }
    }

    let _window = cx.add_window(|_window, _cx| SpacerView);
}

#[gpui::test]
async fn test_spacer_in_vstack(cx: &mut TestAppContext) {
    struct VSpacerView;

    impl Render for VSpacerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .height(StackSize::Fixed(px(200.0)))
                .child(div().child("Top"))
                .child(Spacer::new())
                .child(div().child("Bottom"))
        }
    }

    let _window = cx.add_window(|_window, _cx| VSpacerView);
}

#[gpui::test]
async fn test_multiple_spacers(cx: &mut TestAppContext) {
    struct MultiSpacerView;

    impl Render for MultiSpacerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            HStack::new()
                .width(StackSize::Full)
                .child(div().child("A"))
                .child(Spacer::new())
                .child(div().child("B"))
                .child(Spacer::new())
                .child(div().child("C"))
        }
    }

    let _window = cx.add_window(|_window, _cx| MultiSpacerView);
}

// ============================================================================
// Divider Tests
// ============================================================================

#[gpui::test]
async fn test_horizontal_divider_renders(cx: &mut TestAppContext) {
    struct HDividerView;

    impl Render for HDividerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .width(StackSize::Fixed(px(200.0)))
                .child(div().child("Above"))
                .child(Divider::new())
                .child(div().child("Below"))
        }
    }

    let _window = cx.add_window(|_window, _cx| HDividerView);
}

#[gpui::test]
async fn test_vertical_divider_renders(cx: &mut TestAppContext) {
    struct VDividerView;

    impl Render for VDividerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            HStack::new()
                .height(StackSize::Fixed(px(100.0)))
                .child(div().child("Left"))
                .child(Divider::vertical())
                .child(div().child("Right"))
        }
    }

    let _window = cx.add_window(|_window, _cx| VDividerView);
}

#[gpui::test]
async fn test_divider_with_id(cx: &mut TestAppContext) {
    struct IdDividerView;

    impl Render for IdDividerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .child(div().child("Above"))
                .child(Divider::new().id("my-divider"))
                .child(div().child("Below"))
        }
    }

    let _window = cx.add_window(|_window, _cx| IdDividerView);
}

#[gpui::test]
async fn test_divider_custom_color(cx: &mut TestAppContext) {
    struct ColorDividerView;

    impl Render for ColorDividerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .child(div().child("Above"))
                .child(Divider::new().color(Rgba {
                    r: 1.0,
                    g: 0.0,
                    b: 0.0,
                    a: 1.0,
                }))
                .child(div().child("Below"))
        }
    }

    let _window = cx.add_window(|_window, _cx| ColorDividerView);
}

#[gpui::test]
async fn test_divider_custom_thickness(cx: &mut TestAppContext) {
    struct ThickDividerView;

    impl Render for ThickDividerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .child(div().child("Above"))
                .child(Divider::new().thickness(px(4.0)))
                .child(div().child("Below"))
        }
    }

    let _window = cx.add_window(|_window, _cx| ThickDividerView);
}

#[gpui::test]
async fn test_divider_interactive(cx: &mut TestAppContext) {
    struct InteractiveDividerView;

    impl Render for InteractiveDividerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            HStack::new()
                .height(StackSize::Fixed(px(100.0)))
                .child(div().child("Left"))
                .child(
                    Divider::vertical()
                        .id("interactive-divider")
                        .interactive()
                        .hover_color(Rgba {
                            r: 0.0,
                            g: 0.48,
                            b: 0.8,
                            a: 1.0,
                        }),
                )
                .child(div().child("Right"))
        }
    }

    let _window = cx.add_window(|_window, _cx| InteractiveDividerView);
}

#[gpui::test]
async fn test_divider_build_simple(cx: &mut TestAppContext) {
    struct SimpleDividerView;

    impl Render for SimpleDividerView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .child(div().child("Above"))
                .child(Divider::new().build_simple())
                .child(div().child("Below"))
        }
    }

    let _window = cx.add_window(|_window, _cx| SimpleDividerView);
}

// ============================================================================
// Edge Case Tests
// ============================================================================

#[gpui::test]
async fn test_empty_vstack(cx: &mut TestAppContext) {
    struct EmptyVStackView;

    impl Render for EmptyVStackView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
        }
    }

    let _window = cx.add_window(|_window, _cx| EmptyVStackView);
}

#[gpui::test]
async fn test_empty_hstack(cx: &mut TestAppContext) {
    struct EmptyHStackView;

    impl Render for EmptyHStackView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            HStack::new()
        }
    }

    let _window = cx.add_window(|_window, _cx| EmptyHStackView);
}

#[gpui::test]
async fn test_nested_stacks(cx: &mut TestAppContext) {
    struct NestedStacksView;

    impl Render for NestedStacksView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            VStack::new()
                .child(
                    HStack::new()
                        .child(div().child("A"))
                        .child(div().child("B")),
                )
                .child(
                    HStack::new().child(div().child("C")).child(
                        VStack::new()
                            .child(div().child("D1"))
                            .child(div().child("D2")),
                    ),
                )
        }
    }

    let _window = cx.add_window(|_window, _cx| NestedStacksView);
}

#[gpui::test]
async fn test_stack_fraction_size(cx: &mut TestAppContext) {
    struct FractionView;

    impl Render for FractionView {
        fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
            HStack::new()
                .width(StackSize::Full)
                .child(
                    VStack::new()
                        .width(StackSize::Fraction(0.3))
                        .child(div().child("30%")),
                )
                .child(
                    VStack::new()
                        .width(StackSize::Fraction(0.7))
                        .child(div().child("70%")),
                )
        }
    }

    let _window = cx.add_window(|_window, _cx| FractionView);
}