BlueGit

ict rusty-teams

Files

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

nav.rs

nav.rs 6.6 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; 6] = [
11 SettingsSection::General,
12 SettingsSection::Notifications,
13 SettingsSection::Appearance,
14 SettingsSection::Chats,
15 SettingsSection::Calls,
16 SettingsSection::Devices,
17];
18pub const RUSTY_GROUP: [SettingsSection; 2] = [SettingsSection::Agents, SettingsSection::Mcp];
19const ITEM_MIN_HEIGHT: f32 = 32.;
20const ITEM_PADDING_Y: f32 = 6.;
21const ITEM_LINE_HEIGHT: f32 = 20.;
22const ITEM_GAP: f32 = 2.;
23const ITEM_RADIUS: f32 = 6.;
24const ITEM_ICON: f32 = 16.;
25const NAV_PADDING_X: f32 = 12.;
26
27pub fn label(section: SettingsSection) -> &'static str {
28 match section {
29 SettingsSection::General => "General",
30 SettingsSection::Notifications => "Notifications and activity",
31 SettingsSection::Appearance => "Appearance and accessibility",
32 SettingsSection::Chats => "Chats and channels",
33 SettingsSection::Calls => "Calls",
34 SettingsSection::Devices => "Devices",
35 SettingsSection::Agents => "Agents",
36 SettingsSection::Mcp => "MCP",
37 SettingsSection::About => "About",
38 }
39}
40
41fn icon_name(section: SettingsSection) -> IconName {
42 match section {
43 SettingsSection::General => IconName::SlidersHorizontal,
44 SettingsSection::Notifications => IconName::Bell,
45 SettingsSection::Appearance => IconName::Palette,
46 SettingsSection::Chats => IconName::MessageSquare,
47 SettingsSection::Calls => IconName::Phone,
48 SettingsSection::Devices => IconName::Headphones,
49 SettingsSection::Agents => IconName::Bot,
50 SettingsSection::Mcp => IconName::Plug,
51 SettingsSection::About => IconName::Info,
52 }
53}
54
55pub fn item_selector(section: SettingsSection) -> String {
56 format!("settings/nav/item/{}", element_id(section))
57}
58
59pub fn label_selector(section: SettingsSection) -> String {
60 format!("{}/label", item_selector(section))
61}
62
63fn element_id(section: SettingsSection) -> &'static str {
64 match section {
65 SettingsSection::General => "settings-nav-general",
66 SettingsSection::Notifications => "settings-nav-notifications",
67 SettingsSection::Appearance => "settings-nav-appearance",
68 SettingsSection::Chats => "settings-nav-chats",
69 SettingsSection::Calls => "settings-nav-calls",
70 SettingsSection::Devices => "settings-nav-devices",
71 SettingsSection::Agents => "settings-nav-agents",
72 SettingsSection::Mcp => "settings-nav-mcp",
73 SettingsSection::About => "settings-nav-about",
74 }
75}
76
77pub struct NavLayout {
78 pub width: f32,
79 pub padding_y: f32,
80}
81
82pub fn render_nav(
83 active: SettingsSection,
84 agents_available: bool,
85 layout: NavLayout,
86 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + Clone + 'static,
87) -> Div {
88 let item = |section: SettingsSection| nav_item(section, section == active, on_select.clone());
89 let rusty: Vec<Stateful<Div>> = RUSTY_GROUP
90 .into_iter()
91 .filter(|section| agents_available || *section != SettingsSection::Agents)
92 .map(item)
93 .collect();
94 let group = |items: Vec<Stateful<Div>>| {
95 v_flex()
96 .w_full()
97 .px(px(NAV_PADDING_X))
98 .gap(px(ITEM_GAP))
99 .children(items)
100 };
101 v_flex()
102 .debug_selector(|| "settings/nav".into())
103 .w(px(layout.width))
104 .h_full()
105 .flex_none()
106 .pt(px(layout.padding_y))
107 .pb(px(NAV_PADDING_X))
108 .gap(px(ITEM_GAP))
109 .rounded_l(px(super::dialog::PANEL_RADIUS))
110 .bg(theme::surface_raised())
111 .child(
112 div()
113 .mx(px(2. * NAV_PADDING_X))
114 .mb(px(18.))
115 .text_size(px(20.))
116 .line_height(px(26.))
117 .font_weight(FontWeight::SEMIBOLD)
118 .text_color(theme::text())
119 .child("Settings"),
120 )
121 .child(
122 v_flex()
123 .id("settings-nav-groups")
124 .w_full()
125 .flex_1()
126 .min_h(px(0.))
127 .overflow_y_scroll()
128 .gap(px(ITEM_GAP))
129 .child(group(TEAMS_GROUP.into_iter().map(item).collect()))
130 .child(
131 div()
132 .debug_selector(|| "settings/nav/divider".into())
133 .w_full()
134 .h(px(1.))
135 .flex_none()
136 .mt(px(10.))
137 .bg(theme::border_strong()),
138 )
139 .child(
140 div()
141 .px(px(2. * NAV_PADDING_X))
142 .pt(px(12.))
143 .pb(px(6.))
144 .text_size(px(12.))
145 .font_weight(FontWeight::SEMIBOLD)
146 .text_color(theme::text_muted())
147 .child("RUSTY TEAMS"),
148 )
149 .child(group(rusty)),
150 )
151 .child(
152 div()
153 .w_full()
154 .px(px(NAV_PADDING_X))
155 .child(item(SettingsSection::About).debug_selector(|| "settings/nav/about".into())),
156 )
157}
158
159fn nav_item(
160 section: SettingsSection,
161 active: bool,
162 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + 'static,
163) -> Stateful<Div> {
164 h_flex()
165 .id(element_id(section))
166 .debug_selector(move || item_selector(section))
167 .w_full()
168 .min_h(px(ITEM_MIN_HEIGHT))
169 .flex_none()
170 .px(px(12.))
171 .py(px(ITEM_PADDING_Y))
172 .gap(px(12.))
173 .items_center()
174 .rounded(px(ITEM_RADIUS))
175 .cursor_pointer()
176 .text_size(px(14.))
177 .line_height(px(ITEM_LINE_HEIGHT))
178 .when(active, |item| {
179 item.bg(theme::popup_hover()).text_color(theme::text())
180 })
181 .when(!active, |item| {
182 item.text_color(theme::text_strong())
183 .hover(|item| item.bg(theme::popup()))
184 })
185 .child(icon(
186 icon_name(section),
187 ITEM_ICON,
188 if active {
189 theme::accent_text()
190 } else {
191 theme::text_muted()
192 },
193 ))
194 .child(
195 div()
196 .debug_selector(move || label_selector(section))
197 .flex_1()
198 .min_w_0()
199 .child(label(section)),
200 )
201 .on_click(move |_, window, cx| on_select(section, window, cx))
202}