| 1 | use gpui::{ |
| 2 | App, Application, Bounds, Context, Window, WindowBounds, WindowOptions, div, prelude::*, px, |
| 3 | rgb, size, uniform_list, |
| 4 | }; |
| 5 | |
| 6 | struct UniformListExample {} |
| 7 | |
| 8 | impl 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 | .h_full(), |
| 34 | ) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | fn main() { |
| 39 | Application::new().run(|cx: &mut App| { |
| 40 | let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx); |
| 41 | cx.open_window( |
| 42 | WindowOptions { |
| 43 | window_bounds: Some(WindowBounds::Windowed(bounds)), |
| 44 | ..Default::default() |
| 45 | }, |
| 46 | |_, cx| cx.new(|_| UniformListExample {}), |
| 47 | ) |
| 48 | .unwrap(); |
| 49 | }); |
| 50 | } |