uniform_list.rs

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