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 tabs: Vec<Tab>,
11}
12
13impl<V: 'static> TabBar<V> {
14 pub fn new(tabs: Vec<Tab>) -> Self {
15 Self {
16 view_type: PhantomData,
17 scroll_state: ScrollState::default(),
18 tabs,
19 }
20 }
21
22 pub fn bind_scroll_state(&mut self, scroll_state: ScrollState) {
23 self.scroll_state = scroll_state;
24 }
25
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
31 div()
32 .w_full()
33 .flex()
34 .fill(theme.middle.base.default.background)
35 // Left Side
36 .child(
37 div()
38 .px_1()
39 .flex()
40 .flex_none()
41 .gap_2()
42 // Nav Buttons
43 .child(
44 div()
45 .flex()
46 .items_center()
47 .gap_px()
48 .child(
49 IconButton::new(Icon::ArrowLeft)
50 .state(InteractionState::Enabled.if_enabled(can_navigate_back)),
51 )
52 .child(
53 IconButton::new(Icon::ArrowRight).state(
54 InteractionState::Enabled.if_enabled(can_navigate_forward),
55 ),
56 ),
57 ),
58 )
59 .child(
60 div().w_0().flex_1().h_full().child(
61 div()
62 .flex()
63 .overflow_x_scroll(self.scroll_state.clone())
64 .children(self.tabs.clone()),
65 ),
66 )
67 // Right Side
68 .child(
69 div()
70 .px_1()
71 .flex()
72 .flex_none()
73 .gap_2()
74 // Nav Buttons
75 .child(
76 div()
77 .flex()
78 .items_center()
79 .gap_px()
80 .child(IconButton::new(Icon::Plus))
81 .child(IconButton::new(Icon::Split)),
82 ),
83 )
84 }
85}