1use gpui::{
2 App, Application, Bounds, Context, Window, WindowBounds, WindowOptions, div, prelude::*, px,
3 rgb, size,
4};
5
6struct UniformTableExample {}
7
8impl Render for UniformTableExample {
9 fn render(&mut self, _window: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
10 const COLS: usize = 24;
11 const ROWS: usize = 100;
12 let mut headers = [0; COLS];
13
14 for column in 0..COLS {
15 headers[column] = column;
16 }
17
18 div().bg(rgb(0xffffff)).child(
19 gpui::uniform_table("simple table", ROWS, move |range, _, _| {
20 dbg!(&range);
21 range
22 .map(|row_index| {
23 let mut row = [0; COLS];
24 for col in 0..COLS {
25 row[col] = (row_index + 1) * (col + 1);
26 }
27 row.map(|cell| ToString::to_string(&cell))
28 .map(|cell| div().flex().flex_row().child(cell))
29 .map(IntoElement::into_any_element)
30 })
31 .collect()
32 })
33 .with_width_from_item(Some(ROWS - 1)),
34 )
35 }
36}
37
38fn 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(|_| UniformTableExample {}),
47 )
48 .unwrap();
49 });
50}