tab_bar.rs

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