tab_bar.rs

 1use gpui::Render;
 2use story::Story;
 3
 4use crate::{Tab, TabBar, TabPosition, prelude::*};
 5
 6pub struct TabBarStory;
 7
 8impl Render for TabBarStory {
 9    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
10        let tab_count = 20;
11        let selected_tab_index = 3;
12
13        let tabs = (0..tab_count)
14            .map(|index| {
15                Tab::new(index)
16                    .toggle_state(index == selected_tab_index)
17                    .position(if index == 0 {
18                        TabPosition::First
19                    } else if index == tab_count - 1 {
20                        TabPosition::Last
21                    } else {
22                        TabPosition::Middle(index.cmp(&selected_tab_index))
23                    })
24                    .child(Label::new(format!("Tab {}", index + 1)).color(
25                        if index == selected_tab_index {
26                            Color::Default
27                        } else {
28                            Color::Muted
29                        },
30                    ))
31            })
32            .collect::<Vec<_>>();
33
34        Story::container(cx)
35            .child(Story::title_for::<TabBar>(cx))
36            .child(Story::label("Default", cx))
37            .child(
38                h_flex().child(
39                    TabBar::new("tab_bar_1")
40                        .start_child(
41                            IconButton::new("navigate_backward", IconName::ArrowLeft)
42                                .icon_size(IconSize::Small),
43                        )
44                        .start_child(
45                            IconButton::new("navigate_forward", IconName::ArrowRight)
46                                .icon_size(IconSize::Small),
47                        )
48                        .end_child(
49                            IconButton::new("new", IconName::Plus).icon_size(IconSize::Small),
50                        )
51                        .end_child(
52                            IconButton::new("split_pane", IconName::Split)
53                                .icon_size(IconSize::Small),
54                        )
55                        .children(tabs),
56                ),
57            )
58    }
59}