uniform_list.rs

 1use gpui::{
 2    App, Application, Bounds, Context, ListSizingBehavior, Window, WindowBounds, WindowOptions,
 3    div, prelude::*, px, 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                "entries",
13                50,
14                cx.processor(|_this, range, _window, _cx| {
15                    let mut items = Vec::new();
16                    for ix in range {
17                        let item = ix + 1;
18
19                        items.push(
20                            div()
21                                .id(ix)
22                                .px_2()
23                                .cursor_pointer()
24                                .on_click(move |_event, _window, _cx| {
25                                    println!("clicked Item {item:?}");
26                                })
27                                .child(format!("Item {item}")),
28                        );
29                    }
30                    items
31                }),
32            )
33            .with_sizing_behavior(ListSizingBehavior::Infer)
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}