Skip to main content

gpui_macos/
table.rs

1//! Primitive tables: application-owned columns, rows and content.
2use crate::ActiveTheme;
3use gpui_kit::base::{Table, TableCell, TableHead, TableRow};
4use gpui_kit::rems;
5use gpui_kit::{App, ElementId, FontWeight, InteractiveElement, Styled, prelude::FluentBuilder};
6
7pub fn table(id: impl Into<ElementId>, cx: &App) -> Table {
8    let t = cx.macos();
9    Table::new(id)
10        .w_full()
11        .overflow_hidden()
12        .bg(t.background)
13        .text_color(t.foreground)
14        .font_family(t.font.clone())
15        .text_size(rems(0.8125))
16}
17
18/// `index` is the one-based accessibility row index, including the header.
19/// Alternating content rows use the standard subtle background fill.
20pub fn table_row(id: impl Into<ElementId>, index: usize, cx: &App) -> TableRow {
21    let t = cx.macos();
22    TableRow::new(id, index)
23        .flex()
24        .min_h(rems(1.75))
25        .when(index > 1 && index % 2 == 1, |row| row.bg(t.normal_fill()))
26        .hover(|s| s.bg(t.hover_fill()))
27}
28
29/// `index` is the one-based accessibility column index.
30pub fn table_head(id: impl Into<ElementId>, index: usize, cx: &App) -> TableHead {
31    let t = cx.macos();
32    TableHead::new(id, index)
33        .flex_1()
34        .min_w_0()
35        .px(rems(0.5))
36        .py(rems(0.375))
37        .bg(t.normal_fill())
38        .border_b_1()
39        .border_color(t.divider())
40        .text_color(t.secondary)
41        .font_weight(FontWeight::MEDIUM)
42}
43
44pub fn table_cell(id: impl Into<ElementId>, index: usize, _cx: &App) -> TableCell {
45    TableCell::new(id, index)
46        .flex_1()
47        .min_w_0()
48        .px(rems(0.5))
49        .py(rems(0.375))
50}