BlueGit

ict rusty-teams

Files

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

appearance.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
appearance.rs 7.0 KiB Download Raw
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::*;
4
5use super::rows::{Choice, ROW_INSET, caption, control_row, select_with_width, titled};
6use crate::active_appearance;
7use crate::app_state::AppState;
8use crate::appearance::{AppIcon, ThemeChoice};
9use crate::theme::{self, Palette};
10use crate::views::title_bar::app_icon_image;
11
12const TILE_WIDTH: f32 = 168.;
13const TILE_PADDING: f32 = 8.;
14const TILE_GAP: f32 = 12.;
15const TILE_RADIUS: f32 = 12.;
16const PREVIEW_HEIGHT: f32 = 96.;
17const PREVIEW_RADIUS: f32 = TILE_RADIUS - TILE_PADDING;
18const PREVIEW_ICON_SIZE: f32 = 48.;
19const RADIO_SIZE: f32 = 16.;
20const RADIO_DOT_SIZE: f32 = 8.;
21const COLOR_SCHEME_DETAIL: &str = "The colors to use for Rusty Teams";
22const THEME_TITLE: &str = "Theme";
23const THEME_DETAIL: &str = "The theme to use for Teams";
24const THEME_SELECT_WIDTH: f32 = 240.;
25#[cfg(windows)]
26const APP_ICON_DETAIL: &str =
27 "Shown in the title bar, taskbar and tray. Pinned shortcuts keep the icon of the .exe";
28#[cfg(not(windows))]
29const APP_ICON_DETAIL: &str = "Shown in the title bar, taskbar and tray";
30
31pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
32 let current = active_appearance::current(cx);
33 let scheme_tiles = theme::SCHEMES.into_iter().map(|scheme| {
34 let app = app.clone();
35 tile(
36 SharedString::from(format!("settings-color-scheme-{}", scheme.id)),
37 scheme.name,
38 scheme.id == current.color_scheme.id,
39 scheme_preview(scheme.palette(theme::shade())),
40 )
41 .on_click(move |_, _, cx| {
42 let store = app.read(cx).store.clone();
43 active_appearance::set_color_scheme(scheme, &store, cx);
44 })
45 });
46 let icon_tiles = AppIcon::ALL.into_iter().map(|icon| {
47 let app = app.clone();
48 tile(
49 SharedString::from(format!("settings-app-icon-{}", icon.key())),
50 icon.label(),
51 icon == current.app_icon,
52 icon_preview(icon),
53 )
54 .on_click(move |_, _, cx| {
55 let store = app.read(cx).store.clone();
56 active_appearance::set_app_icon(icon, &store, cx);
57 })
58 });
59 let theme_choices = ThemeChoice::ALL
60 .into_iter()
61 .map(|choice| {
62 let app = app.clone();
63 Choice::new(choice.label(), choice == current.theme, move |cx| {
64 let store = app.read(cx).store.clone();
65 active_appearance::set_theme(choice, &store, cx);
66 })
67 })
68 .collect();
69 v_flex()
70 .w_full()
71 .child(caption("THEME"))
72 .child(control_row(
73 THEME_TITLE,
74 THEME_DETAIL,
75 select_with_width(
76 "settings-theme",
77 current.theme.label(),
78 THEME_SELECT_WIDTH,
79 false,
80 theme_choices,
81 ),
82 ))
83 .child(choice_group(
84 "Color scheme",
85 COLOR_SCHEME_DETAIL,
86 scheme_tiles,
87 ))
88 .child(caption("APP ICON"))
89 .child(choice_group("App icon", APP_ICON_DETAIL, icon_tiles))
90}
91
92fn choice_group(
93 title: &'static str,
94 detail: &'static str,
95 tiles: impl Iterator<Item = Stateful<Div>>,
96) -> Div {
97 v_flex()
98 .w_full()
99 .px(px(ROW_INSET))
100 .py(px(12.))
101 .gap(px(12.))
102 .child(titled(title, detail, theme::text_muted()))
103 .child(
104 h_flex()
105 .w_full()
106 .flex_wrap()
107 .gap(px(TILE_GAP))
108 .children(tiles),
109 )
110}
111
112fn tile(id: SharedString, label: &'static str, selected: bool, preview: Div) -> Stateful<Div> {
113 v_flex()
114 .id(id)
115 .w(px(TILE_WIDTH))
116 .flex_none()
117 .p(px(TILE_PADDING))
118 .gap(px(TILE_PADDING))
119 .rounded(px(TILE_RADIUS))
120 .bg(theme::surface_raised())
121 .cursor_pointer()
122 .hover(|tile| tile.bg(theme::popup_hover()))
123 .child(preview)
124 .child(
125 h_flex()
126 .w_full()
127 .px(px(TILE_PADDING / 2.))
128 .pb(px(TILE_PADDING / 2.))
129 .items_center()
130 .justify_between()
131 .child(
132 div()
133 .text_size(px(14.))
134 .line_height(px(20.))
135 .text_color(theme::text())
136 .child(label),
137 )
138 .child(radio(selected)),
139 )
140}
141
142fn radio(selected: bool) -> Div {
143 div()
144 .size(px(RADIO_SIZE))
145 .flex_none()
146 .flex()
147 .items_center()
148 .justify_center()
149 .rounded_full()
150 .border_1()
151 .border_color(if selected {
152 theme::accent()
153 } else {
154 theme::text_muted()
155 })
156 .when(selected, |radio| {
157 radio.child(
158 div()
159 .size(px(RADIO_DOT_SIZE))
160 .rounded_full()
161 .bg(theme::accent()),
162 )
163 })
164}
165
166fn preview_frame(background: Hsla) -> Div {
167 div()
168 .w_full()
169 .h(px(PREVIEW_HEIGHT))
170 .rounded(px(PREVIEW_RADIUS))
171 .overflow_hidden()
172 .bg(background)
173}
174
175fn scheme_preview(palette: &Palette) -> Div {
176 let fill = |hex: u32| theme::color(hex);
177 let bubble = |hex: u32, width: f32| div().w(px(width)).h(px(12.)).rounded(px(6.)).bg(fill(hex));
178 preview_frame(fill(palette.background)).child(
179 h_flex()
180 .size_full()
181 .p(px(6.))
182 .gap(px(6.))
183 .child(
184 v_flex()
185 .w(px(14.))
186 .h_full()
187 .gap(px(4.))
188 .items_center()
189 .child(
190 div()
191 .size(px(10.))
192 .rounded(px(3.))
193 .bg(fill(palette.surface_raised)),
194 )
195 .child(div().size(px(10.)).rounded(px(3.)).bg(fill(palette.accent))),
196 )
197 .child(
198 v_flex()
199 .flex_1()
200 .h_full()
201 .p(px(8.))
202 .gap(px(6.))
203 .rounded(px(6.))
204 .bg(fill(palette.surface))
205 .child(h_flex().child(bubble(palette.bubble_other, 64.)))
206 .child(
207 h_flex()
208 .justify_end()
209 .child(bubble(palette.bubble_own, 52.)),
210 )
211 .child(h_flex().child(bubble(palette.bubble_other, 40.)))
212 .child(
213 h_flex()
214 .justify_end()
215 .child(div().size(px(12.)).rounded_full().bg(fill(palette.accent))),
216 ),
217 ),
218 )
219}
220
221fn icon_preview(icon: AppIcon) -> Div {
222 preview_frame(theme::background())
223 .flex()
224 .items_center()
225 .justify_center()
226 .child(img(app_icon_image(icon)).size(px(PREVIEW_ICON_SIZE)))
227}