One design source — tokens.toml generates Rust tokens (build.rs) and tokens.css
Browse files at this commit74b8535b71bdd9253b9cc756e66c3386d348a769Parent: 49cf52e- feat
- one design source — tokens.toml generates Rust tokens (build.rs) and tokens.css
- Gece/Gün themes, named hues, Onest
- parts module, YUMUSH_GALLERY view, harness gallery/compare scripts, raw-value gate test
- drops per-community accent
32 changed files +1134 -211
- .gitignore +1 -0
- crates/client/Cargo.toml +3 -0
- crates/client/assets/fonts/Inter-Bold.ttf +0 -0
- crates/client/assets/fonts/Inter-BoldItalic.ttf +0 -0
- crates/client/assets/fonts/Inter-Italic.ttf +0 -0
- crates/client/assets/fonts/Inter-Medium.ttf +0 -0
- crates/client/assets/fonts/Inter-Regular.ttf +0 -0
- crates/client/assets/fonts/Inter-SemiBold.ttf +0 -0
- crates/client/assets/fonts/LICENSE-Inter.txt → crates/client/assets/fonts/LICENSE-Onest.txt +5 -4
- crates/client/assets/fonts/Onest-Bold.ttf +0 -0
- crates/client/assets/fonts/Onest-Medium.ttf +0 -0
- crates/client/assets/fonts/Onest-Regular.ttf +0 -0
- crates/client/assets/fonts/Onest-SemiBold.ttf +0 -0
- crates/client/build.rs +101 -0
- crates/client/design/css.ts +13 -0
- crates/client/design/tokens.toml +63 -0
- crates/client/src/avatar.rs +0 -40
- crates/client/src/gui.rs +35 -118
- crates/client/src/gui/chat.rs +2 -4
- crates/client/src/gui/community_settings.rs +2 -2
- crates/client/src/gui/gallery.rs +193 -0
- crates/client/src/gui/parts.rs +371 -0
- crates/client/src/gui/settings_page.rs +6 -3
- crates/client/src/gui/sidebar.rs +1 -1
- crates/client/src/gui/social.rs +1 -1
- crates/client/src/gui/style.rs +220 -0
- crates/client/src/main.rs +44 -1
- crates/client/src/settings.rs +14 -37
- crates/common/src/model.rs +16 -0
- harness/compare.sh +14 -0
- harness/gallery.sh +25 -0
- harness/niri.kdl +4 -0
.gitignoremodified+1 -0
| @@ -5,3 +5,4 @@ configs/server_config.toml | ||
| 5 | 5 | yumush.db* |
| 6 | 6 | attachments/ |
| 7 | 7 | backups/ |
| 8 | +crates/client/design/tokens.css |
crates/client/Cargo.tomlmodified+3 -0
| @@ -54,5 +54,8 @@ serde = { version = "1.0.229", features = ["derive"] } | ||
| 54 | 54 | [target.'cfg(target_os = "macos")'.dependencies] |
| 55 | 55 | coreaudio-rs = "0.14.2" |
| 56 | 56 | |
| 57 | +[build-dependencies] | |
| 58 | +toml = "1.2.3" | |
| 59 | + | |
| 57 | 60 | [lints] |
| 58 | 61 | workspace = true |
crates/client/assets/fonts/Inter-Bold.ttfdeleted+0 -0
Binary file changed
crates/client/assets/fonts/Inter-BoldItalic.ttfdeleted+0 -0
Binary file changed
crates/client/assets/fonts/Inter-Italic.ttfdeleted+0 -0
Binary file changed
crates/client/assets/fonts/Inter-Medium.ttfdeleted+0 -0
Binary file changed
crates/client/assets/fonts/Inter-Regular.ttfdeleted+0 -0
Binary file changed
crates/client/assets/fonts/Inter-SemiBold.ttfdeleted+0 -0
Binary file changed
crates/client/assets/fonts/LICENSE-Inter.txt → crates/client/assets/fonts/LICENSE-Onest.txtrenamed+5 -4
| @@ -1,8 +1,9 @@ | ||
| 1 | -Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) | |
| 1 | +Copyright 2021 The Onest Project Authors (https://github.com/googlefonts/onest) | |
| 2 | 2 | |
| 3 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. |
| 4 | 4 | This license is copied below, and is also available with a FAQ at: |
| 5 | -http://scripts.sil.org/OFL | |
| 5 | +https://scripts.sil.org/OFL | |
| 6 | + | |
| 6 | 7 | |
| 7 | 8 | ----------------------------------------------------------- |
| 8 | 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 |
| @@ -17,7 +18,7 @@ with others. | ||
| 17 | 18 | |
| 18 | 19 | The OFL allows the licensed fonts to be used, studied, modified and |
| 19 | 20 | redistributed freely as long as they are not sold by themselves. The |
| 20 | -fonts, including any derivative works, can be bundled, embedded, | |
| 21 | +fonts, including any derivative works, can be bundled, embedded, | |
| 21 | 22 | redistributed and/or sold with any software provided that any reserved |
| 22 | 23 | names are not used by derivative works. The fonts and derivatives, |
| 23 | 24 | however, cannot be released under any other type of license. The |
| @@ -43,7 +44,7 @@ new environment. | ||
| 43 | 44 | "Author" refers to any designer, engineer, programmer, technical |
| 44 | 45 | writer or other person who contributed to the Font Software. |
| 45 | 46 | |
| 46 | -PERMISSION AND CONDITIONS | |
| 47 | +PERMISSION & CONDITIONS | |
| 47 | 48 | Permission is hereby granted, free of charge, to any person obtaining |
| 48 | 49 | a copy of the Font Software, to use, study, copy, merge, embed, modify, |
| 49 | 50 | redistribute, and sell modified and unmodified copies of the Font |
crates/client/assets/fonts/Onest-Bold.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/Onest-Medium.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/Onest-Regular.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/Onest-SemiBold.ttfadded+0 -0
Binary file changed
crates/client/build.rsadded+101 -0
| @@ -0,0 +1,101 @@ | ||
| 1 | +use std::{env, fmt::Write, fs, path::Path}; | |
| 2 | + | |
| 3 | +use toml::{Table, Value}; | |
| 4 | + | |
| 5 | +const SOURCE: &str = "design/tokens.toml"; | |
| 6 | +const COLORS: [&str; 10] = [ | |
| 7 | + "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad", | |
| 8 | +]; | |
| 9 | +const SCALES: [&str; 5] = ["space", "radius", "stroke", "text", "size"]; | |
| 10 | + | |
| 11 | +fn main() { | |
| 12 | + println!("cargo::rerun-if-changed={SOURCE}"); | |
| 13 | + let tokens: Table = fs::read_to_string(SOURCE) | |
| 14 | + .expect("read tokens") | |
| 15 | + .parse() | |
| 16 | + .expect("parse tokens"); | |
| 17 | + let mut out = String::new(); | |
| 18 | + | |
| 19 | + let hues = names(&tokens["hues"]); | |
| 20 | + writeln!(out, "pub const HUE_NAMES: [&str; {}] = {hues:?};", hues.len()).unwrap(); | |
| 21 | + | |
| 22 | + let themes = tokens["theme"].as_table().expect("theme table"); | |
| 23 | + writeln!( | |
| 24 | + out, | |
| 25 | + "#[derive(Debug, Clone, Copy, PartialEq, Eq)]\npub enum Theme {{ {} }}", | |
| 26 | + themes.keys().map(|name| camel(name)).collect::<Vec<_>>().join(", ") | |
| 27 | + ) | |
| 28 | + .unwrap(); | |
| 29 | + writeln!( | |
| 30 | + out, | |
| 31 | + "impl Theme {{\n pub const ALL: [Theme; {}] = [{}];\n pub const fn as_str(self) -> &'static str {{ match self {{ {} }} }}\n pub fn parse(text: &str) -> Option<Self> {{ Self::ALL.into_iter().find(|theme| theme.as_str() == text) }}\n pub const fn colors(self) -> &'static Colors {{ match self {{ {} }} }}\n}}", | |
| 32 | + themes.len(), | |
| 33 | + themes.keys().map(|name| format!("Theme::{}", camel(name))).collect::<Vec<_>>().join(", "), | |
| 34 | + themes.keys().map(|name| format!("Theme::{} => \"{name}\"", camel(name))).collect::<Vec<_>>().join(", "), | |
| 35 | + themes.keys().map(|name| format!("Theme::{} => &{}", camel(name), name.to_uppercase())).collect::<Vec<_>>().join(", "), | |
| 36 | + ) | |
| 37 | + .unwrap(); | |
| 38 | + | |
| 39 | + writeln!( | |
| 40 | + out, | |
| 41 | + "pub struct Colors {{\n pub dark: bool,\n{} pub hue: [u32; {}],\n}}", | |
| 42 | + COLORS.map(|name| format!(" pub {name}: u32,\n")).concat(), | |
| 43 | + hues.len() | |
| 44 | + ) | |
| 45 | + .unwrap(); | |
| 46 | + for (name, theme) in themes { | |
| 47 | + let theme = theme.as_table().expect("theme"); | |
| 48 | + let hue = names(&theme["hue"]); | |
| 49 | + assert_eq!(hue.len(), hues.len(), "{name}: one colour per hue"); | |
| 50 | + writeln!( | |
| 51 | + out, | |
| 52 | + "pub const {}: Colors = Colors {{\n dark: {},\n{} hue: [{}],\n}};", | |
| 53 | + name.to_uppercase(), | |
| 54 | + theme["dark"].as_bool().expect("dark"), | |
| 55 | + COLORS | |
| 56 | + .map(|color| format!(" {color}: {},\n", hex(theme[color].as_str().expect(color)))) | |
| 57 | + .concat(), | |
| 58 | + hue.iter().map(|color| hex(color)).collect::<Vec<_>>().join(", ") | |
| 59 | + ) | |
| 60 | + .unwrap(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + for scale in SCALES { | |
| 64 | + writeln!(out, "pub mod {scale} {{").unwrap(); | |
| 65 | + for (name, value) in tokens[scale].as_table().expect(scale) { | |
| 66 | + let value = match value { | |
| 67 | + Value::Integer(value) => *value as f32, | |
| 68 | + Value::Float(value) => *value as f32, | |
| 69 | + _ => panic!("{scale}.{name} is not a number"), | |
| 70 | + }; | |
| 71 | + writeln!(out, " pub const {}: f32 = {value:?};", name.to_uppercase()).unwrap(); | |
| 72 | + } | |
| 73 | + writeln!(out, "}}").unwrap(); | |
| 74 | + } | |
| 75 | + | |
| 76 | + let path = Path::new(&env::var("OUT_DIR").expect("OUT_DIR")).join("tokens.rs"); | |
| 77 | + fs::write(path, out).expect("write tokens"); | |
| 78 | +} | |
| 79 | + | |
| 80 | +fn names(value: &Value) -> Vec<String> { | |
| 81 | + value | |
| 82 | + .as_array() | |
| 83 | + .expect("array") | |
| 84 | + .iter() | |
| 85 | + .map(|item| item.as_str().expect("string").to_string()) | |
| 86 | + .collect() | |
| 87 | +} | |
| 88 | + | |
| 89 | +fn camel(name: &str) -> String { | |
| 90 | + let mut chars = name.chars(); | |
| 91 | + chars | |
| 92 | + .next() | |
| 93 | + .map(|first| first.to_uppercase().chain(chars).collect()) | |
| 94 | + .unwrap_or_default() | |
| 95 | +} | |
| 96 | + | |
| 97 | +fn hex(color: &str) -> String { | |
| 98 | + let digits = color.strip_prefix('#').expect("colour starts with #"); | |
| 99 | + assert_eq!(digits.len(), 6, "{color}: #rrggbb"); | |
| 100 | + format!("0x{digits}") | |
| 101 | +} |
crates/client/design/css.tsadded+13 -0
| @@ -0,0 +1,13 @@ | ||
| 1 | +import tokens from "./tokens.toml"; | |
| 2 | + | |
| 3 | +const out: string[] = []; | |
| 4 | +const scales = ["space", "radius", "stroke", "text", "size"] as const; | |
| 5 | +out.push(":root{" + scales.flatMap(scale => Object.entries(tokens[scale]).map(([name, value]) => `--${scale}-${name}:${value}px`)).join(";") + "}"); | |
| 6 | +const themes = Object.entries(tokens.theme) as [string, Record<string, string | boolean | string[]>][]; | |
| 7 | +themes.forEach(([name, theme], index) => { | |
| 8 | + const selector = index === 0 ? `:root,[data-theme=${name}]` : `[data-theme=${name}]`; | |
| 9 | + const colors = Object.entries(theme).filter(([key]) => key !== "dark" && key !== "hue").map(([key, value]) => `--${key}:${value}`); | |
| 10 | + const hues = (theme.hue as string[]).map((value, hue) => `--h-${tokens.hues[hue]}:${value}`); | |
| 11 | + out.push(`${selector}{color-scheme:${theme.dark ? "dark" : "light"};${[...colors, ...hues].join(";")}}`); | |
| 12 | +}); | |
| 13 | +await Bun.write(new URL("./tokens.css", import.meta.url), out.join("\n") + "\n"); |
crates/client/design/tokens.tomladded+63 -0
| @@ -0,0 +1,63 @@ | ||
| 1 | +hues = ["amber", "sky", "violet", "mint", "rose", "gold", "coral", "teal", "lilac", "paper"] | |
| 2 | + | |
| 3 | +[theme.gece] | |
| 4 | +dark = true | |
| 5 | +ground = "#121527" | |
| 6 | +raise = "#181b30" | |
| 7 | +hov = "#1b1e34" | |
| 8 | +press = "#1d2138" | |
| 9 | +thread = "#262a44" | |
| 10 | +off = "#2f334f" | |
| 11 | +faint = "#5b5c78" | |
| 12 | +dim = "#8f8ca3" | |
| 13 | +paper = "#ece5d8" | |
| 14 | +bad = "#ff8a7a" | |
| 15 | +hue = ["#ffb36b", "#6cc7ff", "#c99bff", "#7fe0a6", "#ff8fb1", "#f4d06f", "#ff8a7a", "#5fd4c8", "#b8b5ff", "#ece5d8"] | |
| 16 | + | |
| 17 | +[theme.gun] | |
| 18 | +dark = false | |
| 19 | +ground = "#ece5d8" | |
| 20 | +raise = "#f4efe6" | |
| 21 | +hov = "#e3dbcc" | |
| 22 | +press = "#d9d0c0" | |
| 23 | +thread = "#d6cdbd" | |
| 24 | +off = "#c8bead" | |
| 25 | +faint = "#8b8476" | |
| 26 | +dim = "#5e5a52" | |
| 27 | +paper = "#151726" | |
| 28 | +bad = "#b33b2a" | |
| 29 | +hue = ["#9c520c", "#11638d", "#7a43c9", "#1a6e41", "#b8325f", "#765b00", "#b33b2a", "#0a6c67", "#5a54c4", "#151726"] | |
| 30 | + | |
| 31 | +[space] | |
| 32 | +xs = 4 | |
| 33 | +sm = 8 | |
| 34 | +md = 12 | |
| 35 | +lg = 16 | |
| 36 | +xl = 24 | |
| 37 | +xxl = 32 | |
| 38 | + | |
| 39 | +[radius] | |
| 40 | +sm = 7 | |
| 41 | +md = 10 | |
| 42 | +lg = 14 | |
| 43 | +full = 9999 | |
| 44 | + | |
| 45 | +[stroke] | |
| 46 | +line = 1.5 | |
| 47 | + | |
| 48 | +[text] | |
| 49 | +caption = 12 | |
| 50 | +label = 13 | |
| 51 | +ui = 14 | |
| 52 | +body = 16 | |
| 53 | +title = 22 | |
| 54 | +display = 28 | |
| 55 | + | |
| 56 | +[size] | |
| 57 | +icon = 18 | |
| 58 | +control = 34 | |
| 59 | +row = 44 | |
| 60 | +avatar = 26 | |
| 61 | +sidebar = 230 | |
| 62 | +talk = 300 | |
| 63 | +popover = 300 |
crates/client/src/avatar.rsmodified+0 -40
| @@ -53,44 +53,4 @@ fn image_error(error: image::ImageError) -> Fail { | ||
| 53 | 53 | Fail::Io(error.to_string()) |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | -const HUE_BINS: usize = 24; | |
| 57 | 56 | |
| 58 | -pub fn dominant_hue(bytes: &[u8]) -> Option<f32> { | |
| 59 | - let image = image::load_from_memory(bytes) | |
| 60 | - .ok()? | |
| 61 | - .thumbnail(32, 32) | |
| 62 | - .to_rgb8(); | |
| 63 | - let mut bins = [(0.0f32, 0.0f32, 0.0f32); HUE_BINS]; | |
| 64 | - | |
| 65 | - for pixel in image.pixels() { | |
| 66 | - let [r, g, b] = pixel.0.map(|channel| channel as f32 / 255.); | |
| 67 | - let max = r.max(g).max(b); | |
| 68 | - let min = r.min(g).min(b); | |
| 69 | - let chroma = max - min; | |
| 70 | - if chroma < 0.15 { | |
| 71 | - continue; | |
| 72 | - } | |
| 73 | - let sector = if max == r { | |
| 74 | - ((g - b) / chroma).rem_euclid(6.) | |
| 75 | - } else if max == g { | |
| 76 | - (b - r) / chroma + 2. | |
| 77 | - } else { | |
| 78 | - (r - g) / chroma + 4. | |
| 79 | - }; | |
| 80 | - let hue = sector / 6.; | |
| 81 | - let angle = hue * std::f32::consts::TAU; | |
| 82 | - let bin = &mut bins[(hue * HUE_BINS as f32) as usize % HUE_BINS]; | |
| 83 | - bin.0 += chroma; | |
| 84 | - bin.1 += angle.cos() * chroma; | |
| 85 | - bin.2 += angle.sin() * chroma; | |
| 86 | - } | |
| 87 | - | |
| 88 | - let pixels = image.pixels().len(); | |
| 89 | - let total: f32 = bins.iter().map(|bin| bin.0).sum(); | |
| 90 | - let (weight, x, y) = bins.into_iter().max_by(|a, b| a.0.total_cmp(&b.0))?; | |
| 91 | - if weight < total * 0.05 || total < pixels as f32 * 0.03 { | |
| 92 | - return None; | |
| 93 | - } | |
| 94 | - | |
| 95 | - Some(y.atan2(x).rem_euclid(std::f32::consts::TAU) / std::f32::consts::TAU) | |
| 96 | -} |
crates/client/src/gui.rsmodified+35 -118
| @@ -1,8 +1,7 @@ | ||
| 1 | -use common::model::Id; | |
| 1 | +use common::model::{Hue, Id}; | |
| 2 | 2 | use std::{ |
| 3 | 3 | collections::HashMap, |
| 4 | 4 | fmt::Display, |
| 5 | - hash::{DefaultHasher, Hash, Hasher}, | |
| 6 | 5 | sync::Arc, |
| 7 | 6 | time::{Duration, Instant}, |
| 8 | 7 | }; |
| @@ -25,12 +24,12 @@ use gpui_kit::{ | ||
| 25 | 24 | StatefulInteractiveElement, Styled, WeakEntity, Window, actions, |
| 26 | 25 | base::Selectable, |
| 27 | 26 | component::{ |
| 28 | - ActiveTheme, Sizable, Theme, ThemeRegistry, WindowExt, | |
| 27 | + Sizable, Theme, ThemeRegistry, WindowExt, | |
| 29 | 28 | input::{Input, InputEvent, InputState}, |
| 30 | 29 | notification::Notification, |
| 31 | 30 | spinner::Spinner, |
| 32 | 31 | }, |
| 33 | - div, ease_out_quint, hsla, img, px, rems, rgb, | |
| 32 | + div, ease_out_quint, img, px, rems, | |
| 34 | 33 | }; |
| 35 | 34 | use jiff::{Timestamp, tz::TimeZone}; |
| 36 | 35 | use tokio::sync::mpsc; |
| @@ -39,10 +38,13 @@ use crate::{ | ||
| 39 | 38 | accounts::{self, Accounts}, |
| 40 | 39 | mutes, |
| 41 | 40 | net::{Fail, LinkError, NetworkEvent, NetworkHandle}, |
| 42 | - settings::{Look, Scale, Settings, ThemeChoice}, | |
| 41 | + settings::{Scale, Settings}, | |
| 43 | 42 | }; |
| 44 | 43 | |
| 45 | 44 | mod auth; |
| 45 | +pub mod gallery; | |
| 46 | +mod parts; | |
| 47 | +pub mod style; | |
| 46 | 48 | mod builder; |
| 47 | 49 | mod camera_view; |
| 48 | 50 | mod chat; |
| @@ -68,6 +70,7 @@ mod wave; | ||
| 68 | 70 | mod widget; |
| 69 | 71 | |
| 70 | 72 | use auth::Auth; |
| 73 | +use style::Tokens; | |
| 71 | 74 | use chat::{Chat, View}; |
| 72 | 75 | use voice_settings::VoiceControls; |
| 73 | 76 | |
| @@ -79,11 +82,6 @@ pub fn text(size: f32) -> Rems { | ||
| 79 | 82 | rems(size / BASE_FONT) |
| 80 | 83 | } |
| 81 | 84 | |
| 82 | -const TINTS: [u32; 10] = [ | |
| 83 | - 0x10b981, 0xa855f7, 0xf59e0b, 0xf97316, 0xec4899, 0x0ea5e9, 0x22c55e, 0xef4444, 0x06b6d4, | |
| 84 | - 0xd946ef, | |
| 85 | -]; | |
| 86 | - | |
| 87 | 85 | #[derive(Clone, Copy)] |
| 88 | 86 | pub struct Palette { |
| 89 | 87 | pub window: Hsla, |
| @@ -102,102 +100,47 @@ pub struct Palette { | ||
| 102 | 100 | pub screen: Hsla, |
| 103 | 101 | pub camera: Hsla, |
| 104 | 102 | pub dark: bool, |
| 103 | + pub tokens: Tokens, | |
| 105 | 104 | } |
| 106 | 105 | |
| 107 | 106 | impl Palette { |
| 108 | 107 | pub fn tinted(self, id: Id) -> Hsla { |
| 109 | - let color = tint(id); | |
| 110 | - if self.dark { | |
| 111 | - color | |
| 112 | - } else { | |
| 113 | - hsla(color.h, color.s, color.l * 0.62, 1.) | |
| 114 | - } | |
| 115 | - } | |
| 116 | - | |
| 117 | - pub fn for_community(self, community: Option<&Community>, hues: &HashMap<Id, f32>) -> Self { | |
| 118 | - let Some(community) = community else { | |
| 119 | - return self; | |
| 120 | - }; | |
| 121 | - let (id, avatar_id) = match &community.kind { | |
| 122 | - CommunityKind::Group | CommunityKind::Notes => (&community.id, &community.avatar_id), | |
| 123 | - CommunityKind::Direct { peer } => (&peer.id, &peer.avatar_id), | |
| 124 | - }; | |
| 125 | - let accent = match avatar_id.as_ref().and_then(|avatar_id| hues.get(avatar_id)) { | |
| 126 | - Some(&hue) if self.dark => hsla(hue, 0.75, 0.55, 1.), | |
| 127 | - Some(&hue) => hsla(hue, 0.75, 0.4, 1.), | |
| 128 | - None => self.tinted(*id), | |
| 129 | - }; | |
| 130 | - Palette { accent, ..self } | |
| 108 | + self.tokens.person(id) | |
| 131 | 109 | } |
| 132 | 110 | } |
| 133 | 111 | |
| 134 | 112 | pub fn palette(cx: &App) -> Palette { |
| 135 | - let black = cx | |
| 136 | - .try_global::<Look>() | |
| 137 | - .is_some_and(|look| look.0 == ThemeChoice::Black); | |
| 138 | - let dark = cx.theme().is_dark(); | |
| 139 | - let (window, panel, field, border, text, body, muted, hover) = match (dark, black) { | |
| 140 | - (true, true) => ( | |
| 141 | - 0x000000, 0x000000, 0x0e0e11, 0x1d1d22, 0xececf0, 0xd4d4da, 0x8f8f99, 0x16161a, | |
| 142 | - ), | |
| 143 | - (true, false) => ( | |
| 144 | - 0x121419, 0x191c23, 0x20232b, 0x2a2e38, 0xececf0, 0xd4d6de, 0x9094a0, 0x232733, | |
| 145 | - ), | |
| 146 | - _ => ( | |
| 147 | - 0xf3f4f8, 0xffffff, 0xffffff, 0xe1e3ea, 0x1c1d24, 0x33353f, 0x6b6e7a, 0xe8eaf1, | |
| 148 | - ), | |
| 149 | - }; | |
| 150 | - let (accent, alert) = if dark { | |
| 151 | - (0xec4899, 0xef4444) | |
| 152 | - } else { | |
| 153 | - (0xdb2777, 0xdc2626) | |
| 154 | - }; | |
| 155 | - | |
| 113 | + let tokens = Tokens::of(cx); | |
| 156 | 114 | Palette { |
| 157 | - window: rgb(window).into(), | |
| 158 | - panel: rgb(panel).into(), | |
| 159 | - field: rgb(field).into(), | |
| 160 | - border: rgb(border).into(), | |
| 161 | - text: rgb(text).into(), | |
| 162 | - body: rgb(body).into(), | |
| 163 | - muted: rgb(muted).into(), | |
| 164 | - hover: rgb(hover).into(), | |
| 165 | - accent: rgb(accent).into(), | |
| 166 | - on_accent: rgb(0xffffff).into(), | |
| 167 | - ok: rgb(0x3fb950).into(), | |
| 168 | - danger: rgb(0xd1483f).into(), | |
| 169 | - alert: rgb(alert).into(), | |
| 170 | - screen: rgb(if dark { 0x60a5fa } else { 0x2563eb }).into(), | |
| 171 | - camera: rgb(if dark { 0xf5a524 } else { 0xc2410c }).into(), | |
| 172 | - dark, | |
| 115 | + window: tokens.ground(), | |
| 116 | + panel: tokens.ground(), | |
| 117 | + field: tokens.raise(), | |
| 118 | + border: tokens.thread(), | |
| 119 | + text: tokens.paper(), | |
| 120 | + body: tokens.paper(), | |
| 121 | + muted: tokens.dim(), | |
| 122 | + hover: tokens.hov(), | |
| 123 | + accent: tokens.paper(), | |
| 124 | + on_accent: tokens.ground(), | |
| 125 | + ok: tokens.hue(Hue::Mint), | |
| 126 | + danger: tokens.bad(), | |
| 127 | + alert: tokens.bad(), | |
| 128 | + screen: tokens.hue(Hue::Sky), | |
| 129 | + camera: tokens.hue(Hue::Amber), | |
| 130 | + dark: tokens.dark(), | |
| 131 | + tokens, | |
| 173 | 132 | } |
| 174 | 133 | } |
| 175 | 134 | |
| 176 | -pub fn sync_accent(accent: Hsla, cx: &mut App) { | |
| 177 | - let theme = Theme::global_mut(cx); | |
| 178 | - if theme.colors.ring == accent { | |
| 179 | - return; | |
| 180 | - } | |
| 181 | - let colors = &mut theme.colors; | |
| 182 | - colors.primary = accent; | |
| 183 | - colors.primary_hover = accent.opacity(0.85); | |
| 184 | - colors.primary_active = accent; | |
| 185 | - colors.ring = accent; | |
| 186 | - colors.caret = accent; | |
| 187 | - theme.tokens = (&theme.colors).into(); | |
| 188 | -} | |
| 189 | - | |
| 190 | -const FONT: &str = "Inter"; | |
| 135 | +const FONT: &str = "Onest"; | |
| 191 | 136 | const MONO_FONT: &str = "Adwaita Mono"; |
| 192 | 137 | |
| 193 | 138 | pub fn init(cx: &mut App) { |
| 194 | 139 | let fonts = [ |
| 195 | - include_bytes!("../assets/fonts/Inter-Regular.ttf").as_slice(), | |
| 196 | - include_bytes!("../assets/fonts/Inter-Italic.ttf"), | |
| 197 | - include_bytes!("../assets/fonts/Inter-Medium.ttf"), | |
| 198 | - include_bytes!("../assets/fonts/Inter-SemiBold.ttf"), | |
| 199 | - include_bytes!("../assets/fonts/Inter-Bold.ttf"), | |
| 200 | - include_bytes!("../assets/fonts/Inter-BoldItalic.ttf"), | |
| 140 | + include_bytes!("../assets/fonts/Onest-Regular.ttf").as_slice(), | |
| 141 | + include_bytes!("../assets/fonts/Onest-Medium.ttf"), | |
| 142 | + include_bytes!("../assets/fonts/Onest-SemiBold.ttf"), | |
| 143 | + include_bytes!("../assets/fonts/Onest-Bold.ttf"), | |
| 201 | 144 | include_bytes!("../assets/fonts/AdwaitaMono-Regular.ttf"), |
| 202 | 145 | include_bytes!("../assets/fonts/AdwaitaMono-Bold.ttf"), |
| 203 | 146 | ]; |
| @@ -258,11 +201,6 @@ pub fn sync_theme(cx: &mut App) { | ||
| 258 | 201 | const FIND_KEY: &str = "ctrl-k"; |
| 259 | 202 | pub const FIND_HINT: &str = "Ctrl K"; |
| 260 | 203 | |
| 261 | -pub fn tint(id: Id) -> Hsla { | |
| 262 | - let mut hasher = DefaultHasher::new(); | |
| 263 | - id.hash(&mut hasher); | |
| 264 | - rgb(TINTS[hasher.finish() as usize % TINTS.len()]).into() | |
| 265 | -} | |
| 266 | 204 | |
| 267 | 205 | pub fn badge(palette: Palette, id: Id, name: &str, size: Pixels, font: Rems) -> Div { |
| 268 | 206 | let initial = name |
| @@ -278,7 +216,7 @@ pub fn badge(palette: Palette, id: Id, name: &str, size: Pixels, font: Rems) -> | ||
| 278 | 216 | .flex() |
| 279 | 217 | .items_center() |
| 280 | 218 | .justify_center() |
| 281 | - .bg(tint(id)) | |
| 219 | + .bg(palette.tinted(id)) | |
| 282 | 220 | .text_color(palette.on_accent) |
| 283 | 221 | .text_size(font) |
| 284 | 222 | .font_weight(FontWeight::SEMIBOLD) |
| @@ -721,15 +659,6 @@ impl Yumush { | ||
| 721 | 659 | pub fn attach_window(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 722 | 660 | self.window = Some(window.window_handle()); |
| 723 | 661 | |
| 724 | - cx.observe_window_appearance(window, |yumush, window, cx| { | |
| 725 | - if yumush.settings.theme == ThemeChoice::System { | |
| 726 | - Theme::sync_system_appearance(Some(window), cx); | |
| 727 | - sync_theme(cx); | |
| 728 | - } | |
| 729 | - cx.notify(); | |
| 730 | - }) | |
| 731 | - .detach(); | |
| 732 | - | |
| 733 | 662 | cx.observe_window_activation(window, |yumush, window, cx| { |
| 734 | 663 | if window.is_window_active() { |
| 735 | 664 | yumush.read_selected(cx); |
| @@ -902,14 +831,6 @@ impl Yumush { | ||
| 902 | 831 | cx.notify(); |
| 903 | 832 | } |
| 904 | 833 | |
| 905 | - pub fn themed(&self, cx: &App) -> Palette { | |
| 906 | - let community = match self.chat.view { | |
| 907 | - View::Settings | View::Builder => None, | |
| 908 | - _ => self.chat.selected_community(), | |
| 909 | - }; | |
| 910 | - palette(cx).for_community(community, &self.chat.hues) | |
| 911 | - } | |
| 912 | - | |
| 913 | 834 | pub fn actor_rank(&self) -> Option<Rank> { |
| 914 | 835 | self.user.as_ref().and_then(|me| self.chat.rank_of(me)) |
| 915 | 836 | } |
| @@ -956,9 +877,6 @@ impl Yumush { | ||
| 956 | 877 | let _ = this.update(cx, |yumush, cx| { |
| 957 | 878 | yumush.chat.avatar_requests.remove(&avatar_id); |
| 958 | 879 | if let Ok(bytes) = result { |
| 959 | - if let Some(hue) = crate::avatar::dominant_hue(&bytes) { | |
| 960 | - yumush.chat.hues.insert(avatar_id, hue); | |
| 961 | - } | |
| 962 | 880 | yumush.chat.avatars.insert( |
| 963 | 881 | avatar_id, |
| 964 | 882 | Arc::new(Image::from_bytes(ImageFormat::Jpeg, bytes)), |
| @@ -1335,7 +1253,7 @@ pub fn input_dialog( | ||
| 1335 | 1253 | let entity = cx.entity(); |
| 1336 | 1254 | let dialog_input = input.clone(); |
| 1337 | 1255 | window.open_dialog(cx, move |dialog, _, cx| { |
| 1338 | - let palette = entity.read(cx).themed(cx); | |
| 1256 | + let palette = palette(cx); | |
| 1339 | 1257 | let entity = entity.clone(); |
| 1340 | 1258 | let on_submit = on_submit.clone(); |
| 1341 | 1259 | let button_input = dialog_input.clone(); |
| @@ -1404,7 +1322,6 @@ impl Render for Yumush { | ||
| 1404 | 1322 | self.hide_idle_cursor(window, cx); |
| 1405 | 1323 | self.schedule_pump(window, cx); |
| 1406 | 1324 | let palette = palette(cx); |
| 1407 | - sync_accent(self.themed(cx).accent, cx); | |
| 1408 | 1325 | let route = self.current_route; |
| 1409 | 1326 | let page = match route { |
| 1410 | 1327 | Route::Login | Route::Register => self.auth_page(route, cx).into_any_element(), |
crates/client/src/gui/chat.rsmodified+2 -4
| @@ -163,7 +163,6 @@ pub struct Chat { | ||
| 163 | 163 | pub(super) community_name_input: Entity<InputState>, |
| 164 | 164 | pub(super) status_input: Entity<InputState>, |
| 165 | 165 | pub(super) avatars: HashMap<Id, Arc<Image>>, |
| 166 | - pub(super) hues: HashMap<Id, f32>, | |
| 167 | 166 | pub(super) avatar_requests: HashSet<Id>, |
| 168 | 167 | pub(super) users: HashMap<Id, User>, |
| 169 | 168 | user_requests: HashSet<Id>, |
| @@ -400,7 +399,6 @@ impl Chat { | ||
| 400 | 399 | ), |
| 401 | 400 | status_input: editable_input("Status...", Yumush::save_status, window, cx), |
| 402 | 401 | avatars: HashMap::new(), |
| 403 | - hues: HashMap::new(), | |
| 404 | 402 | avatar_requests: HashSet::new(), |
| 405 | 403 | users: HashMap::new(), |
| 406 | 404 | user_requests: HashSet::new(), |
| @@ -1329,7 +1327,7 @@ impl Yumush { | ||
| 1329 | 1327 | } |
| 1330 | 1328 | |
| 1331 | 1329 | fn main_panel(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> impl IntoElement { |
| 1332 | - let themed = self.themed(cx); | |
| 1330 | + let themed = palette; | |
| 1333 | 1331 | |
| 1334 | 1332 | div() |
| 1335 | 1333 | .flex_1() |
| @@ -2201,7 +2199,7 @@ impl Yumush { | ||
| 2201 | 2199 | fn confirm_ghost_speak(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 2202 | 2200 | let entity = cx.entity(); |
| 2203 | 2201 | window.open_dialog(cx, move |dialog, _, cx| { |
| 2204 | - let palette = entity.read(cx).themed(cx); | |
| 2202 | + let palette = super::palette(cx); | |
| 2205 | 2203 | let speak = entity.clone(); |
| 2206 | 2204 | |
| 2207 | 2205 | dialog.title("Speak as ghost?").child( |
crates/client/src/gui/community_settings.rsmodified+2 -2
| @@ -350,7 +350,7 @@ impl Yumush { | ||
| 350 | 350 | let entity = cx.entity(); |
| 351 | 351 | window.open_dialog(cx, move |dialog, _, cx| { |
| 352 | 352 | let yumush = entity.read(cx); |
| 353 | - let palette = yumush.themed(cx); | |
| 353 | + let palette = super::palette(cx); | |
| 354 | 354 | let query = search_text(&yumush.chat.ban_search, cx); |
| 355 | 355 | let rows: Vec<AnyElement> = ban_list(&yumush.chat.bans, &query, yumush.chat.ban_sort) |
| 356 | 356 | .into_iter() |
| @@ -391,7 +391,7 @@ impl Yumush { | ||
| 391 | 391 | let entity = cx.entity(); |
| 392 | 392 | window.open_dialog(cx, move |dialog, _, cx| { |
| 393 | 393 | let yumush = entity.read(cx); |
| 394 | - let palette = yumush.themed(cx); | |
| 394 | + let palette = super::palette(cx); | |
| 395 | 395 | let query = search_text(&yumush.chat.log_search, cx); |
| 396 | 396 | let rows: Vec<AnyElement> = log_list(&yumush.chat.logs, &query, yumush.chat.log_sort) |
| 397 | 397 | .into_iter() |
crates/client/src/gui/gallery.rsadded+193 -0
| @@ -0,0 +1,193 @@ | ||
| 1 | +use std::collections::VecDeque; | |
| 2 | + | |
| 3 | +use common::model::Hue; | |
| 4 | +use gpui_kit::{ | |
| 5 | + Context, IntoElement, ParentElement, Render, Styled, Window, assets::IconName, div, px, | |
| 6 | +}; | |
| 7 | + | |
| 8 | +use super::{ | |
| 9 | + parts::{ | |
| 10 | + Fill, Ink, Press, Text, Tone, Voice, band, button, caption, chevron, column, grow, | |
| 11 | + icon_button, index_item, options, popover, row, section, spark, stack, strong, toggle, | |
| 12 | + track, voice_line, words, | |
| 13 | + }, | |
| 14 | + style::{Theme, Tokens, size, space}, | |
| 15 | +}; | |
| 16 | +use crate::settings::FontSize; | |
| 17 | + | |
| 18 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| 19 | +pub enum State { | |
| 20 | + Base, | |
| 21 | + Long, | |
| 22 | + Empty, | |
| 23 | + Many, | |
| 24 | + Gun, | |
| 25 | + Large, | |
| 26 | + Narrow, | |
| 27 | + Bad, | |
| 28 | +} | |
| 29 | + | |
| 30 | +impl State { | |
| 31 | + pub const ALL: [State; 8] = [ | |
| 32 | + State::Base, | |
| 33 | + State::Long, | |
| 34 | + State::Empty, | |
| 35 | + State::Many, | |
| 36 | + State::Gun, | |
| 37 | + State::Large, | |
| 38 | + State::Narrow, | |
| 39 | + State::Bad, | |
| 40 | + ]; | |
| 41 | + | |
| 42 | + pub fn as_str(self) -> &'static str { | |
| 43 | + match self { | |
| 44 | + State::Base => "base", | |
| 45 | + State::Long => "long", | |
| 46 | + State::Empty => "empty", | |
| 47 | + State::Many => "many", | |
| 48 | + State::Gun => "gun", | |
| 49 | + State::Large => "large", | |
| 50 | + State::Narrow => "narrow", | |
| 51 | + State::Bad => "bad", | |
| 52 | + } | |
| 53 | + } | |
| 54 | + | |
| 55 | + pub fn parse(text: &str) -> Option<Self> { | |
| 56 | + Self::ALL.into_iter().find(|state| state.as_str() == text) | |
| 57 | + } | |
| 58 | + | |
| 59 | + pub fn theme(self) -> Theme { | |
| 60 | + match self { | |
| 61 | + State::Gun => Theme::Gun, | |
| 62 | + _ => Theme::Gece, | |
| 63 | + } | |
| 64 | + } | |
| 65 | + | |
| 66 | + pub fn font_size(self) -> FontSize { | |
| 67 | + match self { | |
| 68 | + State::Large => FontSize::Large, | |
| 69 | + _ => FontSize::Medium, | |
| 70 | + } | |
| 71 | + } | |
| 72 | + | |
| 73 | + pub fn window(self) -> (f32, f32) { | |
| 74 | + match self { | |
| 75 | + State::Narrow => (800., 600.), | |
| 76 | + _ => (1120., 720.), | |
| 77 | + } | |
| 78 | + } | |
| 79 | +} | |
| 80 | + | |
| 81 | +pub struct Gallery { | |
| 82 | + page: String, | |
| 83 | + state: State, | |
| 84 | +} | |
| 85 | + | |
| 86 | +impl Gallery { | |
| 87 | + pub fn new(page: String, state: State) -> Self { | |
| 88 | + Self { page, state } | |
| 89 | + } | |
| 90 | +} | |
| 91 | + | |
| 92 | +impl Render for Gallery { | |
| 93 | + fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { | |
| 94 | + let t = Tokens::of(cx); | |
| 95 | + let page = match self.page.as_str() { | |
| 96 | + "parts" => parts_page(self.state, t).into_any_element(), | |
| 97 | + other => words(format!("no gallery page {other}"), Text::Body, Ink::Bad, t).into_any_element(), | |
| 98 | + }; | |
| 99 | + div() | |
| 100 | + .size_full() | |
| 101 | + .bg(t.ground()) | |
| 102 | + .text_color(t.paper()) | |
| 103 | + .p(px(space::XXL)) | |
| 104 | + .child(page) | |
| 105 | + } | |
| 106 | +} | |
| 107 | + | |
| 108 | +fn name(state: State, base: &'static str) -> String { | |
| 109 | + match state { | |
| 110 | + State::Long => format!("{base} with a name that keeps going past the edge"), | |
| 111 | + State::Empty => String::new(), | |
| 112 | + _ => base.to_string(), | |
| 113 | + } | |
| 114 | +} | |
| 115 | + | |
| 116 | +fn bands(seed: f32) -> VecDeque<f32> { | |
| 117 | + (0..24) | |
| 118 | + .map(|index| ((index as f32 * 0.7 + seed).sin() * 0.5 + 0.5) * 0.8) | |
| 119 | + .collect() | |
| 120 | +} | |
| 121 | + | |
| 122 | +fn parts_page(state: State, t: Tokens) -> impl IntoElement { | |
| 123 | + let live = bands(1.); | |
| 124 | + let voice = if state == State::Bad { | |
| 125 | + Voice::Frayed | |
| 126 | + } else { | |
| 127 | + Voice::Live(t.hue(Hue::Amber)) | |
| 128 | + }; | |
| 129 | + let lines = stack(space::SM) | |
| 130 | + .child(section("Lines", t)) | |
| 131 | + .child(caption(name(state, "alice"), voice_line(Some(&live), voice, t), t)) | |
| 132 | + .child(caption(name(state, "bob"), voice_line(None, Voice::Quiet, t), t)) | |
| 133 | + .child(caption("carol", voice_line(Some(&bands(3.)), Voice::Live(t.hue(Hue::Violet)), t), t)) | |
| 134 | + .child( | |
| 135 | + band(space::MD) | |
| 136 | + .h(px(size::ROW)) | |
| 137 | + .child(words("ping", Text::Caption, Ink::Dim, t)) | |
| 138 | + .child(div().flex_1().h_full().child(spark( | |
| 139 | + (0..40).map(|index| (index as f32 * 0.5).sin() * 0.3 + 0.5).collect(), | |
| 140 | + 40, | |
| 141 | + if state == State::Bad { t.bad() } else { t.paper() }, | |
| 142 | + ))) | |
| 143 | + .child(strong(if state == State::Bad { "212 ms" } else { "24 ms" }, Text::Ui, t)), | |
| 144 | + ); | |
| 145 | + let rows = column() | |
| 146 | + .child(section("Rows", t)) | |
| 147 | + .child(row(name(state, "Noise suppression"), toggle("g_toggle", true, t, |_, _| {}), t)) | |
| 148 | + .child(row("Mute", toggle("g_toggle_off", false, t, |_, _| {}), t)) | |
| 149 | + .child(row( | |
| 150 | + "Mode", | |
| 151 | + options("g_mode", [(0, "Voice activity"), (1, "Push to talk")], 0, t, |_, _, _| {}), | |
| 152 | + t, | |
| 153 | + )) | |
| 154 | + .child(row("CPU", band(space::MD).w(px(size::POPOVER)).child(track(Fill::Over { own: 0.09, total: 0.31 }, false, t)).child(words("9 / 31 %", Text::Label, Ink::Paper, t)), t)) | |
| 155 | + .child(row("Loss", band(space::MD).w(px(size::POPOVER)).child(track(Fill::Part(0.42), state == State::Bad, t)).child(words("4.2 %", Text::Label, if state == State::Bad { Ink::Bad } else { Ink::Paper }, t)), t)); | |
| 156 | + let controls = stack(space::MD) | |
| 157 | + .child(section("Controls", t)) | |
| 158 | + .child( | |
| 159 | + band(space::XS) | |
| 160 | + .child(icon_button("g_mic", IconName::Mic, "Mute", Tone::Idle, t, |_, _| {})) | |
| 161 | + .child(chevron("g_mic_more", false, t, |_, _| {})) | |
| 162 | + .child(icon_button("g_cam", IconName::Camera, "Camera", Tone::On, t, |_, _| {})) | |
| 163 | + .child(chevron("g_cam_more", true, t, |_, _| {})) | |
| 164 | + .child(icon_button("g_leave", IconName::PhoneOff, "Leave", Tone::Danger, t, |_, _| {})), | |
| 165 | + ) | |
| 166 | + .child( | |
| 167 | + band(space::XL) | |
| 168 | + .child(button("g_plain", "Change source", Press::Plain, t, |_, _| {})) | |
| 169 | + .child(button("g_stop", "Stop", Press::Danger, t, |_, _| {})) | |
| 170 | + .child(button("g_share", "Share", Press::Primary, t, |_, _| {})), | |
| 171 | + ) | |
| 172 | + .child( | |
| 173 | + column() | |
| 174 | + .w(px(size::SIDEBAR)) | |
| 175 | + .child(index_item("g_i1", "Profile", false, t, |_, _| {})) | |
| 176 | + .child(index_item("g_i2", "Voice", true, t, |_, _| {})) | |
| 177 | + .child(index_item("g_i3", name(state, "Camera & share"), false, t, |_, _| {})), | |
| 178 | + ); | |
| 179 | + let pop = popover(t) | |
| 180 | + .w(px(size::POPOVER)) | |
| 181 | + .gap(px(space::SM)) | |
| 182 | + .child(section("Microphone", t)) | |
| 183 | + .child(words("Shure MV7", Text::Ui, Ink::Paper, t)) | |
| 184 | + .child(words("Laptop mic", Text::Ui, Ink::Dim, t)) | |
| 185 | + .child(div().h(px(size::ICON)).child(voice_line(Some(&live), voice, t))) | |
| 186 | + .child(row("Noise suppression", toggle("g_pop_toggle", true, t, |_, _| {}), t)); | |
| 187 | + band(space::XXL) | |
| 188 | + .items_start() | |
| 189 | + .size_full() | |
| 190 | + .child(stack(space::XL).flex_1().child(lines).child(rows)) | |
| 191 | + .child(stack(space::XL).w(px(size::TALK + size::CONTROL)).child(controls).child(pop)) | |
| 192 | + .child(grow()) | |
| 193 | +} |
crates/client/src/gui/parts.rsadded+371 -0
| @@ -0,0 +1,371 @@ | ||
| 1 | +use std::collections::VecDeque; | |
| 2 | + | |
| 3 | +use gpui_kit::{ | |
| 4 | + prelude::FluentBuilder, | |
| 5 | + AnyElement, App, Div, ElementId, FontWeight, Hsla, InteractiveElement, IntoElement, | |
| 6 | + ParentElement, PathBuilder, SharedString, Stateful, StatefulInteractiveElement, Styled, Window, | |
| 7 | + assets::IconName, canvas, component::Icon, div, point, px, | |
| 8 | +}; | |
| 9 | + | |
| 10 | +use super::{ | |
| 11 | + Tooltip as _, | |
| 12 | + style::{Tokens, radius, size, space, stroke, text}, | |
| 13 | +}; | |
| 14 | + | |
| 15 | +#[derive(Clone, Copy, PartialEq, Eq)] | |
| 16 | +pub enum Text { | |
| 17 | + Caption, | |
| 18 | + Label, | |
| 19 | + Ui, | |
| 20 | + Body, | |
| 21 | + Title, | |
| 22 | + Display, | |
| 23 | +} | |
| 24 | + | |
| 25 | +impl Text { | |
| 26 | + fn size(self) -> f32 { | |
| 27 | + match self { | |
| 28 | + Text::Caption => text::CAPTION, | |
| 29 | + Text::Label => text::LABEL, | |
| 30 | + Text::Ui => text::UI, | |
| 31 | + Text::Body => text::BODY, | |
| 32 | + Text::Title => text::TITLE, | |
| 33 | + Text::Display => text::DISPLAY, | |
| 34 | + } | |
| 35 | + } | |
| 36 | +} | |
| 37 | + | |
| 38 | +#[derive(Clone, Copy, PartialEq, Eq)] | |
| 39 | +pub enum Ink { | |
| 40 | + Paper, | |
| 41 | + Dim, | |
| 42 | + Faint, | |
| 43 | + Bad, | |
| 44 | +} | |
| 45 | + | |
| 46 | +impl Ink { | |
| 47 | + fn color(self, t: Tokens) -> Hsla { | |
| 48 | + match self { | |
| 49 | + Ink::Paper => t.paper(), | |
| 50 | + Ink::Dim => t.dim(), | |
| 51 | + Ink::Faint => t.faint(), | |
| 52 | + Ink::Bad => t.bad(), | |
| 53 | + } | |
| 54 | + } | |
| 55 | +} | |
| 56 | + | |
| 57 | +pub fn words(content: impl Into<SharedString>, style: Text, ink: Ink, t: Tokens) -> Div { | |
| 58 | + let weight = match style { | |
| 59 | + Text::Title | Text::Display => FontWeight::SEMIBOLD, | |
| 60 | + _ => FontWeight::NORMAL, | |
| 61 | + }; | |
| 62 | + div() | |
| 63 | + .text_size(t.text(style.size())) | |
| 64 | + .font_weight(weight) | |
| 65 | + .text_color(ink.color(t)) | |
| 66 | + .min_w_0() | |
| 67 | + .truncate() | |
| 68 | + .child(content.into()) | |
| 69 | +} | |
| 70 | + | |
| 71 | +pub fn strong(content: impl Into<SharedString>, style: Text, t: Tokens) -> Div { | |
| 72 | + words(content, style, Ink::Paper, t).font_weight(FontWeight::SEMIBOLD) | |
| 73 | +} | |
| 74 | + | |
| 75 | +pub fn colored(content: impl Into<SharedString>, style: Text, color: Hsla, t: Tokens) -> Div { | |
| 76 | + words(content, style, Ink::Paper, t) | |
| 77 | + .font_weight(FontWeight::MEDIUM) | |
| 78 | + .text_color(color) | |
| 79 | +} | |
| 80 | + | |
| 81 | +pub fn thread(t: Tokens) -> Div { | |
| 82 | + div().w_full().h(px(stroke::LINE)).flex_none().bg(t.thread()) | |
| 83 | +} | |
| 84 | + | |
| 85 | +pub fn grow() -> Div { | |
| 86 | + div().flex_1() | |
| 87 | +} | |
| 88 | + | |
| 89 | +pub fn column() -> Div { | |
| 90 | + div().flex().flex_col().min_w_0() | |
| 91 | +} | |
| 92 | + | |
| 93 | +pub fn stack(gap: f32) -> Div { | |
| 94 | + column().gap(px(gap)) | |
| 95 | +} | |
| 96 | + | |
| 97 | +pub fn band(gap: f32) -> Div { | |
| 98 | + div().flex().items_center().min_w_0().gap(px(gap)) | |
| 99 | +} | |
| 100 | + | |
| 101 | +pub fn row(label: impl Into<SharedString>, trailing: impl IntoElement, t: Tokens) -> Div { | |
| 102 | + column().child(thread(t)).child( | |
| 103 | + band(space::XL) | |
| 104 | + .min_h(px(size::ROW)) | |
| 105 | + .py(px(space::SM)) | |
| 106 | + .child(words(label, Text::Ui, Ink::Paper, t).flex_shrink_0().max_w(gpui_kit::relative(0.5))) | |
| 107 | + .child(grow()) | |
| 108 | + .child(trailing), | |
| 109 | + ) | |
| 110 | +} | |
| 111 | + | |
| 112 | +pub fn section(title: impl Into<SharedString>, t: Tokens) -> Div { | |
| 113 | + words(title, Text::Caption, Ink::Faint, t).pb(px(space::XS)) | |
| 114 | +} | |
| 115 | + | |
| 116 | +#[derive(Clone, Copy)] | |
| 117 | +pub enum Fill { | |
| 118 | + Part(f32), | |
| 119 | + Over { own: f32, total: f32 }, | |
| 120 | +} | |
| 121 | + | |
| 122 | +pub fn track(fill: Fill, bad: bool, t: Tokens) -> Div { | |
| 123 | + let segment = |share: f32, color: Hsla| { | |
| 124 | + div() | |
| 125 | + .absolute() | |
| 126 | + .left_0() | |
| 127 | + .top(px(4.)) | |
| 128 | + .h(px(stroke::LINE)) | |
| 129 | + .w(gpui_kit::relative(share.clamp(0., 1.))) | |
| 130 | + .bg(color) | |
| 131 | + }; | |
| 132 | + let ink = if bad { t.bad() } else { t.paper() }; | |
| 133 | + let base = div() | |
| 134 | + .relative() | |
| 135 | + .flex_1() | |
| 136 | + .h(px(10.)) | |
| 137 | + .child(segment(1., t.thread())); | |
| 138 | + match fill { | |
| 139 | + Fill::Part(share) => base.child(segment(share, ink)), | |
| 140 | + Fill::Over { own, total } => base.child(segment(total, t.dim())).child(segment(own, ink)), | |
| 141 | + } | |
| 142 | +} | |
| 143 | + | |
| 144 | +pub fn toggle(id: impl Into<ElementId>, on: bool, t: Tokens, flip: impl Fn(&mut Window, &mut App) + 'static) -> Stateful<Div> { | |
| 145 | + let (bar, knob, left) = if on { | |
| 146 | + (t.hue(common::model::Hue::Amber), t.paper(), 20.) | |
| 147 | + } else { | |
| 148 | + (t.faint(), t.faint(), 0.) | |
| 149 | + }; | |
| 150 | + div() | |
| 151 | + .id(id) | |
| 152 | + .cursor_pointer() | |
| 153 | + .relative() | |
| 154 | + .w(px(30.)) | |
| 155 | + .h(px(14.)) | |
| 156 | + .on_click(move |_, window, cx| flip(window, cx)) | |
| 157 | + .child(div().absolute().left_0().right_0().top(px(6.)).h(px(stroke::LINE)).bg(bar)) | |
| 158 | + .child(div().absolute().top(px(2.)).left(px(left)).size(px(10.)).rounded_full().bg(knob)) | |
| 159 | +} | |
| 160 | + | |
| 161 | +pub fn options<T: Copy + PartialEq + 'static>( | |
| 162 | + id: &'static str, | |
| 163 | + items: impl IntoIterator<Item = (T, &'static str)>, | |
| 164 | + selected: T, | |
| 165 | + t: Tokens, | |
| 166 | + pick: impl Fn(T, &mut Window, &mut App) + Clone + 'static, | |
| 167 | +) -> Div { | |
| 168 | + band(space::LG).children(items.into_iter().map(|(item, label)| { | |
| 169 | + let on = item == selected; | |
| 170 | + let pick = pick.clone(); | |
| 171 | + column() | |
| 172 | + .gap(px(3.)) | |
| 173 | + .id(ElementId::Name(format!("{id}_{label}").into())) | |
| 174 | + .cursor_pointer() | |
| 175 | + .on_click(move |_, window, cx| pick(item, window, cx)) | |
| 176 | + .child(words(label, Text::Ui, if on { Ink::Paper } else { Ink::Dim }, t).font_weight(FontWeight::MEDIUM)) | |
| 177 | + .child(div().h(px(stroke::LINE)).bg(if on { t.paper() } else { gpui_kit::transparent_black() })) | |
| 178 | + })) | |
| 179 | +} | |
| 180 | + | |
| 181 | +#[derive(Clone, Copy, PartialEq, Eq)] | |
| 182 | +pub enum Press { | |
| 183 | + Plain, | |
| 184 | + Primary, | |
| 185 | + Danger, | |
| 186 | +} | |
| 187 | + | |
| 188 | +pub fn button( | |
| 189 | + id: impl Into<ElementId>, | |
| 190 | + label: impl Into<SharedString>, | |
| 191 | + kind: Press, | |
| 192 | + t: Tokens, | |
| 193 | + on_click: impl Fn(&mut Window, &mut App) + 'static, | |
| 194 | +) -> Stateful<Div> { | |
| 195 | + let base = band(space::SM) | |
| 196 | + .id(id) | |
| 197 | + .cursor_pointer() | |
| 198 | + .flex_none() | |
| 199 | + .on_click(move |_, window, cx| on_click(window, cx)); | |
| 200 | + let label = label.into(); | |
| 201 | + match kind { | |
| 202 | + Press::Plain => base.child(words(label, Text::Ui, Ink::Paper, t).font_weight(FontWeight::MEDIUM)), | |
| 203 | + Press::Danger => base.child(words(label, Text::Ui, Ink::Bad, t).font_weight(FontWeight::MEDIUM)), | |
| 204 | + Press::Primary => base | |
| 205 | + .px(px(space::LG + 2.)) | |
| 206 | + .h(px(32.)) | |
| 207 | + .rounded_full() | |
| 208 | + .bg(t.paper()) | |
| 209 | + .hover(|style| style.opacity(0.9)) | |
| 210 | + .child(words(label, Text::Ui, Ink::Paper, t).font_weight(FontWeight::SEMIBOLD).text_color(t.ground())), | |
| 211 | + } | |
| 212 | +} | |
| 213 | + | |
| 214 | +#[derive(Clone, Copy, PartialEq, Eq)] | |
| 215 | +pub enum Tone { | |
| 216 | + Idle, | |
| 217 | + On, | |
| 218 | + Danger, | |
| 219 | +} | |
| 220 | + | |
| 221 | +pub fn icon_button( | |
| 222 | + id: impl Into<ElementId>, | |
| 223 | + icon: IconName, | |
| 224 | + tip: &'static str, | |
| 225 | + tone: Tone, | |
| 226 | + t: Tokens, | |
| 227 | + on_click: impl Fn(&mut Window, &mut App) + 'static, | |
| 228 | +) -> Stateful<Div> { | |
| 229 | + let (ink, fill) = match tone { | |
| 230 | + Tone::Idle => (t.dim(), None), | |
| 231 | + Tone::On => (t.paper(), Some(t.press())), | |
| 232 | + Tone::Danger => (t.bad(), None), | |
| 233 | + }; | |
| 234 | + let hov = t.hov(); | |
| 235 | + div() | |
| 236 | + .id(id) | |
| 237 | + .tip(tip) | |
| 238 | + .cursor_pointer() | |
| 239 | + .size(px(size::CONTROL)) | |
| 240 | + .flex_none() | |
| 241 | + .flex() | |
| 242 | + .items_center() | |
| 243 | + .justify_center() | |
| 244 | + .rounded_full() | |
| 245 | + .when_some(fill, |this, fill| this.bg(fill)) | |
| 246 | + .hover(move |style| style.bg(hov)) | |
| 247 | + .text_color(ink) | |
| 248 | + .on_click(move |_, window, cx| on_click(window, cx)) | |
| 249 | + .child(Icon::new(icon).size(px(size::ICON))) | |
| 250 | +} | |
| 251 | + | |
| 252 | +pub fn chevron( | |
| 253 | + id: impl Into<ElementId>, | |
| 254 | + open: bool, | |
| 255 | + t: Tokens, | |
| 256 | + on_click: impl Fn(&mut Window, &mut App) + 'static, | |
| 257 | +) -> Stateful<Div> { | |
| 258 | + div() | |
| 259 | + .id(id) | |
| 260 | + .cursor_pointer() | |
| 261 | + .w(px(16.)) | |
| 262 | + .h(px(size::CONTROL)) | |
| 263 | + .flex() | |
| 264 | + .items_center() | |
| 265 | + .justify_center() | |
| 266 | + .text_color(if open { t.paper() } else { t.faint() }) | |
| 267 | + .on_click(move |_, window, cx| on_click(window, cx)) | |
| 268 | + .child(Icon::new(IconName::ChevronUp).size(px(13.))) | |
| 269 | +} | |
| 270 | + | |
| 271 | +pub fn popover(t: Tokens) -> Div { | |
| 272 | + column() | |
| 273 | + .bg(t.raise()) | |
| 274 | + .rounded(px(radius::LG)) | |
| 275 | + .border_1() | |
| 276 | + .border_color(t.thread()) | |
| 277 | + .shadow_lg() | |
| 278 | + .px(px(space::XL - 4.)) | |
| 279 | + .py(px(space::LG + 2.)) | |
| 280 | +} | |
| 281 | + | |
| 282 | +pub fn caption(name: impl Into<SharedString>, line: impl IntoElement, t: Tokens) -> Div { | |
| 283 | + band(space::MD) | |
| 284 | + .h(px(16.)) | |
| 285 | + .child(words(name, Text::Label, Ink::Dim, t).flex_none()) | |
| 286 | + .child(div().flex_1().h_full().child(line)) | |
| 287 | +} | |
| 288 | + | |
| 289 | +pub fn index_item( | |
| 290 | + id: impl Into<ElementId>, | |
| 291 | + label: impl Into<SharedString>, | |
| 292 | + selected: bool, | |
| 293 | + t: Tokens, | |
| 294 | + on_click: impl Fn(&mut Window, &mut App) + 'static, | |
| 295 | +) -> Stateful<Div> { | |
| 296 | + let ink = if selected { Ink::Paper } else { Ink::Dim }; | |
| 297 | + let weight = if selected { FontWeight::MEDIUM } else { FontWeight::NORMAL }; | |
| 298 | + band(space::MD) | |
| 299 | + .id(id) | |
| 300 | + .cursor_pointer() | |
| 301 | + .h(px(32.)) | |
| 302 | + .on_click(move |_, window, cx| on_click(window, cx)) | |
| 303 | + .child(words(label, Text::Ui, ink, t).font_weight(weight)) | |
| 304 | +} | |
| 305 | + | |
| 306 | +#[derive(Clone, Copy, PartialEq)] | |
| 307 | +pub enum Voice { | |
| 308 | + Quiet, | |
| 309 | + Live(Hsla), | |
| 310 | + Frayed, | |
| 311 | +} | |
| 312 | + | |
| 313 | +pub fn voice_line(bands: Option<&VecDeque<f32>>, voice: Voice, t: Tokens) -> AnyElement { | |
| 314 | + let levels: Vec<f32> = bands.map(|bands| bands.iter().copied().collect()).unwrap_or_default(); | |
| 315 | + let color = match voice { | |
| 316 | + Voice::Quiet => t.off(), | |
| 317 | + Voice::Live(color) => color, | |
| 318 | + Voice::Frayed => t.bad(), | |
| 319 | + }; | |
| 320 | + let frayed = voice == Voice::Frayed; | |
| 321 | + canvas( | |
| 322 | + |_, _, _| {}, | |
| 323 | + move |bounds, _, window, _| { | |
| 324 | + let width = f32::from(bounds.size.width); | |
| 325 | + let middle = bounds.origin.y + bounds.size.height / 2.; | |
| 326 | + let half = f32::from(bounds.size.height) / 2.; | |
| 327 | + let steps = (width / 4.).max(8.) as usize; | |
| 328 | + let mut path = PathBuilder::stroke(px(stroke::LINE)); | |
| 329 | + if frayed { | |
| 330 | + path = path.dash_array(&[px(4.), px(3.)]); | |
| 331 | + } | |
| 332 | + for step in 0..=steps { | |
| 333 | + let along = step as f32 / steps as f32; | |
| 334 | + let level = sample(&levels, along); | |
| 335 | + let envelope = (std::f32::consts::PI * along).sin(); | |
| 336 | + let swing = (step as f32 * 0.9).sin(); | |
| 337 | + let x = bounds.origin.x + bounds.size.width * along; | |
| 338 | + let y = middle + px(swing * level * envelope * half * 0.9); | |
| 339 | + if step == 0 { | |
| 340 | + path.move_to(point(x, y)); | |
| 341 | + } else { | |
| 342 | + path.line_to(point(x, y)); | |
| 343 | + } | |
| 344 | + } | |
| 345 | + if let Ok(path) = path.build() { | |
| 346 | + window.paint_path(path, color); | |
| 347 | + } | |
| 348 | + }, | |
| 349 | + ) | |
| 350 | + .size_full() | |
| 351 | + .into_any_element() | |
| 352 | +} | |
| 353 | + | |
| 354 | +fn sample(levels: &[f32], along: f32) -> f32 { | |
| 355 | + if levels.is_empty() { | |
| 356 | + return 0.; | |
| 357 | + } | |
| 358 | + let at = along * (levels.len() - 1) as f32; | |
| 359 | + let low = at.floor() as usize; | |
| 360 | + let high = (low + 1).min(levels.len() - 1); | |
| 361 | + let mix = at - low as f32; | |
| 362 | + levels[low] * (1. - mix) + levels[high] * mix | |
| 363 | +} | |
| 364 | + | |
| 365 | +pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement { | |
| 366 | + super::wave::line_of(values, slots, color).into_any_element() | |
| 367 | +} | |
| 368 | + | |
| 369 | +pub fn person(content: impl Into<SharedString>, hue: Hsla, t: Tokens) -> Div { | |
| 370 | + colored(content, Text::Ui, hue, t).font_weight(FontWeight::SEMIBOLD) | |
| 371 | +} |
crates/client/src/gui/settings_page.rsmodified+6 -3
| @@ -23,7 +23,10 @@ use super::{ | ||
| 23 | 23 | clickable, notify_error, primary_button, text, |
| 24 | 24 | widget::{field, icon_button}, |
| 25 | 25 | }; |
| 26 | -use crate::settings::{self, FontSize, ThemeChoice}; | |
| 26 | +use crate::{ | |
| 27 | + gui::style::Theme, | |
| 28 | + settings::{self, FontSize}, | |
| 29 | +}; | |
| 27 | 30 | |
| 28 | 31 | impl Yumush { |
| 29 | 32 | pub(super) fn settings_page( |
| @@ -95,7 +98,7 @@ impl Yumush { | ||
| 95 | 98 | row( |
| 96 | 99 | "Theme", |
| 97 | 100 | segmented( |
| 98 | - ThemeChoice::ALL.map(|choice| (choice, choice.label())), | |
| 101 | + Theme::ALL.map(|choice| (choice, choice.label())), | |
| 99 | 102 | self.settings.theme, |
| 100 | 103 | entity, |
| 101 | 104 | palette, |
| @@ -243,7 +246,7 @@ impl Yumush { | ||
| 243 | 246 | .detach(); |
| 244 | 247 | } |
| 245 | 248 | |
| 246 | - pub(super) fn set_theme(&mut self, theme: ThemeChoice, cx: &mut Context<Self>) { | |
| 249 | + pub(super) fn set_theme(&mut self, theme: Theme, cx: &mut Context<Self>) { | |
| 247 | 250 | self.settings.theme = theme; |
| 248 | 251 | settings::apply(theme, self.settings.font_size, cx); |
| 249 | 252 | self.commit_settings(cx); |
crates/client/src/gui/sidebar.rsmodified+1 -1
| @@ -524,7 +524,7 @@ impl Yumush { | ||
| 524 | 524 | } else { |
| 525 | 525 | Some(self.voice_chip(community_id, palette)) |
| 526 | 526 | }; |
| 527 | - let themed = palette.for_community(Some(community), &self.chat.hues); | |
| 527 | + let themed = palette; | |
| 528 | 528 | hoverable_with( |
| 529 | 529 | format!("{key}_{}", community.id), |
| 530 | 530 | entry( |
crates/client/src/gui/social.rsmodified+1 -1
| @@ -296,7 +296,7 @@ impl Yumush { | ||
| 296 | 296 | let dialog_input = input.clone(); |
| 297 | 297 | window.open_dialog(cx, move |dialog, _, cx| { |
| 298 | 298 | let yumush = entity.read(cx); |
| 299 | - let palette = yumush.themed(cx); | |
| 299 | + let palette = super::palette(cx); | |
| 300 | 300 | let result = invite_result(&yumush.chat.invite, community_id, &entity, yumush, palette); |
| 301 | 301 | |
| 302 | 302 | dialog.title("Invite").child( |
crates/client/src/gui/style.rsadded+220 -0
| @@ -0,0 +1,220 @@ | ||
| 1 | +use std::hash::{DefaultHasher, Hash, Hasher}; | |
| 2 | + | |
| 3 | +use common::model::{Hue, Id}; | |
| 4 | +use gpui_kit::{App, Global, Hsla, Rems, rems, rgb}; | |
| 5 | + | |
| 6 | +use crate::settings::FontSize; | |
| 7 | + | |
| 8 | +include!(concat!(env!("OUT_DIR"), "/tokens.rs")); | |
| 9 | + | |
| 10 | +impl Theme { | |
| 11 | + pub fn label(self) -> &'static str { | |
| 12 | + match self { | |
| 13 | + Theme::Gece => "Gece", | |
| 14 | + Theme::Gun => "Gün", | |
| 15 | + } | |
| 16 | + } | |
| 17 | +} | |
| 18 | + | |
| 19 | +pub struct Look { | |
| 20 | + pub theme: Theme, | |
| 21 | + pub size: FontSize, | |
| 22 | +} | |
| 23 | + | |
| 24 | +impl Global for Look {} | |
| 25 | + | |
| 26 | +#[derive(Clone, Copy)] | |
| 27 | +pub struct Tokens { | |
| 28 | + pub theme: Theme, | |
| 29 | + pub size: FontSize, | |
| 30 | +} | |
| 31 | + | |
| 32 | +impl Tokens { | |
| 33 | + pub fn of(cx: &App) -> Self { | |
| 34 | + cx.try_global::<Look>().map_or( | |
| 35 | + Tokens { | |
| 36 | + theme: Theme::Gece, | |
| 37 | + size: FontSize::Medium, | |
| 38 | + }, | |
| 39 | + |look| Tokens { | |
| 40 | + theme: look.theme, | |
| 41 | + size: look.size, | |
| 42 | + }, | |
| 43 | + ) | |
| 44 | + } | |
| 45 | + | |
| 46 | + fn colors(self) -> &'static Colors { | |
| 47 | + self.theme.colors() | |
| 48 | + } | |
| 49 | + | |
| 50 | + pub fn dark(self) -> bool { | |
| 51 | + self.colors().dark | |
| 52 | + } | |
| 53 | + | |
| 54 | + pub fn ground(self) -> Hsla { | |
| 55 | + color(self.colors().ground) | |
| 56 | + } | |
| 57 | + | |
| 58 | + pub fn raise(self) -> Hsla { | |
| 59 | + color(self.colors().raise) | |
| 60 | + } | |
| 61 | + | |
| 62 | + pub fn hov(self) -> Hsla { | |
| 63 | + color(self.colors().hov) | |
| 64 | + } | |
| 65 | + | |
| 66 | + pub fn press(self) -> Hsla { | |
| 67 | + color(self.colors().press) | |
| 68 | + } | |
| 69 | + | |
| 70 | + pub fn thread(self) -> Hsla { | |
| 71 | + color(self.colors().thread) | |
| 72 | + } | |
| 73 | + | |
| 74 | + pub fn off(self) -> Hsla { | |
| 75 | + color(self.colors().off) | |
| 76 | + } | |
| 77 | + | |
| 78 | + pub fn faint(self) -> Hsla { | |
| 79 | + color(self.colors().faint) | |
| 80 | + } | |
| 81 | + | |
| 82 | + pub fn dim(self) -> Hsla { | |
| 83 | + color(self.colors().dim) | |
| 84 | + } | |
| 85 | + | |
| 86 | + pub fn paper(self) -> Hsla { | |
| 87 | + color(self.colors().paper) | |
| 88 | + } | |
| 89 | + | |
| 90 | + pub fn bad(self) -> Hsla { | |
| 91 | + color(self.colors().bad) | |
| 92 | + } | |
| 93 | + | |
| 94 | + pub fn hue(self, hue: Hue) -> Hsla { | |
| 95 | + color(self.colors().hue[hue as usize]) | |
| 96 | + } | |
| 97 | + | |
| 98 | + pub fn person(self, id: Id) -> Hsla { | |
| 99 | + self.hue(hue_of(id)) | |
| 100 | + } | |
| 101 | + | |
| 102 | + pub fn text(self, size: f32) -> Rems { | |
| 103 | + rems(size / text::UI) | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | |
| 107 | +pub fn hue_of(id: Id) -> Hue { | |
| 108 | + let mut hasher = DefaultHasher::new(); | |
| 109 | + id.hash(&mut hasher); | |
| 110 | + let picks = &Hue::ALL[..Hue::ALL.len() - 1]; | |
| 111 | + picks[hasher.finish() as usize % picks.len()] | |
| 112 | +} | |
| 113 | + | |
| 114 | +fn color(value: u32) -> Hsla { | |
| 115 | + rgb(value).into() | |
| 116 | +} | |
| 117 | + | |
| 118 | +#[cfg(test)] | |
| 119 | +mod tests { | |
| 120 | + use super::*; | |
| 121 | + | |
| 122 | + #[test] | |
| 123 | + fn hues_match_tokens() { | |
| 124 | + let names: Vec<&str> = Hue::ALL.iter().map(|hue| hue.as_str()).collect(); | |
| 125 | + assert_eq!(names, HUE_NAMES); | |
| 126 | + } | |
| 127 | + | |
| 128 | + const UNMIGRATED: [&str; 37] = [ | |
| 129 | + "gui.rs", | |
| 130 | + "gui/auth.rs", | |
| 131 | + "gui/builder.rs", | |
| 132 | + "gui/builder/access.rs", | |
| 133 | + "gui/builder/backups.rs", | |
| 134 | + "gui/builder/communities.rs", | |
| 135 | + "gui/builder/log.rs", | |
| 136 | + "gui/builder/messages.rs", | |
| 137 | + "gui/builder/overview.rs", | |
| 138 | + "gui/builder/reports.rs", | |
| 139 | + "gui/builder/server.rs", | |
| 140 | + "gui/builder/storage.rs", | |
| 141 | + "gui/builder/ui.rs", | |
| 142 | + "gui/builder/users.rs", | |
| 143 | + "gui/builder/voice.rs", | |
| 144 | + "gui/camera_view.rs", | |
| 145 | + "gui/chat.rs", | |
| 146 | + "gui/community_settings.rs", | |
| 147 | + "gui/composer.rs", | |
| 148 | + "gui/dock.rs", | |
| 149 | + "gui/forward.rs", | |
| 150 | + "gui/media_view.rs", | |
| 151 | + "gui/message_actions.rs", | |
| 152 | + "gui/poll.rs", | |
| 153 | + "gui/profile.rs", | |
| 154 | + "gui/settings_page.rs", | |
| 155 | + "gui/share_view.rs", | |
| 156 | + "gui/sidebar.rs", | |
| 157 | + "gui/snippet.rs", | |
| 158 | + "gui/social.rs", | |
| 159 | + "gui/stream_stats.rs", | |
| 160 | + "gui/surface.rs", | |
| 161 | + "gui/voice_note.rs", | |
| 162 | + "gui/voice_settings.rs", | |
| 163 | + "gui/voice_stats.rs", | |
| 164 | + "gui/wave.rs", | |
| 165 | + "gui/widget.rs", | |
| 166 | + ]; | |
| 167 | + const FREE: [&str; 2] = ["gui/style.rs", "gui/parts.rs"]; | |
| 168 | + | |
| 169 | + fn sources(dir: &std::path::Path, out: &mut Vec<std::path::PathBuf>) { | |
| 170 | + for entry in std::fs::read_dir(dir).expect("read gui dir") { | |
| 171 | + let path = entry.expect("entry").path(); | |
| 172 | + if path.is_dir() { | |
| 173 | + sources(&path, out); | |
| 174 | + } else if path.extension().is_some_and(|ext| ext == "rs") { | |
| 175 | + out.push(path); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + fn raw(line: &str) -> Option<&'static str> { | |
| 181 | + let literal = |pattern: &str| { | |
| 182 | + line.match_indices(pattern).any(|(at, _)| { | |
| 183 | + line[at + pattern.len()..] | |
| 184 | + .chars() | |
| 185 | + .next() | |
| 186 | + .is_some_and(|next| next.is_ascii_digit()) | |
| 187 | + }) | |
| 188 | + }; | |
| 189 | + [ | |
| 190 | + ("px(", literal("px(")), | |
| 191 | + ("text(", literal(" text(") || literal("(text(")), | |
| 192 | + ("hsla(", line.contains("hsla(")), | |
| 193 | + ("rgb(", line.contains("rgb(")), | |
| 194 | + (".opacity(", line.contains(".opacity(")), | |
| 195 | + ] | |
| 196 | + .into_iter() | |
| 197 | + .find_map(|(name, hit)| hit.then_some(name)) | |
| 198 | + } | |
| 199 | + | |
| 200 | + #[test] | |
| 201 | + fn migrated_files_use_tokens() { | |
| 202 | + let src = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src"); | |
| 203 | + let mut files = vec![src.join("gui.rs")]; | |
| 204 | + sources(&src.join("gui"), &mut files); | |
| 205 | + let mut found = Vec::new(); | |
| 206 | + for file in files { | |
| 207 | + let name = file.strip_prefix(&src).expect("under src").to_string_lossy().replace('\\', "/"); | |
| 208 | + if FREE.contains(&name.as_str()) || UNMIGRATED.contains(&name.as_str()) { | |
| 209 | + continue; | |
| 210 | + } | |
| 211 | + let content = std::fs::read_to_string(&file).expect("read source"); | |
| 212 | + for (number, line) in content.lines().enumerate() { | |
| 213 | + if let Some(pattern) = raw(line) { | |
| 214 | + found.push(format!("{name}:{}: raw {pattern}", number + 1)); | |
| 215 | + } | |
| 216 | + } | |
| 217 | + } | |
| 218 | + assert!(found.is_empty(), "raw values outside tokens:\n{}", found.join("\n")); | |
| 219 | + } | |
| 220 | +} |
crates/client/src/main.rsmodified+44 -1
| @@ -2,7 +2,10 @@ | ||
| 2 | 2 | |
| 3 | 3 | use client::{ |
| 4 | 4 | ClientConfig, NAME, |
| 5 | - gui::{self, Yumush}, | |
| 5 | + gui::{ | |
| 6 | + self, Yumush, | |
| 7 | + gallery::{Gallery, State}, | |
| 8 | + }, | |
| 6 | 9 | net, settings, |
| 7 | 10 | tray::{self, TrayAction, TrayState}, |
| 8 | 11 | }; |
| @@ -32,6 +35,11 @@ fn main() { | ||
| 32 | 35 | ) |
| 33 | 36 | .init(); |
| 34 | 37 | |
| 38 | + if let Ok(spec) = std::env::var("YUMUSH_GALLERY") { | |
| 39 | + gallery(spec); | |
| 40 | + return; | |
| 41 | + } | |
| 42 | + | |
| 35 | 43 | let settings = settings::load(); |
| 36 | 44 | let (network_handle, network_event_receiver) = net::start(ClientConfig::default()); |
| 37 | 45 | let (mut tray_receiver, tray_handle) = tray::start(); |
| @@ -78,6 +86,41 @@ fn main() { | ||
| 78 | 86 | }); |
| 79 | 87 | } |
| 80 | 88 | |
| 89 | +fn gallery(spec: String) { | |
| 90 | + let (page, state) = spec.split_once(':').unwrap_or((&spec, "base")); | |
| 91 | + let page = page.to_string(); | |
| 92 | + let Some(state) = State::parse(state) else { | |
| 93 | + eprintln!("unknown gallery state {state}"); | |
| 94 | + return; | |
| 95 | + }; | |
| 96 | + application() | |
| 97 | + .with_assets(AllAssets) | |
| 98 | + .run(move |cx: &mut App| { | |
| 99 | + gui::init(cx); | |
| 100 | + settings::apply(state.theme(), state.font_size(), cx); | |
| 101 | + let (width, height) = state.window(); | |
| 102 | + let bounds = Bounds::centered(None, size(px(width), px(height)), cx); | |
| 103 | + let opened = cx.open_window( | |
| 104 | + WindowOptions { | |
| 105 | + window_bounds: Some(WindowBounds::Windowed(bounds)), | |
| 106 | + titlebar: Some(TitlebarOptions { | |
| 107 | + title: Some(format!("{NAME} gallery").into()), | |
| 108 | + ..Default::default() | |
| 109 | + }), | |
| 110 | + ..Default::default() | |
| 111 | + }, | |
| 112 | + |window, cx| { | |
| 113 | + let view = cx.new(|_| Gallery::new(page, state)); | |
| 114 | + cx.new(|cx| Root::new(view, window, cx)) | |
| 115 | + }, | |
| 116 | + ); | |
| 117 | + if opened.is_err() { | |
| 118 | + cx.quit(); | |
| 119 | + } | |
| 120 | + cx.activate(true); | |
| 121 | + }); | |
| 122 | +} | |
| 123 | + | |
| 81 | 124 | fn show(view: Entity<Yumush>, cx: &mut App) { |
| 82 | 125 | match view.read(cx).window() { |
| 83 | 126 | Some(handle) => { |
crates/client/src/settings.rsmodified+14 -37
| @@ -8,11 +8,12 @@ use common::{ | ||
| 8 | 8 | }; |
| 9 | 9 | use gpui_kit::{ |
| 10 | 10 | App, Global, Pixels, |
| 11 | - component::{Theme, ThemeMode}, | |
| 11 | + component::{Theme as KitTheme, ThemeMode}, | |
| 12 | 12 | px, |
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | 15 | use crate::{ |
| 16 | + gui::style::{Look, Theme}, | |
| 16 | 17 | read_config, |
| 17 | 18 | share::{audio::AudioMode, encode::capabilities}, |
| 18 | 19 | voice::audio::Choice, |
| @@ -32,20 +33,6 @@ pub const SHARE_QUALITY: Quality = Quality { | ||
| 32 | 33 | pub const SENSITIVITY_DB: RangeInclusive<f32> = -80.0..=0.0; |
| 33 | 34 | pub const VOLUME: RangeInclusive<f32> = 0.0..=200.0; |
| 34 | 35 | |
| 35 | -string_enum! { | |
| 36 | - #[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| 37 | - ThemeChoice { | |
| 38 | - System => "system", | |
| 39 | - Light => "light", | |
| 40 | - Dark => "dark", | |
| 41 | - Black => "black", | |
| 42 | - } | |
| 43 | -} | |
| 44 | - | |
| 45 | -pub struct Look(pub ThemeChoice); | |
| 46 | - | |
| 47 | -impl Global for Look {} | |
| 48 | - | |
| 49 | 36 | string_enum! { |
| 50 | 37 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 51 | 38 | FontSize { |
| @@ -77,17 +64,6 @@ impl FontSize { | ||
| 77 | 64 | } |
| 78 | 65 | } |
| 79 | 66 | |
| 80 | -impl ThemeChoice { | |
| 81 | - pub fn label(self) -> &'static str { | |
| 82 | - match self { | |
| 83 | - ThemeChoice::System => "System", | |
| 84 | - ThemeChoice::Light => "Light", | |
| 85 | - ThemeChoice::Dark => "Dark", | |
| 86 | - ThemeChoice::Black => "Black", | |
| 87 | - } | |
| 88 | - } | |
| 89 | -} | |
| 90 | - | |
| 91 | 67 | string_enum! { |
| 92 | 68 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 93 | 69 | Activation { |
| @@ -209,7 +185,7 @@ impl ShareSettings { | ||
| 209 | 185 | |
| 210 | 186 | #[derive(Debug, Clone, PartialEq)] |
| 211 | 187 | pub struct Settings { |
| 212 | - pub theme: ThemeChoice, | |
| 188 | + pub theme: Theme, | |
| 213 | 189 | pub font_size: FontSize, |
| 214 | 190 | pub voice: VoiceSettings, |
| 215 | 191 | pub share: ShareSettings, |
| @@ -219,7 +195,7 @@ pub struct Settings { | ||
| 219 | 195 | impl Default for Settings { |
| 220 | 196 | fn default() -> Self { |
| 221 | 197 | Self { |
| 222 | - theme: ThemeChoice::Dark, | |
| 198 | + theme: Theme::Gece, | |
| 223 | 199 | font_size: FontSize::Medium, |
| 224 | 200 | voice: VoiceSettings::default(), |
| 225 | 201 | share: ShareSettings::default(), |
| @@ -322,7 +298,7 @@ pub fn load() -> Settings { | ||
| 322 | 298 | |
| 323 | 299 | Settings { |
| 324 | 300 | theme: text("theme") |
| 325 | - .and_then(|value| ThemeChoice::parse(&value)) | |
| 301 | + .and_then(|value| Theme::parse(&value)) | |
| 326 | 302 | .unwrap_or(defaults.theme), |
| 327 | 303 | font_size: text("font_size") |
| 328 | 304 | .and_then(|value| FontSize::parse(&value)) |
| @@ -402,13 +378,14 @@ pub fn save(settings: &Settings) { | ||
| 402 | 378 | write_config("settings", &content); |
| 403 | 379 | } |
| 404 | 380 | |
| 405 | -pub fn apply(choice: ThemeChoice, font_size: FontSize, cx: &mut App) { | |
| 406 | - cx.set_global(Look(choice)); | |
| 407 | - cx.set_global(Scale(font_size)); | |
| 408 | - match choice { | |
| 409 | - ThemeChoice::System => Theme::sync_system_appearance(None, cx), | |
| 410 | - ThemeChoice::Light => Theme::change(ThemeMode::Light, None, cx), | |
| 411 | - ThemeChoice::Dark | ThemeChoice::Black => Theme::change(ThemeMode::Dark, None, cx), | |
| 412 | - } | |
| 381 | +pub fn apply(theme: Theme, size: FontSize, cx: &mut App) { | |
| 382 | + cx.set_global(Look { theme, size }); | |
| 383 | + cx.set_global(Scale(size)); | |
| 384 | + let mode = if theme.colors().dark { | |
| 385 | + ThemeMode::Dark | |
| 386 | + } else { | |
| 387 | + ThemeMode::Light | |
| 388 | + }; | |
| 389 | + KitTheme::change(mode, None, cx); | |
| 413 | 390 | crate::gui::sync_theme(cx); |
| 414 | 391 | } |
crates/common/src/model.rsmodified+16 -0
| @@ -46,6 +46,22 @@ macro_rules! string_enum { | ||
| 46 | 46 | }; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | +string_enum! { | |
| 50 | + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)] | |
| 51 | + Hue { | |
| 52 | + Amber => "amber", | |
| 53 | + Sky => "sky", | |
| 54 | + Violet => "violet", | |
| 55 | + Mint => "mint", | |
| 56 | + Rose => "rose", | |
| 57 | + Gold => "gold", | |
| 58 | + Coral => "coral", | |
| 59 | + Teal => "teal", | |
| 60 | + Lilac => "lilac", | |
| 61 | + Paper => "paper", | |
| 62 | + } | |
| 63 | +} | |
| 64 | + | |
| 49 | 65 | string_enum! { |
| 50 | 66 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)] |
| 51 | 67 | Role { |
harness/compare.shadded+14 -0
| @@ -0,0 +1,14 @@ | ||
| 1 | +#!/usr/bin/env bash | |
| 2 | +set -euo pipefail | |
| 3 | +STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" | |
| 4 | +page="$1" | |
| 5 | +state="$2" | |
| 6 | +artifact="$3" | |
| 7 | +out="$STATE/shots/gallery" | |
| 8 | +size=1120,720 | |
| 9 | +[ "$state" = narrow ] && size=800,600 | |
| 10 | +profile="$(mktemp -d -p "$STATE")" | |
| 11 | +firefox --headless --profile "$profile" --window-size "$size" --screenshot "$out/$page-$state-artifact.png" "file://$artifact#$state" >/dev/null 2>&1 | |
| 12 | +rm -rf "$profile" | |
| 13 | +magick montage "$out/$page-$state-artifact.png" "$out/$page-$state.png" -tile 2x1 -geometry +8+8 -background '#808080' "$out/$page-$state-compare.png" | |
| 14 | +echo "$out/$page-$state-compare.png" |
harness/gallery.shadded+25 -0
| @@ -0,0 +1,25 @@ | ||
| 1 | +#!/usr/bin/env bash | |
| 2 | +set -euo pipefail | |
| 3 | +HERE="$(cd "$(dirname "$0")" && pwd)" | |
| 4 | +ROOT="$(dirname "$HERE")" | |
| 5 | +STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" | |
| 6 | +source "${ENV_FILE:-$STATE/env}" | |
| 7 | +page="$1" | |
| 8 | +shift | |
| 9 | +states=("$@") | |
| 10 | +[ ${#states[@]} -eq 0 ] && states=(base long empty many gun large narrow bad) | |
| 11 | +out="$STATE/shots/gallery" | |
| 12 | +mkdir -p "$out" | |
| 13 | +for state in "${states[@]}"; do | |
| 14 | + size=1120x720 | |
| 15 | + [ "$state" = narrow ] && size=800x600 | |
| 16 | + YUMUSH_GALLERY="$page:$state" "$ROOT/target/${PROFILE:-harness}/client" >"$STATE/gallery.log" 2>&1 & | |
| 17 | + pid=$! | |
| 18 | + sleep "${GALLERY_WAIT:-2}" | |
| 19 | + grim "$out/full.png" | |
| 20 | + kill "$pid" | |
| 21 | + wait "$pid" 2>/dev/null || true | |
| 22 | + magick "$out/full.png" -gravity center -crop "$size+0+0" +repage "$out/$page-$state.png" | |
| 23 | + echo "$out/$page-$state.png" | |
| 24 | +done | |
| 25 | +rm -f "$out/full.png" |
harness/niri.kdlmodified+4 -0
| @@ -21,3 +21,7 @@ gestures { | ||
| 21 | 21 | input { |
| 22 | 22 | focus-follows-mouse |
| 23 | 23 | } |
| 24 | +window-rule { | |
| 25 | + match title="gallery$" | |
| 26 | + open-floating true | |
| 27 | +} |