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)).size_full().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 // todo! without this, the AvailableSpace passed in window.request_measured_layout is a Definite(2600px) on Anthony's machine
35 // this doesn't make sense, and results in the full range of elements getting rendered. This also occurs on uniform_list
36 // This is resulting from windows.bounds() being called
37 .h_full(),
38 )
39 }
40}
41
42fn main() {
43 Application::new().run(|cx: &mut App| {
44 let bounds = Bounds::centered(None, size(px(300.0), px(300.0)), cx);
45 cx.open_window(
46 WindowOptions {
47 window_bounds: Some(WindowBounds::Windowed(bounds)),
48 ..Default::default()
49 },
50 |_, cx| cx.new(|_| UniformTableExample {}),
51 )
52 .unwrap();
53 });
54}