scroll.rs

 1use crate::themes::rose_pine;
 2use gpui2::{
 3    div, px, Component, ParentElement, SharedString, Styled, View, VisualContext, WindowContext,
 4};
 5
 6pub struct ScrollStory {
 7    text: View<()>,
 8}
 9
10impl ScrollStory {
11    pub fn view(cx: &mut WindowContext) -> View<()> {
12        let theme = rose_pine();
13
14        {
15            cx.build_view(|cx| (), move |_, cx| checkerboard(1))
16        }
17    }
18}
19
20fn checkerboard<S>(depth: usize) -> impl Component<S>
21where
22    S: 'static + Send + Sync,
23{
24    let theme = rose_pine();
25    let color_1 = theme.lowest.positive.default.background;
26    let color_2 = theme.lowest.warning.default.background;
27
28    div()
29        .id("parent")
30        .bg(theme.lowest.base.default.background)
31        .size_full()
32        .overflow_scroll()
33        .children((0..10).map(|row| {
34            div()
35                .w(px(1000.))
36                .h(px(100.))
37                .flex()
38                .flex_row()
39                .children((0..10).map(|column| {
40                    let id = SharedString::from(format!("{}, {}", row, column));
41                    let bg = if row % 2 == column % 2 {
42                        color_1
43                    } else {
44                        color_2
45                    };
46                    div().id(id).bg(bg).size(px(100. / depth as f32)).when(
47                        row >= 5 && column >= 5,
48                        |d| {
49                            d.overflow_scroll()
50                                .child(div().size(px(50.)).bg(color_1))
51                                .child(div().size(px(50.)).bg(color_2))
52                                .child(div().size(px(50.)).bg(color_1))
53                                .child(div().size(px(50.)).bg(color_2))
54                        },
55                    )
56                }))
57        }))
58}