uniform_list.rs

 1use gpui::*;
 2
 3struct UniformListExample {}
 4
 5impl Render for UniformListExample {
 6    fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
 7        div().size_full().bg(rgb(0xffffff)).child(
 8            uniform_list(cx.view().clone(), "entries", 50, |_this, range, _cx| {
 9                let mut items = Vec::new();
10                for ix in range {
11                    let item = ix + 1;
12
13                    items.push(
14                        div()
15                            .id(ix)
16                            .px_2()
17                            .cursor_pointer()
18                            .on_click(move |_event, _cx| {
19                                println!("clicked Item {item:?}");
20                            })
21                            .child(format!("Item {item}")),
22                    );
23                }
24                items
25            })
26            .h_full(),
27        )
28    }
29}
30
31fn main() {
32    App::new().run(|cx: &mut AppContext| {
33        let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx);
34        cx.open_window(
35            WindowOptions {
36                window_bounds: Some(WindowBounds::Windowed(bounds)),
37                ..Default::default()
38            },
39            |cx| cx.new_view(|_cx| UniformListExample {}),
40        )
41        .unwrap();
42    });
43}