tab_bar.rs

 1use std::marker::PhantomData;
 2
 3use crate::components::{icon_button, tab, ButtonVariant};
 4use crate::theme::theme;
 5use gpui2::elements::div::ScrollState;
 6use gpui2::style::StyleHelpers;
 7use gpui2::{elements::div, IntoElement};
 8use gpui2::{Element, ParentElement, ViewContext};
 9
10#[derive(Element)]
11pub struct TabBar<V: 'static> {
12    view_type: PhantomData<V>,
13    scroll_state: ScrollState,
14}
15
16pub fn tab_bar<V: 'static>(scroll_state: ScrollState) -> TabBar<V> {
17    TabBar {
18        view_type: PhantomData,
19        scroll_state,
20    }
21}
22
23impl<V: 'static> TabBar<V> {
24    fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
25        let theme = theme(cx);
26
27        div()
28            .w_full()
29            .flex()
30            // Left Side
31            .child(
32                div()
33                    .px_1()
34                    .flex()
35                    .flex_none()
36                    .gap_2()
37                    // Nav Buttons
38                    .child(
39                        div()
40                            .flex()
41                            .items_center()
42                            .gap_px()
43                            .child(icon_button("icons/arrow_left.svg", ButtonVariant::Filled))
44                            .child(icon_button("icons/arrow_right.svg", ButtonVariant::Ghost)),
45                    ),
46            )
47            .child(
48                div().w_0().flex_1().h_full().child(
49                    div()
50                        .flex()
51                        .gap_px()
52                        .overflow_x_scroll(self.scroll_state.clone())
53                        .child(tab("Cargo.toml", false))
54                        .child(tab("Channels Panel", true))
55                        .child(tab("channels_panel.rs", false))
56                        .child(tab("workspace.rs", false))
57                        .child(tab("icon_button.rs", false))
58                        .child(tab("storybook.rs", false))
59                        .child(tab("theme.rs", false))
60                        .child(tab("theme_registry.rs", false))
61                        .child(tab("styleable_helpers.rs", false)),
62                ),
63            )
64            // Right Side
65            .child(
66                div()
67                    .px_1()
68                    .flex()
69                    .flex_none()
70                    .gap_2()
71                    // Nav Buttons
72                    .child(
73                        div()
74                            .flex()
75                            .items_center()
76                            .gap_px()
77                            .child(icon_button("icons/plus.svg", ButtonVariant::Ghost))
78                            .child(icon_button("icons/split.svg", ButtonVariant::Ghost)),
79                    ),
80            )
81    }
82}