BlueGit

ict rusty-teams

Files

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

nav.rs

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