BlueGit

ict rusty-teams

Files

rusty-teams / vendor / gpui-component / src / table / loading.rs

loading.rs

loading.rs 3.0 KiB Download Raw
1use crate::{ActiveTheme, Size, h_flex, skeleton::Skeleton, v_flex};
2use gpui::{IntoElement, ParentElement as _, RenderOnce, Styled, prelude::FluentBuilder as _};
3
4#[derive(IntoElement)]
5pub(super) struct Loading {
6 size: Size,
7}
8
9impl Loading {
10 pub(super) fn new() -> Self {
11 Self { size: Size::Medium }
12 }
13
14 pub(super) fn size(mut self, size: Size) -> Self {
15 self.size = size;
16 self
17 }
18}
19
20#[derive(IntoElement)]
21struct LoadingRow {
22 header: bool,
23 size: Size,
24}
25
26impl LoadingRow {
27 fn header() -> Self {
28 Self {
29 header: true,
30 size: Size::Medium,
31 }
32 }
33
34 fn row() -> Self {
35 Self {
36 header: false,
37 size: Size::Medium,
38 }
39 }
40
41 fn size(mut self, size: Size) -> Self {
42 self.size = size;
43 self
44 }
45}
46
47impl RenderOnce for LoadingRow {
48 fn render(self, _: &mut gpui::Window, cx: &mut gpui::App) -> impl IntoElement {
49 let paddings = self.size.table_cell_padding();
50 let height = self.size.table_row_height() * 0.5;
51
52 h_flex()
53 .gap_3()
54 .h(self.size.table_row_height())
55 .overflow_hidden()
56 .pt(paddings.top)
57 .pb(paddings.bottom)
58 .pl(paddings.left)
59 .pr(paddings.right)
60 .items_center()
61 .justify_between()
62 .overflow_hidden()
63 .when(self.header, |this| this.bg(cx.theme().tokens.table_head))
64 .when(!self.header, |this| {
65 this.border_t_1().border_color(cx.theme().table_row_border)
66 })
67 .child(
68 h_flex()
69 .gap_3()
70 .flex_1()
71 .child(
72 Skeleton::new()
73 .when(self.header, |this| this.secondary())
74 .h(height)
75 .w_24(),
76 )
77 .child(
78 Skeleton::new()
79 .when(self.header, |this| this.secondary())
80 .h(height)
81 .w_48(),
82 )
83 .child(
84 Skeleton::new()
85 .when(self.header, |this| this.secondary())
86 .h(height)
87 .w_16(),
88 ),
89 )
90 .child(
91 Skeleton::new()
92 .when(self.header, |this| this.secondary())
93 .h(height)
94 .w_24(),
95 )
96 }
97}
98
99impl RenderOnce for Loading {
100 fn render(self, _window: &mut gpui::Window, _cx: &mut gpui::App) -> impl IntoElement {
101 v_flex()
102 .gap_0()
103 .child(LoadingRow::header().size(self.size))
104 .child(LoadingRow::row().size(self.size))
105 .child(LoadingRow::row().size(self.size))
106 .child(LoadingRow::row().size(self.size))
107 .child(LoadingRow::row().size(self.size))
108 }
109}