BlueGit

ict rusty-teams

Files

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

appearance.rs

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