1use gpui::Hsla;
11use herogpui_core::{mix_oklab, oklch, soft_mix, with_alpha};
12
13pub fn white() -> Hsla {
19 oklch(1.0, 0.0, 0.0)
20}
21pub fn black() -> Hsla {
23 oklch(0.0, 0.0, 0.0)
24}
25pub fn snow() -> Hsla {
27 oklch(0.9911, 0.0, 0.0)
28}
29pub fn eclipse() -> Hsla {
31 oklch(0.2103, 0.0059, 285.89)
32}
33
34#[derive(Clone, Copy, Debug)]
36pub enum SoftForeground {
37 RoleForeground,
39 Mix { color: f32, foreground: f32 },
42}
43
44#[derive(Clone, Copy, Debug)]
49pub struct RoleColor {
50 pub color: Hsla,
52 pub foreground: Hsla,
54 pub hover_mix: f32,
57 hover_override: Option<Hsla>,
65 soft_mix: f32,
67 soft_hover_mix: f32,
69 soft_foreground: SoftForeground,
71 vibrant_palette: bool,
77}
78
79impl RoleColor {
80 pub fn new(color: Hsla, foreground: Hsla) -> Self {
81 Self {
82 color,
83 foreground,
84 hover_mix: 0.10,
85 hover_override: None,
86 soft_mix: 0.15,
87 soft_hover_mix: 0.20,
88 soft_foreground: SoftForeground::Mix {
89 color: 70.0,
90 foreground: 30.0,
91 },
92 vibrant_palette: false,
93 }
94 }
95
96 pub fn with_hover_mix(mut self, hover_mix: f32) -> Self {
100 self.hover_mix = hover_mix;
101 self
102 }
103
104 pub fn with_hover(mut self, hover: Hsla) -> Self {
117 self.hover_override = Some(hover);
118 self
119 }
120
121 pub fn hover_override(&self) -> Option<Hsla> {
123 self.hover_override
124 }
125
126 pub fn with_soft_mix(mut self, soft: f32, soft_hover: f32) -> Self {
130 self.soft_mix = soft;
131 self.soft_hover_mix = soft_hover;
132 self
133 }
134
135 pub fn with_soft_foreground_mix(mut self, color: f32, foreground: f32) -> Self {
137 self.soft_foreground = SoftForeground::Mix { color, foreground };
138 self
139 }
140
141 pub fn with_vibrant_palette(mut self, vibrant: bool) -> Self {
145 self.vibrant_palette = vibrant;
146 self
147 }
148
149 pub fn is_vibrant_palette(&self) -> bool {
151 self.vibrant_palette
152 }
153
154 pub fn with_soft_foreground_role(mut self) -> Self {
156 self.soft_foreground = SoftForeground::RoleForeground;
157 self
158 }
159
160 pub fn hover(&self) -> Hsla {
164 self.hover_override
165 .unwrap_or_else(|| mix_oklab(self.color, self.foreground, self.hover_mix))
166 }
167
168 pub fn soft(&self) -> Hsla {
170 soft_mix(self.color, self.soft_mix)
171 }
172
173 pub fn soft_hover(&self) -> Hsla {
175 soft_mix(self.color, self.soft_hover_mix)
176 }
177
178 pub fn soft_foreground(&self, page_foreground: Hsla) -> Hsla {
184 match self.soft_foreground {
185 SoftForeground::RoleForeground => self.foreground,
186 SoftForeground::Mix { .. } if self.vibrant_palette => {
189 mix_oklab(self.color, page_foreground, 8.0 / 100.0)
190 }
191 SoftForeground::Mix { color, foreground } => {
192 mix_oklab(
196 self.color,
197 page_foreground,
198 foreground / (color + foreground),
199 )
200 }
201 }
202 }
203
204 pub fn with_alpha(&self, alpha: f32) -> Hsla {
205 with_alpha(self.color, alpha)
206 }
207}
208
209#[derive(Clone, Copy, Debug)]
211pub struct SurfaceColor {
212 pub background: Hsla,
213 pub foreground: Hsla,
214}
215
216impl SurfaceColor {
217 pub fn hover(&self) -> Hsla {
219 mix_oklab(self.background, self.foreground, 0.08)
220 }
221}
222
223#[derive(Clone, Copy, Debug)]
226pub struct FieldColors {
227 pub background: Hsla,
229 pub foreground: Hsla,
231 pub placeholder: Hsla,
233 pub border: Hsla,
235}
236
237impl FieldColors {
238 pub fn hover(&self) -> Hsla {
242 mix_oklab(self.background, self.foreground, 2.0 / 92.0)
243 }
244
245 pub fn focus(&self) -> Hsla {
247 self.background
248 }
249
250 pub fn border_hover(&self) -> Hsla {
256 mix_oklab(self.border, self.foreground, 10.0 / 98.0)
257 }
258
259 pub fn border_focus(&self) -> Hsla {
261 mix_oklab(self.border, self.foreground, 22.0 / 96.0)
262 }
263}
264
265#[derive(Clone, Debug)]
267pub struct ThemeColors {
268 pub background: Hsla,
271 pub foreground: Hsla,
273 pub muted: Hsla,
275 pub scrollbar: Hsla,
277
278 pub surface: SurfaceColor,
282 pub surface_secondary: Hsla,
284 pub surface_tertiary: Hsla,
286 pub overlay: SurfaceColor,
289 pub segment: SurfaceColor,
292
293 pub default: RoleColor,
296 pub accent: RoleColor,
298 pub success: RoleColor,
300 pub warning: RoleColor,
302 pub danger: RoleColor,
304
305 pub field: FieldColors,
307
308 pub border: Hsla,
311 pub separator: Hsla,
313 pub focus: Hsla,
315 pub link: Hsla,
317 pub backdrop: Hsla,
319}
320
321impl ThemeColors {
322 pub fn vibrant_palette(&self) -> bool {
327 self.accent.is_vibrant_palette()
328 }
329
330 pub fn set_vibrant_palette(&mut self, vibrant: bool) {
334 self.accent = self.accent.with_vibrant_palette(vibrant);
335 self.success = self.success.with_vibrant_palette(vibrant);
336 self.warning = self.warning.with_vibrant_palette(vibrant);
337 self.danger = self.danger.with_vibrant_palette(vibrant);
338 }
339
340 pub fn background_secondary(&self) -> Hsla {
344 mix_oklab(self.background, self.foreground, 0.04)
345 }
346
347 pub fn background_tertiary(&self) -> Hsla {
349 mix_oklab(self.background, self.foreground, 0.08)
350 }
351
352 pub fn background_inverse(&self) -> Hsla {
354 self.foreground
355 }
356
357 pub fn separator_secondary(&self) -> Hsla {
361 mix_oklab(self.surface.background, self.surface.foreground, 0.15)
362 }
363
364 pub fn separator_tertiary(&self) -> Hsla {
366 mix_oklab(self.surface.background, self.surface.foreground, 0.19)
367 }
368
369 pub fn border_secondary(&self) -> Hsla {
373 mix_oklab(self.surface.background, self.surface.foreground, 0.22)
374 }
375
376 pub fn border_tertiary(&self) -> Hsla {
378 mix_oklab(self.surface.background, self.surface.foreground, 0.34)
379 }
380
381 pub fn surface_secondary_foreground(&self) -> Hsla {
387 self.foreground
388 }
389
390 pub fn surface_tertiary_foreground(&self) -> Hsla {
392 self.foreground
393 }
394
395 pub fn role(&self, name: &str) -> &RoleColor {
397 match name {
398 "default" => &self.default,
399 "success" => &self.success,
400 "warning" => &self.warning,
401 "danger" => &self.danger,
402 _ => &self.accent,
403 }
404 }
405
406 pub fn light() -> Self {
409 let foreground = eclipse();
410 let muted = oklch(0.5517, 0.0138, 285.94);
411 let accent = RoleColor::new(oklch(0.6204, 0.195, 253.83), snow())
412 .with_soft_mix(0.15, 0.20)
413 .with_soft_foreground_mix(70.0, 30.0);
414 Self {
415 background: oklch(0.9702, 0.0, 0.0),
416 foreground,
417 muted,
418 scrollbar: with_alpha(foreground, 0.15),
419
420 surface: SurfaceColor {
421 background: white(),
422 foreground,
423 },
424 surface_secondary: oklch(0.9524, 0.0013, 286.37),
425 surface_tertiary: oklch(0.9373, 0.0013, 286.37),
426 overlay: SurfaceColor {
427 background: white(),
428 foreground,
429 },
430 segment: SurfaceColor {
431 background: white(),
432 foreground: eclipse(),
433 },
434
435 default: RoleColor::new(oklch(0.94, 0.001, 286.375), eclipse())
436 .with_hover_mix(0.04)
437 .with_soft_mix(0.50, 0.60)
438 .with_soft_foreground_role(),
439 accent,
440 success: RoleColor::new(oklch(0.7329, 0.1935, 150.81), eclipse())
441 .with_soft_foreground_mix(80.0, 60.0),
442 warning: RoleColor::new(oklch(0.7819, 0.1585, 72.33), eclipse())
443 .with_soft_foreground_mix(80.0, 70.0),
444 danger: RoleColor::new(oklch(0.6532, 0.2328, 25.74), snow())
445 .with_soft_foreground_mix(70.0, 40.0),
446
447 field: FieldColors {
448 background: white(),
449 foreground: oklch(0.2103, 0.0059, 285.89),
450 placeholder: muted,
451 border: with_alpha(black(), 0.0),
452 },
453
454 border: oklch(0.9, 0.004, 286.32),
457 separator: oklch(0.92, 0.004, 286.32),
458 focus: accent.color,
459 link: foreground,
460 backdrop: with_alpha(black(), 0.5),
461 }
462 }
463
464 pub fn dark() -> Self {
467 let foreground = snow();
468 let muted = oklch(0.705, 0.015, 286.067);
469 let accent = RoleColor::new(oklch(0.6204, 0.195, 253.83), snow())
470 .with_soft_mix(0.12, 0.16)
471 .with_soft_foreground_mix(80.0, 30.0);
472 let default = RoleColor::new(oklch(0.274, 0.006, 286.033), snow())
473 .with_hover_mix(0.04)
474 .with_soft_mix(0.50, 0.60)
475 .with_soft_foreground_role();
476 Self {
477 background: oklch(0.12, 0.005, 285.823),
478 foreground,
479 muted,
480 scrollbar: with_alpha(foreground, 0.15),
481
482 surface: SurfaceColor {
483 background: oklch(0.2103, 0.0059, 285.89),
484 foreground,
485 },
486 surface_secondary: oklch(0.257, 0.0037, 286.14),
487 surface_tertiary: oklch(0.2721, 0.0024, 247.91),
488 overlay: SurfaceColor {
493 background: oklch(0.2103, 0.0059, 285.89),
494 foreground,
495 },
496 segment: SurfaceColor {
497 background: oklch(0.3964, 0.01, 285.93),
498 foreground,
499 },
500
501 default,
502 accent,
503 success: RoleColor::new(oklch(0.7329, 0.1935, 150.81), eclipse())
506 .with_soft_mix(0.12, 0.16)
507 .with_soft_foreground_mix(80.0, 30.0),
508 warning: RoleColor::new(oklch(0.8203, 0.1388, 76.34), eclipse())
509 .with_soft_mix(0.12, 0.16)
510 .with_soft_foreground_mix(80.0, 30.0),
511 danger: RoleColor::new(oklch(0.594, 0.1967, 24.63), snow())
512 .with_soft_foreground_mix(80.0, 30.0),
513
514 field: FieldColors {
515 background: oklch(0.2103, 0.0059, 285.89),
518 foreground,
519 placeholder: muted,
520 border: with_alpha(black(), 0.0),
521 },
522
523 border: oklch(0.28, 0.006, 286.033),
526 separator: oklch(0.25, 0.006, 286.033),
527 focus: accent.color,
528 link: foreground,
529 backdrop: with_alpha(black(), 0.6),
530 }
531 }
532}
533
534#[cfg(test)]
535mod tests {
536 use super::*;
537
538 fn rgb8(c: Hsla) -> (u8, u8, u8) {
539 let r = gpui::Rgba::from(c);
540 (
541 (r.r * 255.0).round() as u8,
542 (r.g * 255.0).round() as u8,
543 (r.b * 255.0).round() as u8,
544 )
545 }
546
547 #[test]
548 fn an_explicit_role_hover_replaces_the_derived_mix() {
549 let stock = ThemeColors::light();
550 let derived = stock.accent.hover();
551 let named = gpui::hsla(0.6, 0.9, 0.3, 1.0);
554 let role = stock.accent.with_hover(named);
555 assert_ne!(rgb8(derived), rgb8(named), "the fixture must differ");
556 assert_eq!(rgb8(role.hover()), rgb8(named));
557 assert_eq!(role.hover_override(), Some(named));
558 assert_eq!(rgb8(role.soft()), rgb8(stock.accent.soft()));
561 assert_eq!(rgb8(role.soft_hover()), rgb8(stock.accent.soft_hover()));
562 assert_eq!(rgb8(role.color), rgb8(stock.accent.color));
563 }
564
565 #[test]
566 fn a_named_role_hover_outranks_the_hover_mix_whichever_order_they_are_set() {
567 let base = ThemeColors::light().accent;
568 let named = gpui::hsla(0.1, 0.8, 0.4, 1.0);
569 assert_eq!(
570 rgb8(base.with_hover(named).with_hover_mix(0.5).hover()),
571 rgb8(named)
572 );
573 assert_eq!(
574 rgb8(base.with_hover_mix(0.5).with_hover(named).hover()),
575 rgb8(named)
576 );
577 }
578
579 #[test]
580 fn accent_soft_is_fifteen_percent_accent() {
581 let c = ThemeColors::light();
582 assert!((c.accent.soft().a - 0.15).abs() < 1e-4);
583 assert!((c.accent.soft_hover().a - 0.20).abs() < 1e-4);
584 }
585
586 #[test]
587 fn light_scrollbar_thumb_is_fifteen_percent_foreground() {
588 let c = ThemeColors::light();
589 assert_eq!(c.scrollbar, with_alpha(c.foreground, 0.15));
590 }
591
592 #[test]
593 fn dark_scrollbar_thumb_is_fifteen_percent_foreground() {
594 let c = ThemeColors::dark();
595 assert_eq!(c.scrollbar, with_alpha(c.foreground, 0.15));
596 }
597
598 #[test]
599 fn the_soft_matrix_matches_the_pinned_stylesheet() {
600 let light = ThemeColors::light();
604 let dark = ThemeColors::dark();
605 for (colors, role_name, soft, soft_hover, foreground) in [
606 (&light, "default", 0.50, 0.60, None),
607 (&light, "accent", 0.15, 0.20, Some((70.0, 30.0))),
608 (&light, "success", 0.15, 0.20, Some((80.0, 60.0))),
609 (&light, "warning", 0.15, 0.20, Some((80.0, 70.0))),
610 (&light, "danger", 0.15, 0.20, Some((70.0, 40.0))),
611 (&dark, "default", 0.50, 0.60, None),
612 (&dark, "accent", 0.12, 0.16, Some((80.0, 30.0))),
613 (&dark, "success", 0.12, 0.16, Some((80.0, 30.0))),
614 (&dark, "warning", 0.12, 0.16, Some((80.0, 30.0))),
615 (&dark, "danger", 0.15, 0.20, Some((80.0, 30.0))),
616 ] {
617 let role = colors.role(role_name);
618 assert!(
619 (role.soft().a - soft).abs() < 1e-4,
620 "{role_name} soft alpha"
621 );
622 assert!(
623 (role.soft_hover().a - soft_hover).abs() < 1e-4,
624 "{role_name} soft-hover alpha"
625 );
626 match foreground {
627 Some((color, page)) => assert_eq!(
628 role.soft_foreground(colors.foreground),
629 mix_oklab(role.color, colors.foreground, page / (color + page)),
630 "{role_name} soft-foreground mix"
631 ),
632 None => assert_eq!(
633 role.soft_foreground(colors.foreground),
634 role.foreground,
635 "{role_name} soft-foreground follows the role"
636 ),
637 }
638 }
639 }
640
641 #[test]
646 fn every_token_resolves_to_the_stylesheets_own_pixels() {
647 type Pick = fn(&ThemeColors) -> Hsla;
648 type Row = (&'static str, Pick, (u8, u8, u8, f32), (u8, u8, u8, f32));
650 #[rustfmt::skip]
651 let table: &[Row] = &[
652 ("accent", |c| c.accent.color, (4, 133, 247, 1.00), (4, 133, 247, 1.00)),
653 ("accent_foreground", |c| c.accent.foreground, (252, 252, 252, 1.00), (252, 252, 252, 1.00)),
654 ("accent_hover", |c| c.accent.hover(), (53, 146, 249, 1.00), (53, 146, 249, 1.00)),
655 ("accent_soft", |c| c.accent.soft(), (4, 133, 247, 0.15), (4, 133, 247, 0.12)),
656 ("accent_soft_foreground", |c| c.accent.soft_foreground(c.foreground), (30, 99, 174, 1.00), (97, 168, 251, 1.00)),
657 ("backdrop", |c| c.backdrop, (0, 0, 0, 0.50), (0, 0, 0, 0.60)),
658 ("background", |c| c.background, (245, 245, 245, 1.00), (6, 6, 7, 1.00)),
659 ("background_inverse", |c| c.background_inverse(), (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
660 ("background_secondary", |c| c.background_secondary(), (235, 235, 235, 1.00), (12, 12, 14, 1.00)),
661 ("background_tertiary", |c| c.background_tertiary(), (225, 225, 225, 1.00), (19, 19, 22, 1.00)),
662 ("border", |c| c.border, (221, 222, 224, 1.00), (40, 40, 44, 1.00)),
663 ("border_secondary", |c| c.border_secondary(), (198, 198, 199, 1.00), (67, 67, 69, 1.00)),
664 ("border_tertiary", |c| c.border_tertiary(), (168, 168, 169, 1.00), (92, 92, 95, 1.00)),
665 ("danger", |c| c.danger.color, (255, 56, 60, 1.00), (219, 59, 62, 1.00)),
666 ("danger_foreground", |c| c.danger.foreground, (252, 252, 252, 1.00), (252, 252, 252, 1.00)),
667 ("danger_hover", |c| c.danger.hover(), (255, 85, 81, 1.00), (225, 84, 81, 1.00)),
668 ("danger_soft", |c| c.danger.soft(), (255, 56, 60, 0.15), (219, 59, 62, 0.15)),
669 ("danger_soft_foreground", |c| c.danger.soft_foreground(c.foreground), (164, 53, 51, 1.00), (235, 120, 114, 1.00)),
670 ("default", |c| c.default.color, (235, 235, 236, 1.00), (39, 39, 42, 1.00)),
671 ("default_foreground", |c| c.default.foreground, (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
672 ("default_hover", |c| c.default.hover(), (225, 225, 226, 1.00), (46, 46, 49, 1.00)),
673 ("default_soft", |c| c.default.soft(), (235, 235, 235, 0.50), (39, 39, 42, 0.50)),
674 ("default_soft_foreground", |c| c.default.soft_foreground(c.foreground), (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
675 ("field_background", |c| c.field.background, (255, 255, 255, 1.00), (24, 24, 27, 1.00)),
676 ("field_foreground", |c| c.field.foreground, (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
677 ("field_placeholder", |c| c.field.placeholder, (113, 113, 122, 1.00), (159, 159, 169, 1.00)),
678 ("focus", |c| c.focus, (4, 133, 247, 1.00), (4, 133, 247, 1.00)),
679 ("foreground", |c| c.foreground, (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
680 ("link", |c| c.link, (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
681 ("muted", |c| c.muted, (113, 113, 122, 1.00), (159, 159, 169, 1.00)),
682 ("overlay", |c| c.overlay.background, (255, 255, 255, 1.00), (24, 24, 27, 1.00)),
683 ("overlay_foreground", |c| c.overlay.foreground, (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
684 ("scrollbar", |c| c.scrollbar, (24, 24, 27, 0.15), (255, 255, 255, 0.15)),
685 ("segment", |c| c.segment.background, (255, 255, 255, 1.00), (70, 70, 76, 1.00)),
686 ("segment_foreground", |c| c.segment.foreground, (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
687 ("separator", |c| c.separator, (228, 228, 231, 1.00), (33, 33, 36, 1.00)),
688 ("separator_secondary", |c| c.separator_secondary(), (216, 216, 216, 1.00), (52, 52, 55, 1.00)),
689 ("separator_tertiary", |c| c.separator_tertiary(), (205, 205, 206, 1.00), (60, 60, 63, 1.00)),
690 ("success", |c| c.success.color, (23, 201, 100, 1.00), (23, 201, 100, 1.00)),
691 ("success_foreground", |c| c.success.foreground, (24, 24, 27, 1.00), (24, 24, 27, 1.00)),
692 ("success_hover", |c| c.success.hover(), (33, 181, 93, 1.00), (33, 181, 93, 1.00)),
693 ("success_soft", |c| c.success.soft(), (23, 201, 100, 0.15), (23, 201, 100, 0.12)),
694 ("success_soft_foreground", |c| c.success.soft_foreground(c.foreground), (43, 119, 69, 1.00), (116, 216, 143, 1.00)),
695 ("surface", |c| c.surface.background, (255, 255, 255, 1.00), (24, 24, 27, 1.00)),
696 ("surface_foreground", |c| c.surface.foreground, (24, 24, 27, 1.00), (252, 252, 252, 1.00)),
697 ("surface_hover", |c| c.surface.hover(), (234, 234, 234, 1.00), (39, 39, 42, 1.00)),
698 ("surface_secondary", |c| c.surface_secondary, (239, 239, 240, 1.00), (35, 35, 37, 1.00)),
699 ("surface_tertiary", |c| c.surface_tertiary, (234, 234, 235, 1.00), (38, 39, 40, 1.00)),
700 ("warning", |c| c.warning.color, (245, 165, 36, 1.00), (247, 183, 80, 1.00)),
701 ("warning_foreground", |c| c.warning.foreground, (24, 24, 27, 1.00), (24, 24, 27, 1.00)),
702 ("warning_hover", |c| c.warning.hover(), (220, 150, 42, 1.00), (222, 165, 76, 1.00)),
703 ("warning_soft", |c| c.warning.soft(), (245, 165, 36, 0.15), (247, 183, 80, 0.12)),
704 ("warning_soft_foreground", |c| c.warning.soft_foreground(c.foreground), (133, 95, 46, 1.00), (249, 203, 134, 1.00)),
705 ];
706 for (name, pick, light, dark) in table {
707 for (mode, c, want) in [
708 ("light", ThemeColors::light(), light),
709 ("dark", ThemeColors::dark(), dark),
710 ] {
711 let got = pick(&c);
712 let (r, g, b) = rgb8(got);
713 let slack = (2.0 / want.3).ceil() as i32;
716 let near = |a: u8, b: u8| (a as i32 - b as i32).abs() <= slack;
717 assert!(
718 near(r, want.0) && near(g, want.1) && near(b, want.2)
719 && (got.a - want.3).abs() < 0.011,
720 "{name} ({mode}) resolved to ({r}, {g}, {b}, {:.3}), upstream resolves ({}, {}, {}, {:.3})",
721 got.a, want.0, want.1, want.2, want.3
722 );
723 }
724 }
725 }
726
727 #[test]
728 fn soft_foreground_resolves_to_the_stylesheets_own_pixels() {
729 let c = ThemeColors::light();
733 for (role_name, expected) in [
734 ("accent", (30, 99, 174)),
735 ("success", (43, 119, 69)),
736 ("warning", (133, 95, 46)),
737 ("danger", (164, 53, 51)),
738 ] {
739 let got = rgb8(c.role(role_name).soft_foreground(c.foreground));
740 let near = |a: u8, b: u8| (a as i32 - b as i32).abs() <= 2;
741 assert!(
742 near(got.0, expected.0) && near(got.1, expected.1) && near(got.2, expected.2),
743 "{role_name} soft-foreground was {got:?}, expected {expected:?}"
744 );
745 }
746 }
747
748 #[test]
749 fn a_custom_foreground_stays_live_in_the_soft_foreground_mix() {
750 let base = ThemeColors::light();
751 let custom = ThemeColors {
752 foreground: oklch(0.30, 0.05, 120.0),
753 ..base
754 };
755 assert_eq!(
758 custom.accent.soft_foreground(custom.foreground),
759 mix_oklab(custom.accent.color, custom.foreground, 0.30)
760 );
761 assert_ne!(
762 custom.accent.soft_foreground(custom.foreground),
763 base.accent.soft_foreground(base.foreground)
764 );
765 assert_eq!(
768 custom.default.soft_foreground(custom.foreground),
769 custom.default.foreground
770 );
771 }
772
773 #[test]
774 fn the_derived_borders_step_away_from_the_surface() {
775 let c = ThemeColors::light();
776 let steps = [
780 c.separator_secondary(),
781 c.border_secondary(),
782 c.border_tertiary(),
783 ];
784 for pair in steps.windows(2) {
785 assert!(
786 pair[1].l < pair[0].l,
787 "each step is darker than the last on a light surface"
788 );
789 }
790 }
791
792 #[test]
793 fn a_secondary_surface_keeps_the_page_foreground() {
794 let c = ThemeColors::light();
795 assert_eq!(c.surface_secondary_foreground(), c.foreground);
796 assert_eq!(c.surface_tertiary_foreground(), c.foreground);
797 }
798
799 #[test]
800 fn a_field_border_mixes_toward_its_own_foreground() {
801 let c = ThemeColors::light();
802 let border = c.field.border;
805 assert_ne!(c.field.border_hover(), border);
806 assert_ne!(c.field.border_focus(), c.field.border_hover());
807 }
808
809 #[test]
810 fn field_focus_matches_field_background() {
811 let c = ThemeColors::light();
812 assert_eq!(c.field.focus(), c.field.background);
813 }
814
815 #[test]
816 #[ignore = "v3 gives dark mode one colour for both; the shadow separates them"]
817 fn dark_surface_is_darker_than_overlay() {
818 let c = ThemeColors::dark();
819 assert!(c.surface.background.l < c.overlay.background.l);
820 }
821
822 #[test]
823 fn light_background_is_lighter_than_its_derived_levels() {
824 let c = ThemeColors::light();
825 assert!(c.background.l > c.background_secondary().l);
826 assert!(c.background_secondary().l > c.background_tertiary().l);
827 }
828}