1use chrono::DateTime;
2use gpui2::geometry::{relative, rems, Size};
3
4use crate::prelude::*;
5use crate::{
6 theme, v_stack, ChatMessage, ChatPanel, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide,
7 ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar,
8};
9
10#[derive(Element, Default)]
11pub struct WorkspaceElement {
12 left_panel_scroll_state: ScrollState,
13 right_panel_scroll_state: ScrollState,
14 tab_bar_scroll_state: ScrollState,
15 bottom_panel_scroll_state: ScrollState,
16}
17
18impl WorkspaceElement {
19 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
20 let temp_size = rems(36.).into();
21
22 let root_group = PaneGroup::new_groups(
23 vec![
24 PaneGroup::new_panes(
25 vec![
26 Pane::new(
27 ScrollState::default(),
28 Size {
29 width: relative(1.).into(),
30 height: temp_size,
31 },
32 |_, _| vec![Terminal::new().into_any()],
33 Box::new(()),
34 ),
35 Pane::new(
36 ScrollState::default(),
37 Size {
38 width: relative(1.).into(),
39 height: temp_size,
40 },
41 |_, _| vec![Terminal::new().into_any()],
42 Box::new(()),
43 ),
44 ],
45 SplitDirection::Vertical,
46 ),
47 PaneGroup::new_panes(
48 vec![Pane::new(
49 ScrollState::default(),
50 Size {
51 width: relative(1.).into(),
52 height: relative(1.).into(),
53 },
54 |_, _| vec![Terminal::new().into_any()],
55 Box::new(()),
56 )],
57 SplitDirection::Vertical,
58 ),
59 ],
60 SplitDirection::Horizontal,
61 );
62
63 let theme = theme(cx).clone();
64
65 div()
66 .size_full()
67 .flex()
68 .flex_col()
69 .font("Zed Sans Extended")
70 .gap_0()
71 .justify_start()
72 .items_start()
73 .text_color(theme.lowest.base.default.foreground)
74 .fill(theme.lowest.base.default.background)
75 .child(TitleBar::new(cx))
76 .child(
77 div()
78 .flex_1()
79 .w_full()
80 .flex()
81 .flex_row()
82 .overflow_hidden()
83 .border_t()
84 .border_b()
85 .border_color(theme.lowest.base.default.border)
86 .child(
87 ProjectPanel::new(self.left_panel_scroll_state.clone())
88 .side(PanelSide::Left),
89 )
90 .child(
91 v_stack()
92 .flex_1()
93 .h_full()
94 .child(
95 div()
96 .flex()
97 .flex_1()
98 // CSS Hack: Flex 1 has to have a set height to properly fill the space
99 // Or it will give you a height of 0
100 .h_px()
101 .child(root_group),
102 )
103 .child(
104 Panel::new(
105 self.bottom_panel_scroll_state.clone(),
106 |_, _| vec![Terminal::new().into_any()],
107 Box::new(()),
108 )
109 .allowed_sides(PanelAllowedSides::BottomOnly)
110 .side(PanelSide::Bottom),
111 ),
112 )
113 .child(ChatPanel::new(ScrollState::default()).with_messages(vec![
114 ChatMessage::new(
115 "osiewicz".to_string(),
116 "is this thing on?".to_string(),
117 DateTime::parse_from_rfc3339(
118 "2023-09-27T15:40:52.707Z",
119 )
120 .unwrap()
121 .naive_local(),
122 ),
123 ChatMessage::new(
124 "maxdeviant".to_string(),
125 "Reading you loud and clear!".to_string(),
126 DateTime::parse_from_rfc3339(
127 "2023-09-28T15:40:52.707Z",
128 )
129 .unwrap()
130 .naive_local(),
131 ),
132 ])),
133 )
134 .child(StatusBar::new())
135 }
136}