| 1 | use gpui_kit::component::{h_flex, v_flex}; |
| 2 | use gpui_kit::prelude::FluentBuilder as _; |
| 3 | use gpui_kit::*; |
| 4 | |
| 5 | use super::rows::{Choice, ROW_INSET, caption, control_row, select_with_width, titled}; |
| 6 | use crate::active_appearance; |
| 7 | use crate::app_state::AppState; |
| 8 | use crate::appearance::{AppIcon, ThemeChoice}; |
| 9 | use crate::theme::{self, Palette}; |
| 10 | use crate::views::title_bar::app_icon_image; |
| 11 | |
| 12 | const TILE_WIDTH: f32 = 168.; |
| 13 | const TILE_PADDING: f32 = 8.; |
| 14 | const TILE_GAP: f32 = 12.; |
| 15 | const TILE_RADIUS: f32 = 12.; |
| 16 | const PREVIEW_HEIGHT: f32 = 96.; |
| 17 | const PREVIEW_RADIUS: f32 = TILE_RADIUS - TILE_PADDING; |
| 18 | const PREVIEW_ICON_SIZE: f32 = 48.; |
| 19 | const RADIO_SIZE: f32 = 16.; |
| 20 | const RADIO_DOT_SIZE: f32 = 8.; |
| 21 | const COLOR_SCHEME_DETAIL: &str = "The colors to use for Rusty Teams"; |
| 22 | const THEME_TITLE: &str = "Theme"; |
| 23 | const THEME_DETAIL: &str = "The theme to use for Teams"; |
| 24 | const THEME_SELECT_WIDTH: f32 = 240.; |
| 25 | #[cfg(windows)] |
| 26 | const 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))] |
| 29 | const APP_ICON_DETAIL: &str = "Shown in the title bar, taskbar and tray"; |
| 30 | |
| 31 | pub 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 | |
| 92 | fn 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 | |
| 112 | fn 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 | |
| 142 | fn 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 | |
| 166 | fn 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 | |
| 175 | fn 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(h_flex().justify_end().child(bubble(palette.bubble_own, 52.))) |
| 207 | .child(h_flex().child(bubble(palette.bubble_other, 40.))) |
| 208 | .child( |
| 209 | h_flex() |
| 210 | .justify_end() |
| 211 | .child(div().size(px(12.)).rounded_full().bg(fill(palette.accent))), |
| 212 | ), |
| 213 | ), |
| 214 | ) |
| 215 | } |
| 216 | |
| 217 | fn icon_preview(icon: AppIcon) -> Div { |
| 218 | preview_frame(theme::background()) |
| 219 | .flex() |
| 220 | .items_center() |
| 221 | .justify_center() |
| 222 | .child(img(app_icon_image(icon)).size(px(PREVIEW_ICON_SIZE))) |
| 223 | } |