tab_bar.rs

  1use std::marker::PhantomData;
  2
  3use crate::prelude::*;
  4use crate::{theme, Icon, IconButton, Tab};
  5
  6#[derive(Element)]
  7pub struct TabBar<V: 'static> {
  8    view_type: PhantomData<V>,
  9    scroll_state: ScrollState,
 10}
 11
 12impl<V: 'static> TabBar<V> {
 13    pub fn new(scroll_state: ScrollState) -> Self {
 14        Self {
 15            view_type: PhantomData,
 16            scroll_state,
 17        }
 18    }
 19
 20    fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
 21        let theme = theme(cx);
 22        let can_navigate_back = true;
 23        let can_navigate_forward = false;
 24        div()
 25            .w_full()
 26            .flex()
 27            .fill(theme.middle.base.default.background)
 28            // Left Side
 29            .child(
 30                div()
 31                    .px_1()
 32                    .flex()
 33                    .flex_none()
 34                    .gap_2()
 35                    // Nav Buttons
 36                    .child(
 37                        div()
 38                            .flex()
 39                            .items_center()
 40                            .gap_px()
 41                            .child(
 42                                IconButton::new(Icon::ArrowLeft)
 43                                    .state(InteractionState::Enabled.if_enabled(can_navigate_back)),
 44                            )
 45                            .child(
 46                                IconButton::new(Icon::ArrowRight).state(
 47                                    InteractionState::Enabled.if_enabled(can_navigate_forward),
 48                                ),
 49                            ),
 50                    ),
 51            )
 52            .child(
 53                div().w_0().flex_1().h_full().child(
 54                    div()
 55                        .flex()
 56                        .overflow_x_scroll(self.scroll_state.clone())
 57                        .child(
 58                            Tab::new()
 59                                .title("Cargo.toml".to_string())
 60                                .current(false)
 61                                .git_status(GitStatus::Modified),
 62                        )
 63                        .child(
 64                            Tab::new()
 65                                .title("Channels Panel".to_string())
 66                                .current(false),
 67                        )
 68                        .child(
 69                            Tab::new()
 70                                .title("channels_panel.rs".to_string())
 71                                .current(true)
 72                                .git_status(GitStatus::Modified),
 73                        )
 74                        .child(
 75                            Tab::new()
 76                                .title("workspace.rs".to_string())
 77                                .current(false)
 78                                .git_status(GitStatus::Modified),
 79                        )
 80                        .child(
 81                            Tab::new()
 82                                .title("icon_button.rs".to_string())
 83                                .current(false),
 84                        )
 85                        .child(
 86                            Tab::new()
 87                                .title("storybook.rs".to_string())
 88                                .current(false)
 89                                .git_status(GitStatus::Created),
 90                        )
 91                        .child(Tab::new().title("theme.rs".to_string()).current(false))
 92                        .child(
 93                            Tab::new()
 94                                .title("theme_registry.rs".to_string())
 95                                .current(false),
 96                        )
 97                        .child(
 98                            Tab::new()
 99                                .title("styleable_helpers.rs".to_string())
100                                .current(false),
101                        ),
102                ),
103            )
104            // Right Side
105            .child(
106                div()
107                    .px_1()
108                    .flex()
109                    .flex_none()
110                    .gap_2()
111                    // Nav Buttons
112                    .child(
113                        div()
114                            .flex()
115                            .items_center()
116                            .gap_px()
117                            .child(IconButton::new(Icon::Plus))
118                            .child(IconButton::new(Icon::Split)),
119                    ),
120            )
121    }
122}