tab_bar.rs

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