workspace.rs

  1use std::marker::PhantomData;
  2use std::sync::Arc;
  3
  4use chrono::DateTime;
  5use gpui3::{relative, rems, Size};
  6
  7use crate::prelude::*;
  8use crate::{theme, v_stack, Panel, PanelAllowedSides, PanelSide, ProjectPanel};
  9
 10#[derive(Element)]
 11pub struct WorkspaceElement<S: 'static + Send + Sync + Clone> {
 12    state_type: PhantomData<S>,
 13    left_panel_scroll_state: ScrollState,
 14    right_panel_scroll_state: ScrollState,
 15    tab_bar_scroll_state: ScrollState,
 16    bottom_panel_scroll_state: ScrollState,
 17}
 18
 19impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
 20    pub fn new() -> Self {
 21        Self {
 22            state_type: PhantomData,
 23            left_panel_scroll_state: ScrollState::default(),
 24            right_panel_scroll_state: ScrollState::default(),
 25            tab_bar_scroll_state: ScrollState::default(),
 26            bottom_panel_scroll_state: ScrollState::default(),
 27        }
 28    }
 29
 30    pub fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
 31        let theme = theme(cx).clone();
 32
 33        // let temp_size = rems(36.).into();
 34
 35        // let root_group = PaneGroup::new_groups(
 36        //     vec![
 37        //         PaneGroup::new_panes(
 38        //             vec![
 39        //                 Pane::new(
 40        //                     ScrollState::default(),
 41        //                     Size {
 42        //                         width: relative(1.).into(),
 43        //                         height: temp_size,
 44        //                     },
 45        //                     |_, payload| {
 46        //                         let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();
 47
 48        //                         vec![EditorPane::new(hello_world_rust_editor_with_status_example(
 49        //                             &theme,
 50        //                         ))
 51        //                         .into_any()]
 52        //                     },
 53        //                     Box::new(theme.clone()),
 54        //                 ),
 55        //                 Pane::new(
 56        //                     ScrollState::default(),
 57        //                     Size {
 58        //                         width: relative(1.).into(),
 59        //                         height: temp_size,
 60        //                     },
 61        //                     |_, _| vec![Terminal::new().into_any()],
 62        //                     Box::new(()),
 63        //                 ),
 64        //             ],
 65        //             SplitDirection::Vertical,
 66        //         ),
 67        //         PaneGroup::new_panes(
 68        //             vec![Pane::new(
 69        //                 ScrollState::default(),
 70        //                 Size {
 71        //                     width: relative(1.).into(),
 72        //                     height: relative(1.).into(),
 73        //                 },
 74        //                 |_, payload| {
 75        //                     let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();
 76
 77        //                     vec![EditorPane::new(hello_world_rust_editor_with_status_example(
 78        //                         &theme,
 79        //                     ))
 80        //                     .into_any()]
 81        //                 },
 82        //                 Box::new(theme.clone()),
 83        //             )],
 84        //             SplitDirection::Vertical,
 85        //         ),
 86        //     ],
 87        //     SplitDirection::Horizontal,
 88        // );
 89
 90        div()
 91            .relative()
 92            .size_full()
 93            .flex()
 94            .flex_col()
 95            .font("Zed Sans Extended")
 96            .gap_0()
 97            .justify_start()
 98            .items_start()
 99            .text_color(theme.lowest.base.default.foreground)
100            .fill(theme.lowest.base.default.background)
101            // .child(TitleBar::new(cx).set_livestream(Some(Livestream {
102            //     players: random_players_with_call_status(7),
103            //     channel: Some("gpui2-ui".to_string()),
104            // })))
105            .child(
106                div()
107                    .flex_1()
108                    .w_full()
109                    .flex()
110                    .flex_row()
111                    .overflow_hidden()
112                    .border_t()
113                    .border_b()
114                    .border_color(theme.lowest.base.default.border)
115                    .child(
116                        Panel::new(
117                            self.left_panel_scroll_state.clone(),
118                            |_, payload| vec![ProjectPanel::new(ScrollState::default()).into_any()],
119                            Box::new(()),
120                        )
121                        .side(PanelSide::Left),
122                    )
123                    .child(
124                        v_stack()
125                            .flex_1()
126                            .h_full()
127                            .child(
128                                div()
129                                    .flex()
130                                    .flex_1()
131                                    // CSS Hack: Flex 1 has to have a set height to properly fill the space
132                                    // Or it will give you a height of 0
133                                    .h_px(), // .child(root_group),
134                            )
135                            .child(
136                                Panel::new(
137                                    self.bottom_panel_scroll_state.clone(),
138                                    |_, _| {
139                                        vec![
140                                            // Terminal::new().into_any()
141                                        ]
142                                    },
143                                    Box::new(()),
144                                )
145                                .allowed_sides(PanelAllowedSides::BottomOnly)
146                                .side(PanelSide::Bottom),
147                            ),
148                    )
149                    .child(
150                        Panel::new(
151                            self.right_panel_scroll_state.clone(),
152                            |_, payload| vec![ProjectPanel::new(ScrollState::default()).into_any()],
153                            Box::new(()),
154                        )
155                        .side(PanelSide::Right),
156                    ), // .child(
157                       //     Panel::new(
158                       //         self.right_panel_scroll_state.clone(),
159                       //         |_, payload| {
160                       //             vec![ChatPanel::new(ScrollState::default())
161                       //                 .with_messages(vec![
162                       //                     ChatMessage::new(
163                       //                         "osiewicz".to_string(),
164                       //                         "is this thing on?".to_string(),
165                       //                         DateTime::parse_from_rfc3339(
166                       //                             "2023-09-27T15:40:52.707Z",
167                       //                         )
168                       //                         .unwrap()
169                       //                         .naive_local(),
170                       //                     ),
171                       //                     ChatMessage::new(
172                       //                         "maxdeviant".to_string(),
173                       //                         "Reading you loud and clear!".to_string(),
174                       //                         DateTime::parse_from_rfc3339(
175                       //                             "2023-09-28T15:40:52.707Z",
176                       //                         )
177                       //                         .unwrap()
178                       //                         .naive_local(),
179                       //                     ),
180                       //                 ])
181                       //                 .into_any()]
182                       //         },
183                       //         Box::new(()),
184                       //     )
185                       //     .side(PanelSide::Right),
186                       // ),
187            )
188            // .child(StatusBar::new())
189        // An example of a toast is below
190        // Currently because of stacking order this gets obscured by other elements
191
192        // .child(Toast::new(
193        //     ToastOrigin::Bottom,
194        //     |_, payload| {
195        //         let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();
196
197        //         vec![Label::new("label").into_any()]
198        //     },
199        //     Box::new(theme.clone()),
200        // ))
201    }
202}