BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-base / src / theme / kvt.rs

kvt.rs

kvt.rs 10.8 KiB Download Raw
1//! Colour scheme "Koninklijke van Twist" (KVT house style). Kept in its own file so the
2//! upstream scheme file stays untouched apart from the list of schemes.
3//!
4//! Source: Huisstijlhandboek KVT (versie september 2020) and `kleuren-kvt.pdf`, KVT Intranet >
5//! Marketing > Huisstijlhandboek. The brand colours are the official ones:
6//!
7//! | Name | HEX | RGB | CMYK | PMS |
8//! |---------------|---------|-------------|-----------------|----------------|
9//! | Perkins blauw | #00529B | 0 82 155 | 100 69 0 11 | 287 C |
10//! | Helder blauw | #0099CC | 0 153 204 | 100 13 1 3 | Process Blue C |
11//! | Lichtblauw | #33CCFF | 51 204 255 | 57 0 7 0 | 305 C |
12//! | Donkergrijs | #575757 | 86 86 86 | 0 0 0 80 | Cool gray 11 |
13//!
14//! `NAVY` (#00101F) is the title and body text colour of the KVT presentation template 2026.1.
15//! Every other value is a mix of those colours with white or `NAVY` (surfaces, borders, hover
16//! states) or a status colour copied from the other schemes.
17//!
18//! The house style asks for the logo on a white background, so the light shade is the primary
19//! look and the one new installations start in. Perkins blauw is the accent in both shades:
20//! buttons, focus rings, tab indicators, badges, selection and other fills. On a dark ground
21//! Perkins is too dark for text (and Helder blauw / Lichtblauw are too light for text on white,
22//! about 3.1 and 1.8 to 1), so links and icons on dark surfaces use a light tint of Lichtblauw,
23//! and those two blues otherwise appear as tints.
24//!
25//! Font: the house style names DINPro (promotion) and Arial (letters). The app keeps its own
26//! font: DINPro cannot be redistributed and the font is not part of a colour scheme.
27//!
28//! Who gets it: a new install, and anyone without saved appearance settings, starts in this
29//! scheme in its light shade (`appearance::AppearanceSettings::default`). A saved choice is kept,
30//! also when it is Rusty Teams or Teams. Settings saved without a scheme or theme key (oldest
31//! versions) keep Rusty Teams and dark.
32
33use super::schemes::{ColorScheme, DARK_BASE, LIGHT_BASE, Palette};
34
35/// Family names under which DINPro is commonly installed. The font is not shipped
36/// with the app (licence); we only use it when the OS already has it.
37pub const FONT_CANDIDATES: &[&str] = &["DINPro", "DIN Pro", "DINPro-Regular", "DIN Pro Regular"];
38
39/// First installed family that matches [`FONT_CANDIDATES`], case-insensitive.
40/// `None` means the caller should keep the bundled default.
41pub fn system_font_family<S: AsRef<str>>(installed: &[S]) -> Option<&'static str> {
42 FONT_CANDIDATES.iter().copied().find(|candidate| {
43 installed
44 .iter()
45 .any(|name| name.as_ref().eq_ignore_ascii_case(candidate))
46 })
47}
48
49const AVATAR_PALETTE: [u32; 6] = [0x00529b, 0x00698f, 0x575757, 0x2c5479, 0x004e6d, 0x00315d];
50
51pub const KVT: ColorScheme = ColorScheme {
52 id: "koninklijke-van-twist",
53 name: "Koninklijke van Twist",
54 dark: Palette {
55 background: 0x00101f,
56 surface: 0x061a2e,
57 surface_raised: 0x12304f,
58 row_hover: 0x0e2744,
59 popup: 0x183a5e,
60 popup_hover: 0x204670,
61 popup_nested: 0x214a76,
62 popup_nested_hover: 0x2a5886,
63 reply_surface: 0x0a2038,
64 border: 0x0f2a47,
65 border_strong: 0x24476b,
66 foreground: 0xf2f8fc,
67 text_strong: 0xe3eef7,
68 text_soft: 0xcfdeeb,
69 text_muted: 0xa3b8cb,
70 text_faint: 0x8fa6bb,
71 accent: 0x00529b,
72 accent_text: 0x66d9ff,
73 accent_soft: 0x99e6ff,
74 accent_strong: 0x003b70,
75 on_accent: 0xffffff,
76 bubble_own: 0x00396b,
77 bubble_other: 0x12304f,
78 reaction_on_own: 0x00529b,
79 mention_background: 0x0a3a66,
80 mention_background_own: 0x00529b,
81 own_meta: 0xbfe4f7,
82 own_read: 0x66d9ff,
83 drop_background: 0x00529b14,
84 selection: 0x00529b66,
85 rule_own: 0x00529b,
86 badge_muted: 0x24476b,
87 toast_mention: 0x082f52,
88 green: 0x22c55e,
89 red: 0xef4444,
90 red_soft: 0xf87171,
91 red_tint: 0xfca5a5,
92 amber: 0xfbbf24,
93 close_button_hover: 0xc42b1c,
94 close_button_pressed: 0xb5271a,
95 avatar_palette: AVATAR_PALETTE,
96 ..DARK_BASE
97 },
98 light: Palette {
99 background: 0xe6eef5,
100 surface: 0xf5f8fb,
101 surface_raised: 0xffffff,
102 row_hover: 0xedf3f8,
103 popup: 0xffffff,
104 popup_hover: 0xf0f5f9,
105 popup_nested: 0xffffff,
106 popup_nested_hover: 0xe8eff6,
107 reply_surface: 0xfafcfd,
108 border: 0xd1e0ed,
109 border_strong: 0xadc8df,
110 foreground: 0x00101f,
111 text_strong: 0x00101f,
112 text_soft: 0x2c343b,
113 text_muted: 0x575757,
114 text_faint: 0x626262,
115 accent: 0x00529b,
116 accent_text: 0x004888,
117 accent_soft: 0x003463,
118 accent_strong: 0x003b70,
119 on_accent: 0xffffff,
120 bubble_own: 0xd1e0ed,
121 bubble_other: 0xffffff,
122 reaction_on_own: 0xd1e0ed,
123 mention_background: 0xd6e3ef,
124 mention_background_own: 0xd1e0ed,
125 own_meta: 0x004582,
126 own_read: 0x00529b,
127 drop_background: 0x00529b14,
128 selection: 0x00529b59,
129 rule_own: 0xa6c2dc,
130 badge_muted: 0xadc8df,
131 toast_mention: 0xd6e3ef,
132 green: 0x16a34a,
133 red: 0xc81e1e,
134 red_soft: 0xb91c1c,
135 red_tint: 0x991b1b,
136 amber: 0xc27c0e,
137 close_button_hover: 0xc42b1c,
138 close_button_pressed: 0xb5271a,
139 avatar_palette: AVATAR_PALETTE,
140 ..LIGHT_BASE
141 },
142};
143
144#[cfg(test)]
145mod tests {
146 use super::super::Shade;
147 use super::*;
148
149 fn channel(hex: u32, shift: u32) -> f64 {
150 let value = f64::from((hex >> shift) & 0xff) / 255.;
151 if value <= 0.04045 {
152 value / 12.92
153 } else {
154 ((value + 0.055) / 1.055).powf(2.4)
155 }
156 }
157
158 fn luminance(hex: u32) -> f64 {
159 0.2126 * channel(hex, 16) + 0.7152 * channel(hex, 8) + 0.0722 * channel(hex, 0)
160 }
161
162 fn contrast(first: u32, second: u32) -> f64 {
163 let (first, second) = (luminance(first), luminance(second));
164 (first.max(second) + 0.05) / (first.min(second) + 0.05)
165 }
166
167 #[test]
168 fn the_scheme_uses_the_official_kvt_blues() {
169 assert_eq!(KVT.light.accent, 0x00529b, "Perkins blauw");
170 assert_eq!(KVT.dark.accent, 0x00529b, "Perkins blauw on fills");
171 assert_eq!(KVT.dark.on_accent, 0xffffff);
172 assert_eq!(KVT.dark.accent_text, 0x66d9ff, "readable on dark grounds");
173 assert_eq!(KVT.dark.accent_strong, 0x003b70);
174 assert_eq!(KVT.light.selection, 0x00529b59);
175 assert_eq!(KVT.dark.selection, 0x00529b66);
176 assert_eq!(KVT.light.text_muted, 0x575757, "Donkergrijs");
177 assert_eq!(KVT.light.foreground, 0x00101f);
178 assert_eq!(KVT.light.shade, Shade::Light);
179 assert_eq!(KVT.dark.shade, Shade::Dark);
180 }
181
182 /// WCAG AA asks 4.5 to 1 for normal text. The shared test in `schemes.rs` is looser for
183 /// muted and faint text; this scheme meets AA for every text role on every ground.
184 #[test]
185 fn every_text_role_meets_wcag_aa_on_every_ground() {
186 for palette in [&KVT.dark, &KVT.light] {
187 let grounds = [
188 palette.background,
189 palette.surface,
190 palette.reply_surface,
191 palette.row_hover,
192 palette.surface_raised,
193 palette.popup,
194 palette.bubble_other,
195 palette.bubble_own,
196 ];
197 let roles = [
198 ("foreground", palette.foreground),
199 ("text_soft", palette.text_soft),
200 ("text_muted", palette.text_muted),
201 ("text_faint", palette.text_faint),
202 ("accent_text", palette.accent_text),
203 ];
204 for (name, text) in roles {
205 for ground in grounds {
206 let ratio = contrast(text, ground);
207 assert!(
208 ratio >= 4.5,
209 "{:?}: {name} #{text:06x} on #{ground:06x} is {ratio:.2}",
210 palette.shade
211 );
212 }
213 }
214 for (name, text, ground) in [
215 ("on_accent", palette.on_accent, palette.accent),
216 ("own_meta", palette.own_meta, palette.bubble_own),
217 (
218 "foreground on mention",
219 palette.foreground,
220 palette.mention_background,
221 ),
222 (
223 "accent_text on mention",
224 palette.accent_text,
225 palette.mention_background,
226 ),
227 (
228 "foreground on own mention",
229 palette.foreground,
230 palette.mention_background_own,
231 ),
232 (
233 "foreground on own reaction",
234 palette.foreground,
235 palette.reaction_on_own,
236 ),
237 (
238 "foreground on popup hover",
239 palette.foreground,
240 palette.popup_hover,
241 ),
242 (
243 "text_muted on popup hover",
244 palette.text_muted,
245 palette.popup_hover,
246 ),
247 (
248 "foreground on toast mention",
249 palette.foreground,
250 palette.toast_mention,
251 ),
252 ] {
253 let ratio = contrast(text, ground);
254 assert!(
255 ratio >= 4.5,
256 "{:?}: {name} #{text:06x} on #{ground:06x} is {ratio:.2}",
257 palette.shade
258 );
259 }
260 for avatar in palette.avatar_palette {
261 assert!(contrast(0xffffff, avatar) >= 4.5, "avatar #{avatar:06x}");
262 }
263 }
264 }
265
266 #[test]
267 fn dinpro_is_picked_when_installed_and_ignored_otherwise() {
268 assert_eq!(system_font_family(&[] as &[&str]), None);
269 assert_eq!(system_font_family(&["Google Sans Flex", "Arial"]), None);
270 assert_eq!(system_font_family(&["DINPro"]), Some("DINPro"));
271 assert_eq!(system_font_family(&["dinpro"]), Some("DINPro"));
272 assert_eq!(system_font_family(&["DIN Pro"]), Some("DIN Pro"));
273 assert_eq!(
274 system_font_family(&["DIN Pro Regular"]),
275 Some("DIN Pro Regular")
276 );
277 assert_eq!(
278 system_font_family(&["DINPro-Regular"]),
279 Some("DINPro-Regular")
280 );
281 // Prefer the first candidate when several are present.
282 assert_eq!(
283 system_font_family(&["DIN Pro Regular", "DIN Pro", "DINPro"]),
284 Some("DINPro")
285 );
286 }
287}