BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / settings / nav.rs

nav.rs

nav.rs 5.0 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5
6use crate::settings_section::SettingsSection;
7use crate::theme;
8use crate::views::widgets::icon;
9
10pub const TEAMS_GROUP: [SettingsSection; 5] = [
11 SettingsSection::General,
12 SettingsSection::Notifications,
13 SettingsSection::Chats,
14 SettingsSection::Calls,
15 SettingsSection::Devices,
16];
17pub const RUSTY_GROUP: [SettingsSection; 2] = [SettingsSection::Agents, SettingsSection::Mcp];
18const ITEM_HEIGHT: f32 = 34.;
19const ITEM_GAP: f32 = 2.;
20const ITEM_RADIUS: f32 = 6.;
21const ITEM_ICON: f32 = 16.;
22const NAV_PADDING_X: f32 = 12.;
23
24pub fn label(section: SettingsSection) -> &'static str {
25 match section {
26 SettingsSection::General => "General",
27 SettingsSection::Notifications => "Notifications and activity",
28 SettingsSection::Chats => "Chats and channels",
29 SettingsSection::Calls => "Calls",
30 SettingsSection::Devices => "Devices",
31 SettingsSection::Agents => "Agents",
32 SettingsSection::Mcp => "MCP",
33 SettingsSection::About => "About",
34 }
35}
36
37fn icon_name(section: SettingsSection) -> IconName {
38 match section {
39 SettingsSection::General => IconName::SlidersHorizontal,
40 SettingsSection::Notifications => IconName::Bell,
41 SettingsSection::Chats => IconName::MessageSquare,
42 SettingsSection::Calls => IconName::Phone,
43 SettingsSection::Devices => IconName::Headphones,
44 SettingsSection::Agents => IconName::Bot,
45 SettingsSection::Mcp => IconName::Plug,
46 SettingsSection::About => IconName::Info,
47 }
48}
49
50fn element_id(section: SettingsSection) -> &'static str {
51 match section {
52 SettingsSection::General => "settings-nav-general",
53 SettingsSection::Notifications => "settings-nav-notifications",
54 SettingsSection::Chats => "settings-nav-chats",
55 SettingsSection::Calls => "settings-nav-calls",
56 SettingsSection::Devices => "settings-nav-devices",
57 SettingsSection::Agents => "settings-nav-agents",
58 SettingsSection::Mcp => "settings-nav-mcp",
59 SettingsSection::About => "settings-nav-about",
60 }
61}
62
63pub struct NavLayout {
64 pub width: f32,
65 pub padding_y: f32,
66}
67
68pub fn render_nav(
69 active: SettingsSection,
70 agents_available: bool,
71 layout: NavLayout,
72 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + Clone + 'static,
73) -> Div {
74 let item = |section: SettingsSection| nav_item(section, section == active, on_select.clone());
75 let rusty: Vec<Stateful<Div>> = RUSTY_GROUP
76 .into_iter()
77 .filter(|section| agents_available || *section != SettingsSection::Agents)
78 .map(item)
79 .collect();
80 v_flex()
81 .debug_selector(|| "settings/nav".into())
82 .w(px(layout.width))
83 .h_full()
84 .flex_none()
85 .px(px(NAV_PADDING_X))
86 .py(px(layout.padding_y))
87 .gap(px(ITEM_GAP))
88 .rounded_l(px(super::dialog::PANEL_RADIUS))
89 .bg(theme::surface_raised())
90 .child(
91 div()
92 .mx(px(12.))
93 .mb(px(18.))
94 .text_size(px(20.))
95 .line_height(px(26.))
96 .font_weight(FontWeight::SEMIBOLD)
97 .text_color(theme::text())
98 .child("Settings"),
99 )
100 .children(TEAMS_GROUP.map(item))
101 .child(
102 div()
103 .mt(px(10.))
104 .px(px(12.))
105 .pt(px(12.))
106 .pb(px(6.))
107 .border_t_1()
108 .border_color(theme::border_strong())
109 .text_size(px(12.))
110 .font_weight(FontWeight::SEMIBOLD)
111 .text_color(theme::text_muted())
112 .child("RUSTY TEAMS"),
113 )
114 .children(rusty)
115 .child(div().flex_1().min_h(px(0.)))
116 .child(item(SettingsSection::About))
117}
118
119fn nav_item(
120 section: SettingsSection,
121 active: bool,
122 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + 'static,
123) -> Stateful<Div> {
124 h_flex()
125 .id(element_id(section))
126 .w_full()
127 .h(px(ITEM_HEIGHT))
128 .flex_none()
129 .px(px(12.))
130 .gap(px(12.))
131 .items_center()
132 .rounded(px(ITEM_RADIUS))
133 .cursor_pointer()
134 .text_size(px(14.))
135 .when(active, |item| {
136 item.bg(theme::popup_hover())
137 .font_weight(FontWeight::SEMIBOLD)
138 .text_color(theme::text())
139 })
140 .when(!active, |item| {
141 item.text_color(theme::text_strong())
142 .hover(|item| item.bg(theme::popup()))
143 })
144 .child(icon(
145 icon_name(section),
146 ITEM_ICON,
147 if active {
148 theme::accent_text()
149 } else {
150 theme::text_muted()
151 },
152 ))
153 .child(div().flex_1().min_w_0().truncate().child(label(section)))
154 .on_click(move |_, window, cx| on_select(section, window, cx))
155}