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 dbg!(&range);
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 .with_sizing_behavior(ListSizingBehavior::Infer)
35 .h_full(),
36 )
37 }
38}
39
40fn main() {
41 Application::new().run(|cx: &mut App| {
42 let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx);
43 cx.open_window(
44 WindowOptions {
45 window_bounds: Some(WindowBounds::Windowed(bounds)),
46 ..Default::default()
47 },
48 |_, cx| cx.new(|_| UniformListExample {}),
49 )
50 .unwrap();
51 });
52}