uniform_table.rs

 1use component::{Component, example_group_with_title, single_example};
 2use gpui::{AnyElement, App, IntoElement, ParentElement as _, Styled as _, Window};
 3use ui_macros::RegisterComponent;
 4
 5use crate::v_flex;
 6
 7#[derive(RegisterComponent)]
 8struct Table;
 9
10impl Component for Table {
11    fn name() -> &'static str {
12        "Uniform Table"
13    }
14
15    fn scope() -> component::ComponentScope {
16        component::ComponentScope::Layout
17    }
18
19    fn description() -> Option<&'static str> {
20        Some("A table with uniform rows")
21    }
22
23    fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
24        let data = vec![
25            ["Alice", "25", "New York"],
26            ["Bob", "30", "Los Angeles"],
27            ["Charlie", "35", "Chicago"],
28            ["Sam", "27", "Detroit"],
29        ];
30        Some(
31            v_flex()
32                .gap_6()
33                .children([example_group_with_title(
34                    "Basic",
35                    vec![single_example(
36                        "Simple Table",
37                        gpui::uniform_table("simple table", 4, move |range, _, _| {
38                            data[range]
39                                .iter()
40                                .cloned()
41                                .map(|arr| arr.map(IntoElement::into_any_element))
42                                .collect()
43                        })
44                        .into_any_element(),
45                    )],
46                )])
47                .into_any_element(),
48        )
49    }
50}