uniform_list.rs

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