1use sui_core::Color;
2use sui_layout::Padding as Insets;
3use sui_text::{FontFamilyStack, TextStyle};
4
5use crate::animation::Easing;
6use crate::hdr_theme::HdrThemeTokens;
7
8#[derive(Debug, Clone, Copy, PartialEq)]
20pub struct ThemeMotion {
21 pub duration_instant: f32,
23 pub duration_fast: f32,
25 pub duration_normal: f32,
27 pub duration_slow: f32,
29 pub duration_slower: f32,
31 pub easing_standard: Easing,
34 pub easing_emphasized: Easing,
36 pub easing_decelerate: Easing,
39 pub easing_accelerate: Easing,
42}
43
44impl ThemeMotion {
45 pub const fn standard() -> Self {
47 Self {
48 duration_instant: 0.0,
49 duration_fast: 0.07,
50 duration_normal: 0.14,
51 duration_slow: 0.22,
52 duration_slower: 0.34,
53 easing_standard: Easing::CubicBezier {
54 x1: 0.2,
55 y1: 0.0,
56 x2: 0.0,
57 y2: 1.0,
58 },
59 easing_emphasized: Easing::CubicBezier {
60 x1: 0.45,
61 y1: 0.0,
62 x2: 0.15,
63 y2: 1.0,
64 },
65 easing_decelerate: Easing::CubicBezier {
66 x1: 0.2,
67 y1: 0.0,
68 x2: 0.0,
69 y2: 1.0,
70 },
71 easing_accelerate: Easing::CubicBezier {
72 x1: 0.45,
73 y1: 0.0,
74 x2: 1.0,
75 y2: 1.0,
76 },
77 }
78 }
79
80 pub fn hover_duration(&self) -> f64 {
81 f64::from(self.duration_fast)
82 }
83
84 pub fn press_duration(&self) -> f64 {
85 f64::from(self.duration_fast)
86 }
87
88 pub fn focus_duration(&self) -> f64 {
89 f64::from(self.duration_normal)
90 }
91
92 pub fn toggle_duration(&self) -> f64 {
93 f64::from(self.duration_normal)
94 }
95
96 pub fn entrance_duration(&self) -> f64 {
97 f64::from(self.duration_normal)
98 }
99
100 pub fn tab_switch_duration(&self) -> f64 {
101 f64::from(self.duration_fast)
102 }
103
104 pub const fn hover_easing(&self) -> Easing {
105 self.easing_standard
106 }
107
108 pub const fn press_easing(&self) -> Easing {
109 self.easing_standard
110 }
111
112 pub const fn focus_easing(&self) -> Easing {
113 self.easing_decelerate
114 }
115
116 pub const fn toggle_easing(&self) -> Easing {
117 self.easing_emphasized
118 }
119
120 pub const fn entrance_easing(&self) -> Easing {
121 self.easing_decelerate
122 }
123
124 pub const fn tab_switch_easing(&self) -> Easing {
125 self.easing_standard
126 }
127}
128
129impl Default for ThemeMotion {
130 fn default() -> Self {
131 Self::standard()
132 }
133}
134
135#[derive(Debug, Clone, Copy, PartialEq, Eq)]
136pub struct ThemeFontStack {
137 pub primary: &'static str,
138 pub fallbacks: &'static [&'static str],
139}
140
141impl From<ThemeFontStack> for FontFamilyStack {
142 fn from(value: ThemeFontStack) -> Self {
143 Self::new(value.primary, value.fallbacks)
144 }
145}
146
147#[derive(Debug, Clone, Copy, PartialEq, Eq)]
148pub struct ThemeFontFamilies {
149 pub sans: ThemeFontStack,
150 pub serif: ThemeFontStack,
151 pub mono: ThemeFontStack,
152}
153
154impl Default for ThemeFontFamilies {
155 fn default() -> Self {
156 Self {
157 sans: ThemeFontStack {
158 primary: "ui-sans-serif",
159 fallbacks: &[
160 "system-ui",
161 "sans-serif",
162 "Apple Color Emoji",
163 "Segoe UI Emoji",
164 "Segoe UI Symbol",
165 "Noto Color Emoji",
166 ],
167 },
168 serif: ThemeFontStack {
169 primary: "ui-serif",
170 fallbacks: &["Georgia", "Cambria", "Times New Roman", "Times", "serif"],
171 },
172 mono: ThemeFontStack {
173 primary: "ui-monospace",
174 fallbacks: &[
175 "SFMono-Regular",
176 "Menlo",
177 "Monaco",
178 "Consolas",
179 "Liberation Mono",
180 "Courier New",
181 "monospace",
182 ],
183 },
184 }
185 }
186}
187
188#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
189pub enum ThemeColorScheme {
190 #[default]
191 Light,
192 Dark,
193 HighContrast,
194}
195
196#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
197pub enum ThemeDensity {
198 Compact,
199 #[default]
200 Comfortable,
201 Touch,
202}
203
204#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
213pub enum ControlSize {
214 Small,
215 #[default]
216 Medium,
217 Large,
218}
219
220impl ControlSize {
221 const fn legacy_density(self) -> ThemeDensity {
222 match self {
223 Self::Small => ThemeDensity::Compact,
224 Self::Medium => ThemeDensity::Comfortable,
225 Self::Large => ThemeDensity::Touch,
226 }
227 }
228
229 const fn control_height(self) -> f32 {
230 match self {
231 Self::Small => 28.0,
232 Self::Medium => 32.0,
233 Self::Large => 40.0,
234 }
235 }
236
237 const fn row_height(self) -> f32 {
238 match self {
239 Self::Small => 30.0,
240 Self::Medium => 36.0,
241 Self::Large => 44.0,
242 }
243 }
244
245 const fn icon_size(self) -> f32 {
246 match self {
247 Self::Small => 13.0,
248 Self::Medium => 15.0,
249 Self::Large => 17.0,
250 }
251 }
252}
253
254#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
255pub enum SemanticTone {
256 #[default]
257 Neutral,
258 Accent,
259 Info,
260 Success,
261 Warning,
262 Danger,
263}
264
265#[derive(Debug, Clone, Copy, PartialEq)]
266pub struct ThemeColors {
267 pub name: &'static str,
268 pub scheme: ThemeColorScheme,
269 pub base_100: Color,
270 pub base_200: Color,
271 pub base_300: Color,
272 pub base_content: Color,
273 pub primary: Color,
274 pub primary_content: Color,
275 pub secondary: Color,
276 pub secondary_content: Color,
277 pub accent: Color,
278 pub accent_content: Color,
279 pub neutral: Color,
280 pub neutral_content: Color,
281 pub info: Color,
282 pub info_content: Color,
283 pub success: Color,
284 pub success_content: Color,
285 pub warning: Color,
286 pub warning_content: Color,
287 pub error: Color,
288 pub error_content: Color,
289}
290
291impl ThemeColors {
292 pub fn sui() -> Self {
296 Self::light()
297 }
298
299 pub fn light() -> Self {
300 Self {
301 name: "light",
302 scheme: ThemeColorScheme::Light,
303 base_100: rgb8(255, 255, 255),
304 base_200: rgb8(247, 248, 250),
305 base_300: rgb8(227, 232, 239),
306 base_content: rgb8(13, 18, 32),
307 primary: rgb8(8, 124, 164),
308 primary_content: Color::WHITE,
309 secondary: rgb8(143, 125, 248),
310 secondary_content: Color::WHITE,
311 accent: rgb8(8, 124, 164),
312 accent_content: Color::WHITE,
313 neutral: rgb8(73, 84, 107),
314 neutral_content: Color::WHITE,
315 info: rgb8(41, 112, 255),
316 info_content: Color::WHITE,
317 success: rgb8(22, 163, 74),
318 success_content: Color::WHITE,
319 warning: rgb8(220, 154, 16),
320 warning_content: rgb8(36, 22, 0),
321 error: rgb8(217, 45, 32),
322 error_content: Color::WHITE,
323 }
324 }
325
326 pub fn neutral() -> Self {
332 Self {
333 name: "neutral",
334 scheme: ThemeColorScheme::Light,
335 base_100: Color::WHITE,
336 base_200: rgb8(250, 250, 250),
337 base_300: rgb8(229, 229, 229),
338 base_content: rgb8(23, 23, 23),
339 primary: rgb8(23, 23, 23),
340 primary_content: Color::WHITE,
341 secondary: rgb8(64, 64, 64),
342 secondary_content: Color::WHITE,
343 accent: rgb8(23, 23, 23),
344 accent_content: Color::WHITE,
345 neutral: rgb8(38, 38, 38),
346 neutral_content: Color::WHITE,
347 info: rgb8(37, 99, 235),
348 info_content: Color::WHITE,
349 success: rgb8(21, 128, 61),
350 success_content: Color::WHITE,
351 warning: rgb8(180, 83, 9),
352 warning_content: Color::WHITE,
353 error: rgb8(185, 28, 28),
354 error_content: Color::WHITE,
355 }
356 }
357
358 pub fn neutral_dark() -> Self {
361 Self {
362 name: "neutral-dark",
363 scheme: ThemeColorScheme::Dark,
364 base_100: rgb8(10, 10, 10),
365 base_200: rgb8(23, 23, 23),
366 base_300: rgb8(38, 38, 38),
367 base_content: rgb8(245, 245, 245),
368 primary: rgb8(245, 245, 245),
369 primary_content: rgb8(23, 23, 23),
370 secondary: rgb8(163, 163, 163),
371 secondary_content: rgb8(23, 23, 23),
372 accent: rgb8(245, 245, 245),
373 accent_content: rgb8(23, 23, 23),
374 neutral: rgb8(38, 38, 38),
375 neutral_content: rgb8(245, 245, 245),
376 info: rgb8(96, 165, 250),
377 info_content: rgb8(23, 37, 84),
378 success: rgb8(74, 222, 128),
379 success_content: rgb8(5, 46, 22),
380 warning: rgb8(251, 191, 36),
381 warning_content: rgb8(66, 32, 6),
382 error: rgb8(248, 113, 113),
383 error_content: rgb8(69, 10, 10),
384 }
385 }
386
387 pub fn dark() -> Self {
388 Self {
389 name: "dark",
390 scheme: ThemeColorScheme::Dark,
391 base_100: rgb8(11, 14, 19),
392 base_200: rgb8(18, 22, 31),
393 base_300: rgb8(29, 36, 49),
394 base_content: rgb8(231, 235, 244),
395 primary: rgb8(53, 210, 238),
396 primary_content: rgb8(5, 33, 41),
397 secondary: rgb8(143, 125, 248),
398 secondary_content: rgb8(16, 11, 36),
399 accent: rgb8(53, 210, 238),
400 accent_content: rgb8(5, 33, 41),
401 neutral: rgb8(23, 28, 39),
402 neutral_content: rgb8(231, 235, 244),
403 info: rgb8(109, 149, 245),
404 info_content: rgb8(7, 19, 48),
405 success: rgb8(52, 211, 116),
406 success_content: rgb8(2, 38, 20),
407 warning: rgb8(253, 176, 34),
408 warning_content: rgb8(40, 24, 0),
409 error: rgb8(241, 87, 92),
410 error_content: rgb8(42, 8, 8),
411 }
412 }
413
414 pub fn high_contrast() -> Self {
415 Self {
416 name: "void",
417 scheme: ThemeColorScheme::HighContrast,
418 base_100: Color::BLACK,
419 base_200: rgb8(11, 14, 20),
420 base_300: rgb8(19, 23, 34),
421 base_content: rgb8(223, 229, 240),
422 primary: rgb8(33, 199, 229),
423 primary_content: rgb8(3, 19, 24),
424 secondary: rgb8(143, 125, 248),
425 secondary_content: rgb8(16, 11, 36),
426 accent: rgb8(33, 199, 229),
427 accent_content: rgb8(3, 19, 24),
428 neutral: rgb8(11, 14, 20),
429 neutral_content: rgb8(223, 229, 240),
430 info: rgb8(100, 141, 240),
431 info_content: rgb8(5, 16, 42),
432 success: rgb8(46, 201, 108),
433 success_content: rgb8(1, 33, 16),
434 warning: rgb8(242, 169, 31),
435 warning_content: rgb8(38, 23, 0),
436 error: rgb8(233, 78, 83),
437 error_content: rgb8(36, 6, 6),
438 }
439 }
440
441 pub fn with_scheme(scheme: ThemeColorScheme) -> Self {
442 match scheme {
443 ThemeColorScheme::Light => Self::light(),
444 ThemeColorScheme::Dark => Self::dark(),
445 ThemeColorScheme::HighContrast => Self::high_contrast(),
446 }
447 }
448}
449
450impl Default for ThemeColors {
451 fn default() -> Self {
452 Self::light()
453 }
454}
455
456#[derive(Debug, Clone, Copy, PartialEq)]
457pub struct ThemeBreakpoints {
458 pub sm: f32,
459 pub md: f32,
460 pub lg: f32,
461 pub xl: f32,
462 pub _2xl: f32,
463}
464
465impl Default for ThemeBreakpoints {
466 fn default() -> Self {
467 Self {
468 sm: 640.0,
469 md: 768.0,
470 lg: 1024.0,
471 xl: 1280.0,
472 _2xl: 1536.0,
473 }
474 }
475}
476
477#[derive(Debug, Clone, Copy, PartialEq)]
478pub struct ThemeContainers {
479 pub _3xs: f32,
480 pub _2xs: f32,
481 pub xs: f32,
482 pub sm: f32,
483 pub md: f32,
484 pub lg: f32,
485 pub xl: f32,
486 pub _2xl: f32,
487 pub _3xl: f32,
488 pub _4xl: f32,
489 pub _5xl: f32,
490 pub _6xl: f32,
491 pub _7xl: f32,
492}
493
494impl Default for ThemeContainers {
495 fn default() -> Self {
496 Self {
497 _3xs: 256.0,
498 _2xs: 288.0,
499 xs: 320.0,
500 sm: 384.0,
501 md: 448.0,
502 lg: 512.0,
503 xl: 576.0,
504 _2xl: 672.0,
505 _3xl: 768.0,
506 _4xl: 896.0,
507 _5xl: 1024.0,
508 _6xl: 1152.0,
509 _7xl: 1280.0,
510 }
511 }
512}
513
514#[derive(Debug, Clone, Copy, PartialEq)]
515pub struct ThemeTextToken {
516 pub size: f32,
517 pub line_height: f32,
518}
519
520#[derive(Debug, Clone, Copy, PartialEq)]
521pub struct ThemeTextScale {
522 pub xs: ThemeTextToken,
523 pub sm: ThemeTextToken,
524 pub base: ThemeTextToken,
525 pub lg: ThemeTextToken,
526 pub xl: ThemeTextToken,
527 pub _2xl: ThemeTextToken,
528 pub _3xl: ThemeTextToken,
529 pub _4xl: ThemeTextToken,
530 pub _5xl: ThemeTextToken,
531 pub _6xl: ThemeTextToken,
532 pub _7xl: ThemeTextToken,
533 pub _8xl: ThemeTextToken,
534 pub _9xl: ThemeTextToken,
535}
536
537impl Default for ThemeTextScale {
538 fn default() -> Self {
539 Self {
540 xs: ThemeTextToken {
541 size: 12.0,
542 line_height: 17.0,
543 },
544 sm: ThemeTextToken {
545 size: 13.0,
546 line_height: 18.0,
547 },
548 base: ThemeTextToken {
549 size: 15.0,
550 line_height: 22.0,
551 },
552 lg: ThemeTextToken {
553 size: 17.0,
554 line_height: 25.0,
555 },
556 xl: ThemeTextToken {
557 size: 19.0,
558 line_height: 27.0,
559 },
560 _2xl: ThemeTextToken {
561 size: 21.0,
562 line_height: 29.0,
563 },
564 _3xl: ThemeTextToken {
565 size: 25.0,
566 line_height: 33.0,
567 },
568 _4xl: ThemeTextToken {
569 size: 31.0,
570 line_height: 39.0,
571 },
572 _5xl: ThemeTextToken {
573 size: 37.0,
574 line_height: 45.0,
575 },
576 _6xl: ThemeTextToken {
577 size: 49.0,
578 line_height: 55.0,
579 },
580 _7xl: ThemeTextToken {
581 size: 61.0,
582 line_height: 67.0,
583 },
584 _8xl: ThemeTextToken {
585 size: 73.0,
586 line_height: 79.0,
587 },
588 _9xl: ThemeTextToken {
589 size: 97.0,
590 line_height: 103.0,
591 },
592 }
593 }
594}
595
596#[derive(Debug, Clone, Copy, PartialEq, Eq)]
597pub struct ThemeFontWeights {
598 pub thin: u16,
599 pub extralight: u16,
600 pub light: u16,
601 pub normal: u16,
602 pub medium: u16,
603 pub semibold: u16,
604 pub bold: u16,
605 pub extrabold: u16,
606 pub black: u16,
607}
608
609impl Default for ThemeFontWeights {
610 fn default() -> Self {
611 Self {
612 thin: 100,
613 extralight: 200,
614 light: 300,
615 normal: 400,
616 medium: 500,
617 semibold: 600,
618 bold: 700,
619 extrabold: 800,
620 black: 900,
621 }
622 }
623}
624
625#[derive(Debug, Clone, Copy, PartialEq)]
626pub struct ThemeTracking {
627 pub tighter: f32,
628 pub tight: f32,
629 pub normal: f32,
630 pub wide: f32,
631 pub wider: f32,
632 pub widest: f32,
633}
634
635impl Default for ThemeTracking {
636 fn default() -> Self {
637 Self {
638 tighter: 0.0,
639 tight: 0.0,
640 normal: 0.0,
641 wide: 0.02,
642 wider: 0.04,
643 widest: 0.06,
644 }
645 }
646}
647
648#[derive(Debug, Clone, Copy, PartialEq)]
649pub struct ThemeLeading {
650 pub tight: f32,
651 pub snug: f32,
652 pub normal: f32,
653 pub relaxed: f32,
654 pub loose: f32,
655}
656
657impl Default for ThemeLeading {
658 fn default() -> Self {
659 Self {
660 tight: 1.3,
661 snug: 1.4,
662 normal: 1.5,
663 relaxed: 1.6,
664 loose: 1.65,
665 }
666 }
667}
668
669#[derive(Debug, Clone, Copy, PartialEq)]
670pub struct ThemeRadii {
671 pub xs: f32,
672 pub sm: f32,
673 pub md: f32,
674 pub lg: f32,
675 pub xl: f32,
676 pub _2xl: f32,
677 pub _3xl: f32,
678 pub _4xl: f32,
679}
680
681impl Default for ThemeRadii {
682 fn default() -> Self {
683 Self {
684 xs: 2.0,
685 sm: 4.0,
686 md: 6.0,
687 lg: 8.0,
688 xl: 10.0,
689 _2xl: 14.0,
690 _3xl: 18.0,
691 _4xl: 999.0,
692 }
693 }
694}
695
696#[derive(Debug, Clone, Copy, PartialEq)]
697pub struct ThemeShadowLayer {
698 pub offset_x: f32,
699 pub offset_y: f32,
700 pub blur: f32,
701 pub spread: f32,
702 pub color: Color,
703 pub inset: bool,
704}
705
706#[derive(Debug, Clone, Copy, PartialEq)]
707pub struct ThemeShadow {
708 pub first: Option<ThemeShadowLayer>,
709 pub second: Option<ThemeShadowLayer>,
710}
711
712impl ThemeShadow {
713 pub const fn empty() -> Self {
714 Self {
715 first: None,
716 second: None,
717 }
718 }
719
720 pub const fn single(layer: ThemeShadowLayer) -> Self {
721 Self {
722 first: Some(layer),
723 second: None,
724 }
725 }
726
727 pub const fn double(first: ThemeShadowLayer, second: ThemeShadowLayer) -> Self {
728 Self {
729 first: Some(first),
730 second: Some(second),
731 }
732 }
733}
734
735impl ThemeShadowLayer {
736 pub fn to_shadow_params(&self) -> sui_scene::ShadowParams {
739 sui_scene::ShadowParams {
740 offset_x: self.offset_x,
741 offset_y: self.offset_y,
742 blur: self.blur,
743 spread: self.spread,
744 color: self.color,
745 }
746 }
747
748 pub const fn is_outer(&self) -> bool {
751 !self.inset
752 }
753}
754
755pub fn paint_theme_shadow(
766 paint: &mut sui_runtime::PaintCtx,
767 rect: sui_core::Rect,
768 radii: [f32; 4],
769 shadow: &ThemeShadow,
770) {
771 if let Some(layer) = shadow.second
774 && layer.is_outer()
775 {
776 paint.draw_shadow(rect, radii, layer.to_shadow_params());
777 }
779 if let Some(layer) = shadow.first
780 && layer.is_outer()
781 {
782 paint.draw_shadow(rect, radii, layer.to_shadow_params());
783 }
785}
786
787#[derive(Debug, Clone, Copy, PartialEq)]
788pub struct ThemeBoxShadowScale {
789 pub _2xs: ThemeShadow,
790 pub xs: ThemeShadow,
791 pub sm: ThemeShadow,
792 pub md: ThemeShadow,
793 pub lg: ThemeShadow,
794 pub xl: ThemeShadow,
795 pub _2xl: ThemeShadow,
796}
797
798#[derive(Debug, Clone, Copy, PartialEq)]
799pub struct ThemeInsetShadowScale {
800 pub _2xs: ThemeShadow,
801 pub xs: ThemeShadow,
802 pub sm: ThemeShadow,
803}
804
805#[derive(Debug, Clone, Copy, PartialEq)]
806pub struct ThemeDropShadowScale {
807 pub xs: ThemeShadow,
808 pub sm: ThemeShadow,
809 pub md: ThemeShadow,
810 pub lg: ThemeShadow,
811 pub xl: ThemeShadow,
812 pub _2xl: ThemeShadow,
813}
814
815#[derive(Debug, Clone, Copy, PartialEq)]
816pub struct ThemeTextShadowScale {
817 pub _2xs: ThemeShadow,
818 pub xs: ThemeShadow,
819 pub sm: ThemeShadow,
820 pub md: ThemeShadow,
821 pub lg: ThemeShadow,
822}
823
824#[derive(Debug, Clone, Copy, PartialEq)]
825pub struct ThemeShadows {
826 pub box_shadow: ThemeBoxShadowScale,
827 pub inset: ThemeInsetShadowScale,
828 pub drop: ThemeDropShadowScale,
829 pub text: ThemeTextShadowScale,
830}
831
832impl Default for ThemeShadows {
833 fn default() -> Self {
834 let black_005 = Color::BLACK.with_alpha(0.05);
835 let black_01 = Color::BLACK.with_alpha(0.1);
836 let black_012 = Color::BLACK.with_alpha(0.12);
837 let black_015 = Color::BLACK.with_alpha(0.15);
838 let black_02 = Color::BLACK.with_alpha(0.2);
839 let black_025 = Color::BLACK.with_alpha(0.25);
840 let black_075 = Color::BLACK.with_alpha(0.075);
841
842 Self {
843 box_shadow: ThemeBoxShadowScale {
844 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black_005, false)),
845 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black_005, false)),
846 sm: ThemeShadow::double(
847 shadow_layer(0.0, 1.0, 3.0, 0.0, black_01, false),
848 shadow_layer(0.0, 1.0, 2.0, -1.0, black_01, false),
849 ),
850 md: ThemeShadow::double(
851 shadow_layer(0.0, 4.0, 6.0, -1.0, black_01, false),
852 shadow_layer(0.0, 2.0, 4.0, -2.0, black_01, false),
853 ),
854 lg: ThemeShadow::double(
855 shadow_layer(0.0, 10.0, 15.0, -3.0, black_01, false),
856 shadow_layer(0.0, 4.0, 6.0, -4.0, black_01, false),
857 ),
858 xl: ThemeShadow::double(
859 shadow_layer(0.0, 20.0, 25.0, -5.0, black_01, false),
860 shadow_layer(0.0, 8.0, 10.0, -6.0, black_01, false),
861 ),
862 _2xl: ThemeShadow::single(shadow_layer(0.0, 25.0, 50.0, -12.0, black_025, false)),
863 },
864 inset: ThemeInsetShadowScale {
865 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black_005, true)),
866 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black_005, true)),
867 sm: ThemeShadow::single(shadow_layer(0.0, 2.0, 4.0, 0.0, black_005, true)),
868 },
869 drop: ThemeDropShadowScale {
870 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black_005, false)),
871 sm: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black_015, false)),
872 md: ThemeShadow::single(shadow_layer(0.0, 3.0, 3.0, 0.0, black_012, false)),
873 lg: ThemeShadow::single(shadow_layer(0.0, 4.0, 4.0, 0.0, black_015, false)),
874 xl: ThemeShadow::single(shadow_layer(0.0, 9.0, 7.0, 0.0, black_01, false)),
875 _2xl: ThemeShadow::single(shadow_layer(0.0, 25.0, 25.0, 0.0, black_015, false)),
876 },
877 text: ThemeTextShadowScale {
878 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black_015, false)),
879 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black_02, false)),
880 sm: ThemeShadow::double(
881 shadow_layer(0.0, 1.0, 0.0, 0.0, black_075, false),
882 shadow_layer(0.0, 1.0, 1.0, 0.0, black_075, false),
883 ),
884 md: ThemeShadow::double(
885 shadow_layer(0.0, 1.0, 1.0, 0.0, black_01, false),
886 shadow_layer(0.0, 2.0, 4.0, 0.0, black_01, false),
887 ),
888 lg: ThemeShadow::double(
889 shadow_layer(0.0, 1.0, 2.0, 0.0, black_01, false),
890 shadow_layer(0.0, 4.0, 8.0, 0.0, black_01, false),
891 ),
892 },
893 }
894 }
895}
896
897impl ThemeShadows {
898 pub fn for_colors(colors: &ThemeColors) -> Self {
900 if is_neutral_theme(colors) && matches!(colors.scheme, ThemeColorScheme::Light) {
901 Self::neutral()
902 } else {
903 Self::for_scheme(colors.scheme)
904 }
905 }
906
907 pub fn for_scheme(scheme: ThemeColorScheme) -> Self {
912 match scheme {
913 ThemeColorScheme::Light => Self::light(),
914 ThemeColorScheme::Dark => Self::dark(),
915 ThemeColorScheme::HighContrast => Self::none(),
916 }
917 }
918
919 pub fn light() -> Self {
922 Self::light_with_ink(rgb8(13, 18, 32))
923 }
924
925 fn light_with_ink(shadow_ink: Color) -> Self {
926 let ink = |alpha: f32| shadow_ink.with_alpha(alpha);
927
928 Self {
929 box_shadow: ThemeBoxShadowScale {
930 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, ink(0.04), false)),
931 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, ink(0.06), false)),
932 sm: ThemeShadow::double(
933 shadow_layer(0.0, 1.0, 3.0, 0.0, ink(0.07), false),
934 shadow_layer(0.0, 1.0, 2.0, -1.0, ink(0.06), false),
935 ),
936 md: ThemeShadow::single(shadow_layer(0.0, 2.0, 10.0, 0.0, ink(0.08), false)),
937 lg: ThemeShadow::single(shadow_layer(0.0, 8.0, 24.0, -2.0, ink(0.12), false)),
938 xl: ThemeShadow::single(shadow_layer(0.0, 16.0, 40.0, -4.0, ink(0.16), false)),
939 _2xl: ThemeShadow::single(shadow_layer(0.0, 24.0, 56.0, -8.0, ink(0.20), false)),
940 },
941 inset: ThemeInsetShadowScale {
942 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, ink(0.05), true)),
943 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.05), true)),
944 sm: ThemeShadow::single(shadow_layer(0.0, 2.0, 4.0, 0.0, ink(0.05), true)),
945 },
946 drop: ThemeDropShadowScale {
947 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.05), false)),
948 sm: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, ink(0.12), false)),
949 md: ThemeShadow::single(shadow_layer(0.0, 3.0, 3.0, 0.0, ink(0.10), false)),
950 lg: ThemeShadow::single(shadow_layer(0.0, 4.0, 4.0, 0.0, ink(0.12), false)),
951 xl: ThemeShadow::single(shadow_layer(0.0, 9.0, 7.0, 0.0, ink(0.09), false)),
952 _2xl: ThemeShadow::single(shadow_layer(0.0, 25.0, 25.0, 0.0, ink(0.12), false)),
953 },
954 text: ThemeTextShadowScale {
955 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, ink(0.12), false)),
956 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.16), false)),
957 sm: ThemeShadow::double(
958 shadow_layer(0.0, 1.0, 0.0, 0.0, ink(0.07), false),
959 shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.07), false),
960 ),
961 md: ThemeShadow::double(
962 shadow_layer(0.0, 1.0, 1.0, 0.0, ink(0.09), false),
963 shadow_layer(0.0, 2.0, 4.0, 0.0, ink(0.09), false),
964 ),
965 lg: ThemeShadow::double(
966 shadow_layer(0.0, 1.0, 2.0, 0.0, ink(0.09), false),
967 shadow_layer(0.0, 4.0, 8.0, 0.0, ink(0.09), false),
968 ),
969 },
970 }
971 }
972
973 pub fn neutral() -> Self {
976 Self::light_with_ink(Color::BLACK)
977 }
978
979 pub fn dark() -> Self {
982 let black = |alpha: f32| Color::BLACK.with_alpha(alpha);
983
984 Self {
985 box_shadow: ThemeBoxShadowScale {
986 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black(0.24), false)),
987 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black(0.30), false)),
988 sm: ThemeShadow::double(
989 shadow_layer(0.0, 2.0, 6.0, 0.0, black(0.32), false),
990 shadow_layer(0.0, 1.0, 2.0, -1.0, black(0.28), false),
991 ),
992 md: ThemeShadow::single(shadow_layer(0.0, 4.0, 16.0, 0.0, black(0.40), false)),
993 lg: ThemeShadow::single(shadow_layer(0.0, 10.0, 28.0, -2.0, black(0.46), false)),
994 xl: ThemeShadow::single(shadow_layer(0.0, 20.0, 48.0, -4.0, black(0.55), false)),
995 _2xl: ThemeShadow::single(shadow_layer(0.0, 28.0, 64.0, -8.0, black(0.60), false)),
996 },
997 inset: ThemeInsetShadowScale {
998 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black(0.24), true)),
999 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.24), true)),
1000 sm: ThemeShadow::single(shadow_layer(0.0, 2.0, 4.0, 0.0, black(0.24), true)),
1001 },
1002 drop: ThemeDropShadowScale {
1003 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.24), false)),
1004 sm: ThemeShadow::single(shadow_layer(0.0, 1.0, 2.0, 0.0, black(0.34), false)),
1005 md: ThemeShadow::single(shadow_layer(0.0, 3.0, 3.0, 0.0, black(0.32), false)),
1006 lg: ThemeShadow::single(shadow_layer(0.0, 4.0, 4.0, 0.0, black(0.34), false)),
1007 xl: ThemeShadow::single(shadow_layer(0.0, 9.0, 7.0, 0.0, black(0.30), false)),
1008 _2xl: ThemeShadow::single(shadow_layer(0.0, 25.0, 25.0, 0.0, black(0.34), false)),
1009 },
1010 text: ThemeTextShadowScale {
1011 _2xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 0.0, 0.0, black(0.30), false)),
1012 xs: ThemeShadow::single(shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.36), false)),
1013 sm: ThemeShadow::double(
1014 shadow_layer(0.0, 1.0, 0.0, 0.0, black(0.20), false),
1015 shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.20), false),
1016 ),
1017 md: ThemeShadow::double(
1018 shadow_layer(0.0, 1.0, 1.0, 0.0, black(0.24), false),
1019 shadow_layer(0.0, 2.0, 4.0, 0.0, black(0.24), false),
1020 ),
1021 lg: ThemeShadow::double(
1022 shadow_layer(0.0, 1.0, 2.0, 0.0, black(0.24), false),
1023 shadow_layer(0.0, 4.0, 8.0, 0.0, black(0.24), false),
1024 ),
1025 },
1026 }
1027 }
1028
1029 pub fn none() -> Self {
1032 let empty_box = ThemeBoxShadowScale {
1033 _2xs: ThemeShadow::empty(),
1034 xs: ThemeShadow::empty(),
1035 sm: ThemeShadow::empty(),
1036 md: ThemeShadow::empty(),
1037 lg: ThemeShadow::empty(),
1038 xl: ThemeShadow::empty(),
1039 _2xl: ThemeShadow::empty(),
1040 };
1041
1042 Self {
1043 box_shadow: empty_box,
1044 inset: ThemeInsetShadowScale {
1045 _2xs: ThemeShadow::empty(),
1046 xs: ThemeShadow::empty(),
1047 sm: ThemeShadow::empty(),
1048 },
1049 drop: ThemeDropShadowScale {
1050 xs: ThemeShadow::empty(),
1051 sm: ThemeShadow::empty(),
1052 md: ThemeShadow::empty(),
1053 lg: ThemeShadow::empty(),
1054 xl: ThemeShadow::empty(),
1055 _2xl: ThemeShadow::empty(),
1056 },
1057 text: ThemeTextShadowScale {
1058 _2xs: ThemeShadow::empty(),
1059 xs: ThemeShadow::empty(),
1060 sm: ThemeShadow::empty(),
1061 md: ThemeShadow::empty(),
1062 lg: ThemeShadow::empty(),
1063 },
1064 }
1065 }
1066}
1067
1068#[derive(Debug, Clone, Copy, PartialEq)]
1073pub struct ThemeGlows {
1074 pub accent: ThemeShadow,
1076 pub secondary: ThemeShadow,
1078}
1079
1080impl ThemeGlows {
1081 pub fn for_colors(colors: &ThemeColors) -> Self {
1083 if is_neutral_theme(colors) {
1084 match colors.scheme {
1085 ThemeColorScheme::Light => Self::none(),
1086 ThemeColorScheme::Dark => Self::neutral_dark(),
1087 ThemeColorScheme::HighContrast => Self::none(),
1088 }
1089 } else {
1090 Self::for_scheme(colors.scheme)
1091 }
1092 }
1093
1094 pub fn for_scheme(scheme: ThemeColorScheme) -> Self {
1095 match scheme {
1096 ThemeColorScheme::Light => Self::none(),
1097 ThemeColorScheme::Dark => Self {
1098 accent: ThemeShadow::single(shadow_layer(
1099 0.0,
1100 0.0,
1101 16.0,
1102 0.0,
1103 rgb8(53, 210, 238).with_alpha(0.22),
1104 false,
1105 )),
1106 secondary: ThemeShadow::single(shadow_layer(
1107 0.0,
1108 0.0,
1109 18.0,
1110 0.0,
1111 rgb8(143, 125, 248).with_alpha(0.26),
1112 false,
1113 )),
1114 },
1115 ThemeColorScheme::HighContrast => Self {
1116 accent: ThemeShadow::single(shadow_layer(
1117 0.0,
1118 0.0,
1119 10.0,
1120 0.0,
1121 rgb8(33, 199, 229).with_alpha(0.14),
1122 false,
1123 )),
1124 secondary: ThemeShadow::single(shadow_layer(
1125 0.0,
1126 0.0,
1127 12.0,
1128 0.0,
1129 rgb8(143, 125, 248).with_alpha(0.16),
1130 false,
1131 )),
1132 },
1133 }
1134 }
1135
1136 pub fn none() -> Self {
1137 Self {
1138 accent: ThemeShadow::empty(),
1139 secondary: ThemeShadow::empty(),
1140 }
1141 }
1142
1143 pub fn neutral_dark() -> Self {
1145 Self {
1146 accent: ThemeShadow::single(shadow_layer(
1147 0.0,
1148 0.0,
1149 12.0,
1150 0.0,
1151 rgb8(245, 245, 245).with_alpha(0.12),
1152 false,
1153 )),
1154 secondary: ThemeShadow::single(shadow_layer(
1155 0.0,
1156 0.0,
1157 14.0,
1158 0.0,
1159 rgb8(163, 163, 163).with_alpha(0.12),
1160 false,
1161 )),
1162 }
1163 }
1164}
1165
1166impl Default for ThemeGlows {
1167 fn default() -> Self {
1168 Self::for_scheme(ThemeColorScheme::Light)
1169 }
1170}
1171
1172#[derive(Debug, Clone, Copy, PartialEq)]
1173pub struct ThemeBlurScale {
1174 pub xs: f32,
1175 pub sm: f32,
1176 pub md: f32,
1177 pub lg: f32,
1178 pub xl: f32,
1179 pub _2xl: f32,
1180 pub _3xl: f32,
1181}
1182
1183impl Default for ThemeBlurScale {
1184 fn default() -> Self {
1185 Self {
1186 xs: 4.0,
1187 sm: 8.0,
1188 md: 12.0,
1189 lg: 16.0,
1190 xl: 24.0,
1191 _2xl: 40.0,
1192 _3xl: 64.0,
1193 }
1194 }
1195}
1196
1197#[derive(Debug, Clone, Copy, PartialEq)]
1198pub struct ThemePerspective {
1199 pub dramatic: f32,
1200 pub near: f32,
1201 pub normal: f32,
1202 pub midrange: f32,
1203 pub distant: f32,
1204}
1205
1206impl Default for ThemePerspective {
1207 fn default() -> Self {
1208 Self {
1209 dramatic: 100.0,
1210 near: 300.0,
1211 normal: 500.0,
1212 midrange: 800.0,
1213 distant: 1200.0,
1214 }
1215 }
1216}
1217
1218#[derive(Debug, Clone, Copy, PartialEq)]
1219pub struct ThemeAspectRatios {
1220 pub video: f32,
1221}
1222
1223impl Default for ThemeAspectRatios {
1224 fn default() -> Self {
1225 Self { video: 16.0 / 9.0 }
1226 }
1227}
1228
1229#[derive(Debug, Clone, Copy, PartialEq)]
1234struct BuiltinColorRoles {
1235 bg_subtle: Color,
1236 surface: Color,
1237 surface_2: Color,
1238 surface_3: Color,
1239 overlay: Color,
1240 field: Color,
1241 border: Color,
1242 border_strong: Color,
1243 border_subtle: Color,
1244 text_2: Color,
1245 text_3: Color,
1246 text_disabled: Color,
1247 text_invert: Color,
1248 accent_hover: Color,
1249 accent_text: Color,
1250 accent_soft: Color,
1251 accent_border: Color,
1252 ok_text: Color,
1253 ok_soft: Color,
1254 warn_text: Color,
1255 warn_soft: Color,
1256 danger_text: Color,
1257 danger_soft: Color,
1258 danger_hover: Color,
1259 info_text: Color,
1260 info_soft: Color,
1261 focus: Color,
1262 selection: Color,
1263 scrim: Color,
1264}
1265
1266fn builtin_color_roles(colors: &ThemeColors) -> Option<BuiltinColorRoles> {
1269 match (colors.name, colors.scheme) {
1270 ("light", ThemeColorScheme::Light) => Some(BuiltinColorRoles {
1271 bg_subtle: rgb8(247, 248, 250),
1272 surface: rgb8(255, 255, 255),
1273 surface_2: rgb8(243, 245, 248),
1274 surface_3: rgb8(234, 238, 243),
1275 overlay: rgb8(255, 255, 255),
1276 field: rgb8(248, 250, 252),
1280 border: rgb8(227, 232, 239),
1281 border_strong: rgb8(205, 213, 224),
1282 border_subtle: rgb8(238, 241, 246),
1283 text_2: rgb8(73, 84, 107),
1284 text_3: rgb8(104, 115, 144),
1285 text_disabled: rgb8(163, 173, 194),
1286 text_invert: rgb8(255, 255, 255),
1287 accent_hover: rgb8(7, 109, 144),
1288 accent_text: rgb8(8, 124, 164),
1289 accent_soft: rgba8(8, 124, 164, 0.08),
1290 accent_border: rgba8(8, 124, 164, 0.35),
1291 ok_text: rgb8(21, 128, 61),
1292 ok_soft: rgba8(22, 163, 74, 0.10),
1293 warn_text: rgb8(154, 103, 0),
1294 warn_soft: rgba8(154, 103, 0, 0.10),
1295 danger_text: rgb8(217, 45, 32),
1296 danger_soft: rgba8(217, 45, 32, 0.08),
1297 danger_hover: rgb8(180, 35, 24),
1298 info_text: rgb8(23, 92, 211),
1299 info_soft: rgba8(41, 112, 255, 0.09),
1300 focus: rgb8(9, 148, 198),
1301 selection: rgba8(8, 124, 164, 0.18),
1302 scrim: rgba8(9, 12, 20, 0.45),
1303 }),
1304 ("neutral", ThemeColorScheme::Light) => Some(BuiltinColorRoles {
1305 bg_subtle: rgb8(250, 250, 250),
1306 surface: Color::WHITE,
1307 surface_2: rgb8(245, 245, 245),
1308 surface_3: rgb8(229, 229, 229),
1309 overlay: Color::WHITE,
1310 field: rgb8(250, 250, 250),
1311 border: rgb8(229, 229, 229),
1312 border_strong: rgb8(212, 212, 212),
1313 border_subtle: rgb8(240, 240, 240),
1314 text_2: rgb8(82, 82, 82),
1315 text_3: rgb8(115, 115, 115),
1316 text_disabled: rgb8(163, 163, 163),
1317 text_invert: Color::WHITE,
1318 accent_hover: rgb8(38, 38, 38),
1319 accent_text: rgb8(23, 23, 23),
1320 accent_soft: rgba8(23, 23, 23, 0.06),
1321 accent_border: rgba8(23, 23, 23, 0.28),
1322 ok_text: rgb8(21, 128, 61),
1323 ok_soft: rgba8(21, 128, 61, 0.10),
1324 warn_text: rgb8(146, 64, 14),
1325 warn_soft: rgba8(180, 83, 9, 0.10),
1326 danger_text: rgb8(185, 28, 28),
1327 danger_soft: rgba8(185, 28, 28, 0.08),
1328 danger_hover: rgb8(153, 27, 27),
1329 info_text: rgb8(29, 78, 216),
1330 info_soft: rgba8(37, 99, 235, 0.09),
1331 focus: rgb8(64, 64, 64),
1332 selection: rgba8(23, 23, 23, 0.12),
1333 scrim: Color::BLACK.with_alpha(0.45),
1334 }),
1335 ("neutral-dark", ThemeColorScheme::Dark) => Some(BuiltinColorRoles {
1336 bg_subtle: rgb8(10, 10, 10),
1337 surface: rgb8(23, 23, 23),
1338 surface_2: rgb8(38, 38, 38),
1339 surface_3: rgb8(51, 51, 51),
1340 overlay: rgb8(31, 31, 31),
1341 field: rgb8(18, 18, 18),
1342 border: Color::WHITE.with_alpha(0.14),
1343 border_strong: Color::WHITE.with_alpha(0.22),
1344 border_subtle: Color::WHITE.with_alpha(0.08),
1345 text_2: rgb8(212, 212, 212),
1346 text_3: rgb8(163, 163, 163),
1347 text_disabled: rgb8(115, 115, 115),
1348 text_invert: rgb8(23, 23, 23),
1349 accent_hover: Color::WHITE,
1350 accent_text: rgb8(245, 245, 245),
1351 accent_soft: Color::WHITE.with_alpha(0.10),
1352 accent_border: Color::WHITE.with_alpha(0.28),
1353 ok_text: rgb8(74, 222, 128),
1354 ok_soft: rgba8(74, 222, 128, 0.12),
1355 warn_text: rgb8(251, 191, 36),
1356 warn_soft: rgba8(251, 191, 36, 0.12),
1357 danger_text: rgb8(248, 113, 113),
1358 danger_soft: rgba8(248, 113, 113, 0.12),
1359 danger_hover: rgb8(252, 165, 165),
1360 info_text: rgb8(147, 197, 253),
1361 info_soft: rgba8(96, 165, 250, 0.12),
1362 focus: rgb8(212, 212, 212),
1363 selection: Color::WHITE.with_alpha(0.16),
1364 scrim: Color::BLACK.with_alpha(0.65),
1365 }),
1366 ("dark", ThemeColorScheme::Dark) => Some(BuiltinColorRoles {
1367 bg_subtle: rgb8(14, 18, 26),
1368 surface: rgb8(18, 22, 31),
1369 surface_2: rgb8(23, 28, 39),
1370 surface_3: rgb8(29, 36, 49),
1371 overlay: rgb8(22, 27, 38),
1372 field: rgb8(15, 19, 27),
1373 border: rgba8(151, 168, 199, 0.16),
1374 border_strong: rgba8(151, 168, 199, 0.27),
1375 border_subtle: rgba8(151, 168, 199, 0.09),
1376 text_2: rgb8(166, 178, 200),
1377 text_3: rgb8(124, 137, 163),
1378 text_disabled: rgb8(81, 93, 117),
1379 text_invert: rgb8(13, 18, 32),
1380 accent_hover: rgb8(95, 224, 246),
1381 accent_text: rgb8(83, 215, 240),
1382 accent_soft: rgba8(53, 210, 238, 0.12),
1383 accent_border: rgba8(53, 210, 238, 0.35),
1384 ok_text: rgb8(74, 222, 128),
1385 ok_soft: rgba8(74, 222, 128, 0.12),
1386 warn_text: rgb8(253, 176, 34),
1387 warn_soft: rgba8(253, 176, 34, 0.12),
1388 danger_text: rgb8(249, 112, 102),
1389 danger_soft: rgba8(249, 112, 102, 0.12),
1390 danger_hover: rgb8(246, 121, 125),
1391 info_text: rgb8(132, 169, 255),
1392 info_soft: rgba8(132, 169, 255, 0.12),
1393 focus: rgb8(73, 199, 234),
1394 selection: rgba8(53, 210, 238, 0.24),
1395 scrim: rgba8(2, 4, 8, 0.6),
1396 }),
1397 ("void", ThemeColorScheme::HighContrast) => Some(BuiltinColorRoles {
1398 bg_subtle: Color::BLACK,
1399 surface: Color::BLACK,
1400 surface_2: rgb8(11, 14, 20),
1401 surface_3: rgb8(19, 23, 34),
1402 overlay: rgb8(10, 13, 19),
1403 field: rgb8(11, 14, 20),
1404 border: rgba8(158, 175, 205, 0.18),
1405 border_strong: rgba8(158, 175, 205, 0.30),
1406 border_subtle: rgba8(158, 175, 205, 0.10),
1407 text_2: rgb8(153, 165, 188),
1408 text_3: rgb8(117, 129, 154),
1409 text_disabled: rgb8(72, 83, 107),
1410 text_invert: rgb8(13, 18, 32),
1411 accent_hover: rgb8(76, 212, 236),
1412 accent_text: rgb8(64, 205, 232),
1413 accent_soft: rgba8(33, 199, 229, 0.10),
1414 accent_border: rgba8(33, 199, 229, 0.32),
1415 ok_text: rgb8(64, 212, 122),
1416 ok_soft: rgba8(64, 212, 122, 0.10),
1417 warn_text: rgb8(242, 169, 31),
1418 warn_soft: rgba8(242, 169, 31, 0.10),
1419 danger_text: rgb8(244, 104, 94),
1420 danger_soft: rgba8(244, 104, 94, 0.10),
1421 danger_hover: rgb8(240, 104, 109),
1422 info_text: rgb8(123, 162, 252),
1423 info_soft: rgba8(123, 162, 252, 0.10),
1424 focus: rgb8(63, 196, 228),
1425 selection: rgba8(33, 199, 229, 0.22),
1426 scrim: rgba8(0, 0, 0, 0.72),
1427 }),
1428 _ => None,
1429 }
1430}
1431
1432#[derive(Debug, Clone, Copy, PartialEq)]
1433pub struct ControlPalette {
1434 pub text: Color,
1435 pub text_muted: Color,
1436 pub placeholder: Color,
1437 pub surface: Color,
1438 pub surface_raised: Color,
1439 pub control: Color,
1440 pub control_hover: Color,
1441 pub control_active: Color,
1442 pub field: Color,
1446 pub surface_hover: Color,
1447 pub surface_pressed: Color,
1448 pub surface_focus: Color,
1449 pub border: Color,
1450 pub border_strong: Color,
1451 pub border_hover: Color,
1452 pub border_focus: Color,
1453 pub focus: Color,
1456 pub focus_ring: Color,
1457 pub caret: Color,
1458 pub selection: Color,
1459 pub accent: Color,
1460 pub accent_hover: Color,
1461 pub accent_pressed: Color,
1462 pub accent_border: Color,
1463 pub accent_border_hover: Color,
1464 pub accent_border_focus: Color,
1465 pub accent_text: Color,
1466 pub accent_soft: Color,
1469 pub accent_soft_text: Color,
1473 pub info: Color,
1474 pub info_text: Color,
1475 pub info_soft: Color,
1476 pub info_soft_text: Color,
1477 pub success: Color,
1478 pub success_text: Color,
1479 pub success_soft: Color,
1480 pub success_soft_text: Color,
1481 pub warning: Color,
1482 pub warning_text: Color,
1483 pub warning_soft: Color,
1484 pub warning_soft_text: Color,
1485 pub danger: Color,
1486 pub danger_text: Color,
1487 pub danger_soft: Color,
1488 pub danger_soft_text: Color,
1489 pub danger_hover: Color,
1490}
1491
1492impl ControlPalette {
1493 pub fn from_colors(colors: &ThemeColors) -> Self {
1494 let is_dark = matches!(
1495 colors.scheme,
1496 ThemeColorScheme::Dark | ThemeColorScheme::HighContrast
1497 );
1498 let roles = builtin_color_roles(colors);
1499 let surface = colors.base_100;
1500 let surface_raised = roles.map(|r| r.surface).unwrap_or(colors.base_200);
1501 let flatten = move |color: Color| color.over(surface_raised);
1506 let control = roles.map(|r| r.surface_2).unwrap_or(colors.base_200);
1508 let control_hover = roles
1509 .map(|r| r.surface_3)
1510 .unwrap_or_else(|| interactive_surface(control, colors.scheme, 0.035));
1511 let control_active = roles
1512 .map(|r| mix(r.surface_3, colors.base_content, 0.04))
1513 .unwrap_or_else(|| interactive_surface(control, colors.scheme, 0.075));
1514 let field = roles.map(|r| r.field).unwrap_or(control);
1515 let text_muted = roles.map(|r| r.text_2).unwrap_or_else(|| {
1516 mix(
1517 colors.base_content,
1518 surface,
1519 if is_dark { 0.34 } else { 0.16 },
1520 )
1521 });
1522 let placeholder = roles.map(|r| r.text_3).unwrap_or_else(|| {
1523 mix(
1524 colors.base_content,
1525 surface,
1526 if is_dark { 0.50 } else { 0.22 },
1527 )
1528 });
1529 let border = roles.map(|r| flatten(r.border)).unwrap_or_else(|| {
1530 if is_dark {
1531 mix(colors.base_300, surface, 0.22)
1532 } else {
1533 colors.base_300
1534 }
1535 });
1536 let border_strong = roles.map(|r| flatten(r.border_strong)).unwrap_or_else(|| {
1537 mix(
1538 colors.base_300,
1539 colors.base_content,
1540 if is_dark { 0.18 } else { 0.10 },
1541 )
1542 });
1543 let border_hover = roles
1546 .map(|r| flatten(r.border_strong))
1547 .unwrap_or_else(|| mix(border, colors.primary, if is_dark { 0.28 } else { 0.18 }));
1548 let border_focus = colors.primary;
1549 let focus = roles.map(|r| r.focus).unwrap_or(colors.primary);
1550 let selection = roles
1551 .map(|r| flatten(r.selection))
1552 .unwrap_or_else(|| mix(surface, colors.primary, if is_dark { 0.30 } else { 0.14 }));
1553 let soft_alpha = if is_dark { 0.12 } else { 0.10 };
1556 let derived_soft = move |color: Color| color.with_alpha(soft_alpha).over(surface_raised);
1557 let derived_soft_text = |color: Color| {
1558 if is_dark {
1559 mix(color, Color::WHITE, 0.22)
1560 } else {
1561 mix(color, Color::BLACK, 0.12)
1562 }
1563 };
1564
1565 Self {
1566 text: colors.base_content,
1567 text_muted,
1568 placeholder,
1569 surface,
1570 surface_raised,
1571 control,
1572 control_hover,
1573 control_active,
1574 field,
1575 surface_hover: control_hover,
1576 surface_pressed: control_active,
1577 surface_focus: roles
1578 .map(|r| flatten(r.accent_soft))
1579 .unwrap_or_else(|| mix(control, colors.primary, if is_dark { 0.14 } else { 0.08 })),
1580 border,
1581 border_strong,
1582 border_hover,
1583 border_focus,
1584 focus,
1585 focus_ring: focus,
1586 caret: colors.primary,
1587 selection,
1588 accent: colors.primary,
1589 accent_hover: roles
1590 .map(|r| r.accent_hover)
1591 .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.08)),
1592 accent_pressed: interactive_variant(colors.primary, colors.scheme, 0.16),
1593 accent_border: roles
1594 .map(|r| flatten(r.accent_border))
1595 .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.12)),
1596 accent_border_hover: roles
1597 .map(|r| flatten(r.accent_border))
1598 .unwrap_or_else(|| interactive_variant(colors.primary, colors.scheme, 0.2)),
1599 accent_border_focus: colors.primary,
1600 accent_text: colors.primary_content,
1601 accent_soft: roles
1602 .map(|r| flatten(r.accent_soft))
1603 .unwrap_or_else(|| derived_soft(colors.primary)),
1604 accent_soft_text: roles
1605 .map(|r| r.accent_text)
1606 .unwrap_or_else(|| derived_soft_text(colors.primary)),
1607 info: colors.info,
1608 info_text: colors.info_content,
1609 info_soft: roles
1610 .map(|r| flatten(r.info_soft))
1611 .unwrap_or_else(|| derived_soft(colors.info)),
1612 info_soft_text: roles
1613 .map(|r| r.info_text)
1614 .unwrap_or_else(|| derived_soft_text(colors.info)),
1615 success: colors.success,
1616 success_text: colors.success_content,
1617 success_soft: roles
1618 .map(|r| flatten(r.ok_soft))
1619 .unwrap_or_else(|| derived_soft(colors.success)),
1620 success_soft_text: roles
1621 .map(|r| r.ok_text)
1622 .unwrap_or_else(|| derived_soft_text(colors.success)),
1623 warning: colors.warning,
1624 warning_text: colors.warning_content,
1625 warning_soft: roles
1626 .map(|r| flatten(r.warn_soft))
1627 .unwrap_or_else(|| derived_soft(colors.warning)),
1628 warning_soft_text: roles
1629 .map(|r| r.warn_text)
1630 .unwrap_or_else(|| derived_soft_text(colors.warning)),
1631 danger: colors.error,
1632 danger_text: colors.error_content,
1633 danger_soft: roles
1634 .map(|r| flatten(r.danger_soft))
1635 .unwrap_or_else(|| derived_soft(colors.error)),
1636 danger_soft_text: roles
1637 .map(|r| r.danger_text)
1638 .unwrap_or_else(|| derived_soft_text(colors.error)),
1639 danger_hover: roles
1640 .map(|r| r.danger_hover)
1641 .unwrap_or_else(|| interactive_variant(colors.error, colors.scheme, 0.08)),
1642 }
1643 }
1644}
1645
1646impl Default for ControlPalette {
1647 fn default() -> Self {
1648 Self::from_colors(&ThemeColors::default())
1649 }
1650}
1651
1652#[derive(Debug, Clone, Copy, PartialEq)]
1653pub struct SurfacePalette {
1654 pub dark: bool,
1655 pub window: Color,
1656 pub window_subtle: Color,
1659 pub sidebar: Color,
1660 pub panel: Color,
1661 pub surface_2: Color,
1663 pub surface_3: Color,
1666 pub overlay: Color,
1668 pub titlebar: Color,
1669 pub field: Color,
1670 pub border: Color,
1671 pub border_strong: Color,
1672 pub border_subtle: Color,
1674 pub text: Color,
1675 pub text_muted: Color,
1676 pub text_faint: Color,
1677 pub text_disabled: Color,
1679 pub text_invert: Color,
1681 pub accent: Color,
1682 pub accent_hover: Color,
1683 pub on_accent: Color,
1684 pub accent_text: Color,
1686 pub accent_soft: Color,
1688 pub accent_border: Color,
1690 pub focus: Color,
1692 pub hover: Color,
1693 pub selected: Color,
1694 pub overlay_scrim: Color,
1695 pub tooltip: Color,
1696 pub tooltip_border: Color,
1697 pub tooltip_text: Color,
1698 pub canvas: Color,
1699 pub canvas_grid: Color,
1700 pub canvas_axis_x: Color,
1701 pub canvas_axis_y: Color,
1702 pub pixel_canvas_paper: Color,
1703 pub pixel_canvas_document_edge: Color,
1704 pub pixel_canvas_shadow_near: Color,
1705 pub pixel_canvas_shadow_far: Color,
1706 pub pixel_canvas_grid: Color,
1707 pub canvas_ruler: Color,
1708 pub canvas_ruler_border: Color,
1709 pub canvas_ruler_tick: Color,
1710 pub canvas_ruler_text: Color,
1711 pub checkerboard_light: Color,
1712 pub checkerboard_dark: Color,
1713 pub color_picker_chrome_border: Color,
1714 pub color_picker_plane_border: Color,
1715 pub color_picker_bar_border: Color,
1716 pub color_picker_marker_outer: Color,
1717 pub color_picker_marker_dark: Color,
1718 pub color_picker_marker_light: Color,
1719 pub color_picker_sdr_marker: Color,
1720 pub color_picker_hdr_divider: Color,
1721 pub good: Color,
1722 pub good_text: Color,
1724 pub good_soft: Color,
1726 pub warn: Color,
1727 pub warn_text: Color,
1729 pub warn_soft: Color,
1731 pub bad: Color,
1732 pub bad_text: Color,
1734 pub bad_soft: Color,
1736 pub info: Color,
1738 pub info_text: Color,
1740 pub info_soft: Color,
1742}
1743
1744impl SurfacePalette {
1745 pub fn from_theme_parts(colors: &ThemeColors, controls: &ControlPalette) -> Self {
1746 let dark = matches!(
1747 colors.scheme,
1748 ThemeColorScheme::Dark | ThemeColorScheme::HighContrast
1749 );
1750 let neutral = is_neutral_theme(colors);
1751 let roles = builtin_color_roles(colors);
1752 let text_muted = controls.text_muted;
1753 let text_faint = controls.placeholder;
1754 let window_subtle = roles
1755 .map(|r| r.bg_subtle)
1756 .unwrap_or_else(|| mix(controls.surface, controls.control, 0.4));
1757 let overlay = roles.map(|r| r.overlay).unwrap_or(controls.surface_raised);
1758
1759 Self {
1760 dark,
1761 window: controls.surface,
1762 window_subtle,
1763 sidebar: window_subtle,
1766 panel: controls.surface_raised,
1767 surface_2: controls.control,
1768 surface_3: controls.control_hover,
1769 overlay,
1770 titlebar: window_subtle,
1771 field: controls.field,
1772 border: controls.border,
1773 border_strong: controls.border_strong,
1774 border_subtle: roles
1775 .map(|r| r.border_subtle.over(controls.surface_raised))
1776 .unwrap_or_else(|| mix(controls.border, controls.surface_raised, 0.44)),
1777 text: controls.text,
1778 text_muted,
1779 text_faint,
1780 text_disabled: roles.map(|r| r.text_disabled).unwrap_or_else(|| {
1781 mix(
1782 controls.text,
1783 controls.surface,
1784 if dark { 0.62 } else { 0.44 },
1785 )
1786 }),
1787 text_invert: roles.map(|r| r.text_invert).unwrap_or(controls.surface),
1788 accent: controls.accent,
1789 accent_hover: controls.accent_hover,
1790 on_accent: controls.accent_text,
1791 accent_text: controls.accent_soft_text,
1792 accent_soft: controls.accent_soft,
1793 accent_border: controls.accent_border,
1794 focus: controls.focus,
1795 hover: controls.text.with_alpha(if dark { 0.06 } else { 0.045 }),
1796 selected: controls.selection,
1797 overlay_scrim: roles
1798 .map(|r| r.scrim)
1799 .unwrap_or_else(|| Color::rgba(0.06, 0.08, 0.12, if dark { 0.38 } else { 0.24 })),
1800 tooltip: overlay,
1803 tooltip_border: controls.border_strong,
1804 tooltip_text: text_muted,
1805 canvas: controls.surface,
1806 canvas_grid: controls.border.with_alpha(if dark { 0.30 } else { 0.18 }),
1807 canvas_axis_x: colors.error.with_alpha(if dark { 0.72 } else { 0.55 }),
1808 canvas_axis_y: colors.success.with_alpha(if dark { 0.72 } else { 0.55 }),
1809 pixel_canvas_paper: if dark {
1810 mix(controls.surface_raised, controls.text, 0.10)
1811 } else if neutral {
1812 rgb8(250, 250, 250)
1813 } else {
1814 Color::rgba(0.975, 0.980, 0.988, 1.0)
1815 },
1816 pixel_canvas_document_edge: controls.text.with_alpha(if dark { 0.82 } else { 0.72 }),
1817 pixel_canvas_shadow_near: if neutral {
1818 Color::BLACK.with_alpha(if dark { 0.30 } else { 0.16 })
1819 } else {
1820 Color::rgba(0.05, 0.07, 0.10, if dark { 0.30 } else { 0.16 })
1821 },
1822 pixel_canvas_shadow_far: if neutral {
1823 Color::BLACK.with_alpha(if dark { 0.18 } else { 0.08 })
1824 } else {
1825 Color::rgba(0.05, 0.07, 0.10, if dark { 0.18 } else { 0.08 })
1826 },
1827 pixel_canvas_grid: controls.text.with_alpha(if dark { 0.32 } else { 0.28 }),
1828 canvas_ruler: controls.surface_raised,
1829 canvas_ruler_border: controls.border.with_alpha(0.78),
1830 canvas_ruler_tick: controls.text_muted.with_alpha(0.72),
1831 canvas_ruler_text: controls.text.with_alpha(0.76),
1832 checkerboard_light: if dark {
1833 mix(controls.surface_raised, controls.text, 0.18)
1834 } else if neutral {
1835 rgb8(250, 250, 250)
1836 } else {
1837 Color::rgba(0.980, 0.980, 0.990, 1.0)
1838 },
1839 checkerboard_dark: if dark {
1840 mix(controls.surface_raised, controls.text, 0.10)
1841 } else if neutral {
1842 rgb8(229, 229, 229)
1843 } else {
1844 Color::rgba(0.900, 0.920, 0.950, 1.0)
1845 },
1846 color_picker_chrome_border: controls.text.with_alpha(if dark { 0.24 } else { 0.18 }),
1847 color_picker_plane_border: controls.text.with_alpha(if dark { 0.22 } else { 0.16 }),
1848 color_picker_bar_border: controls.text.with_alpha(if dark { 0.20 } else { 0.14 }),
1849 color_picker_marker_outer: controls.surface_raised.with_alpha(0.92),
1850 color_picker_marker_dark: Color::BLACK.with_alpha(0.84),
1851 color_picker_marker_light: Color::WHITE.with_alpha(0.95),
1852 color_picker_sdr_marker: controls.surface_raised.with_alpha(0.30),
1853 color_picker_hdr_divider: controls.surface_raised.with_alpha(0.28),
1854 good: colors.success,
1855 good_text: controls.success_soft_text,
1856 good_soft: controls.success_soft,
1857 warn: colors.warning,
1858 warn_text: controls.warning_soft_text,
1859 warn_soft: controls.warning_soft,
1860 bad: colors.error,
1861 bad_text: controls.danger_soft_text,
1862 bad_soft: controls.danger_soft,
1863 info: colors.info,
1864 info_text: controls.info_soft_text,
1865 info_soft: controls.info_soft,
1866 }
1867 }
1868}
1869
1870impl Default for SurfacePalette {
1871 fn default() -> Self {
1872 let colors = ThemeColors::default();
1873 let controls = ControlPalette::from_colors(&colors);
1874 Self::from_theme_parts(&colors, &controls)
1875 }
1876}
1877
1878#[derive(Debug, Clone, Copy, PartialEq)]
1879pub struct ControlTypography {
1880 pub body_font_size: f32,
1881 pub body_line_height: f32,
1882}
1883
1884impl ControlTypography {
1885 pub fn from_text_scale(text: &ThemeTextScale) -> Self {
1886 Self::for_density(text, ThemeDensity::default())
1887 }
1888
1889 pub fn for_density(text: &ThemeTextScale, density: ThemeDensity) -> Self {
1893 let token = match density {
1894 ThemeDensity::Compact | ThemeDensity::Comfortable => text.base,
1895 ThemeDensity::Touch => text.lg,
1896 };
1897 Self {
1898 body_font_size: token.size,
1899 body_line_height: token.line_height,
1900 }
1901 }
1902
1903 pub fn for_size(text: &ThemeTextScale, size: ControlSize) -> Self {
1907 let token = match size {
1908 ControlSize::Small => text.sm,
1909 ControlSize::Medium => text.base,
1910 ControlSize::Large => text.lg,
1911 };
1912 Self {
1913 body_font_size: token.size,
1914 body_line_height: token.line_height,
1915 }
1916 }
1917}
1918
1919impl Default for ControlTypography {
1920 fn default() -> Self {
1921 Self::from_text_scale(&ThemeTextScale::default())
1922 }
1923}
1924
1925#[derive(Debug, Clone, Copy, PartialEq)]
1926pub struct ControlStateMetrics {
1927 pub hover_blend: f32,
1928 pub pressed_blend: f32,
1929 pub selected_blend: f32,
1930 pub tab_selected_blend: f32,
1931 pub disabled_opacity: f32,
1932 pub disabled_content_opacity: f32,
1933 pub pressed_offset: f32,
1934 pub active_indicator_thickness: f32,
1935}
1936
1937impl ControlStateMetrics {
1938 pub fn for_density(density: ThemeDensity) -> Self {
1939 match density {
1940 ThemeDensity::Compact => Self {
1941 hover_blend: 0.78,
1942 pressed_blend: 0.88,
1943 selected_blend: 0.20,
1944 tab_selected_blend: 0.07,
1945 disabled_opacity: 0.70,
1946 disabled_content_opacity: 0.46,
1947 pressed_offset: 0.0,
1948 active_indicator_thickness: 2.0,
1949 },
1950 ThemeDensity::Comfortable => Self {
1951 hover_blend: 0.86,
1952 pressed_blend: 1.0,
1953 selected_blend: 0.22,
1954 tab_selected_blend: 0.08,
1955 disabled_opacity: 0.74,
1956 disabled_content_opacity: 0.50,
1957 pressed_offset: 0.0,
1958 active_indicator_thickness: 3.0,
1959 },
1960 ThemeDensity::Touch => Self {
1961 hover_blend: 0.94,
1962 pressed_blend: 1.0,
1963 selected_blend: 0.24,
1964 tab_selected_blend: 0.09,
1965 disabled_opacity: 0.78,
1966 disabled_content_opacity: 0.54,
1967 pressed_offset: 0.0,
1968 active_indicator_thickness: 4.0,
1969 },
1970 }
1971 }
1972}
1973
1974impl Default for ControlStateMetrics {
1975 fn default() -> Self {
1976 Self::for_density(ThemeDensity::default())
1977 }
1978}
1979
1980#[derive(Debug, Clone, Copy, PartialEq)]
1981pub struct ControlMetrics {
1982 pub min_height: f32,
1983 pub touch_target_size: f32,
1984 pub button_min_width: f32,
1985 pub button_padding: Insets,
1986 pub checkbox_padding: Insets,
1987 pub checkbox_indicator_size: f32,
1988 pub checkbox_gap: f32,
1989 pub icon_label_gap: f32,
1990 pub separator_thickness: f32,
1991 pub icon_size: f32,
1992 pub icon_button_size: f32,
1993 pub switch_track_width: f32,
1994 pub switch_track_height: f32,
1995 pub switch_thumb_inset: f32,
1996 pub slider_min_width: f32,
1997 pub slider_padding: Insets,
1998 pub slider_track_height: f32,
1999 pub slider_thumb_size: f32,
2000 pub number_input_stepper_width: f32,
2001 pub text_input_min_width: f32,
2002 pub text_input_padding: Insets,
2003 pub text_area_min_height: f32,
2004 pub select_menu_max_height: f32,
2005 pub select_menu_gap: f32,
2006 pub select_menu_edge_padding: f32,
2007 pub tab_height: f32,
2008 pub tab_min_width: f32,
2009 pub tab_gap: f32,
2010 pub tab_padding: Insets,
2011 pub tab_panel_padding: Insets,
2012 pub tab_panel_gap: f32,
2013 pub menu_row_height: f32,
2014 pub menu_padding: Insets,
2015 pub menu_item_padding: Insets,
2016 pub menu_shortcut_width: f32,
2017 pub popover_padding: Insets,
2018 pub popover_gap: f32,
2019 pub popover_reveal_offset: f32,
2020 pub tooltip_padding: Insets,
2021 pub tooltip_min_width: f32,
2022 pub tooltip_gap: f32,
2023 pub tooltip_reveal_offset: f32,
2024 pub dialog_min_width: f32,
2025 pub dialog_max_width: f32,
2026 pub dialog_outer_margin: f32,
2027 pub dialog_padding: Insets,
2028 pub dialog_title_font_size: f32,
2029 pub dialog_title_line_height: f32,
2030 pub dialog_description_gap: f32,
2031 pub dialog_body_gap: f32,
2032 pub dialog_footer_gap: f32,
2033 pub dialog_action_gap: f32,
2034 pub dialog_action_min_width: f32,
2035 pub toolbar_extent: f32,
2036 pub toolbar_padding: Insets,
2037 pub toolbar_spacing: f32,
2038 pub command_group_padding: Insets,
2039 pub command_group_spacing: f32,
2040 pub command_group_radius: f32,
2041 pub tool_palette_item_size: f32,
2042 pub tool_palette_icon_size: f32,
2043 pub preset_strip_item_height: f32,
2044 pub preset_strip_item_min_width: f32,
2045 pub preset_strip_item_padding: Insets,
2046 pub preset_strip_gap: f32,
2047 pub preset_strip_label_padding: Insets,
2048 pub action_card_min_width: f32,
2049 pub action_card_min_height: f32,
2050 pub action_card_padding: Insets,
2051 pub action_card_icon_box_size: f32,
2052 pub action_card_icon_size: f32,
2053 pub action_card_icon_gap: f32,
2054 pub action_card_text_gap: f32,
2055 pub action_card_trailing_gap: f32,
2056 pub action_card_chevron_size: f32,
2057 pub action_card_accent_width: f32,
2058 pub action_card_accent_inset: f32,
2059 pub status_bar_height: f32,
2060 pub status_bar_segment_padding: f32,
2061 pub status_bar_segment_min_width: f32,
2062 pub status_bar_separator_inset: f32,
2063 pub progress_bar_min_width: f32,
2064 pub progress_bar_height: f32,
2065 pub progress_bar_value_height: f32,
2066 pub progress_bar_label_padding: Insets,
2067 pub property_row_label_width: f32,
2068 pub property_row_inline_gap: f32,
2069 pub property_row_stacked_gap: f32,
2070 pub form_row_label_width: f32,
2071 pub form_row_control_width: f32,
2072 pub form_row_gap: f32,
2073 pub field_group_spacing: f32,
2074 pub form_section_padding: Insets,
2075 pub form_section_body_gap: f32,
2076 pub form_section_header_gap: f32,
2077 pub form_section_description_gap: f32,
2078 pub form_section_max_width: f32,
2079 pub form_section_radius: f32,
2080 pub panel_section_gap: f32,
2081 pub panel_section_action_gap: f32,
2082 pub panel_section_disclosure_size: f32,
2083 pub dock_panel_header_height: f32,
2084 pub dock_panel_padding: Insets,
2085 pub data_viewport_padding: Insets,
2086 pub data_row_padding: Insets,
2087 pub data_row_icon_size: f32,
2088 pub data_row_icon_gap: f32,
2089 pub data_row_trailing_gap: f32,
2090 pub data_scroll_thumb_width: f32,
2091 pub data_scroll_thumb_inset: f32,
2092 pub data_scroll_thumb_radius: f32,
2093 pub data_scroll_thumb_min_length: f32,
2094 pub data_scroll_thumb_opacity: f32,
2095 pub list_row_height: f32,
2096 pub layer_row_height: f32,
2097 pub layer_action_size: f32,
2098 pub layer_action_icon_inset: f32,
2099 pub layer_lock_icon_inset: f32,
2100 pub layer_visibility_stroke_width: f32,
2101 pub layer_visibility_slash_stroke_width: f32,
2102 pub layer_thumbnail_size: f32,
2103 pub layer_thumbnail_inset: f32,
2104 pub layer_thumbnail_radius: f32,
2105 pub layer_thumbnail_disabled_opacity: f32,
2106 pub layer_thumbnail_disabled_border_opacity: f32,
2107 pub tree_row_height: f32,
2108 pub tree_indent: f32,
2109 pub tree_disclosure_size: f32,
2110 pub tree_disclosure_gap: f32,
2111 pub table_row_height: f32,
2112 pub table_header_height: f32,
2113 pub table_cell_padding: f32,
2114 pub table_header_separator_inset: f32,
2115 pub table_separator_width: f32,
2116 pub table_row_border_opacity: f32,
2117 pub breadcrumb_height: f32,
2118 pub breadcrumb_item_padding: Insets,
2119 pub breadcrumb_gap: f32,
2120 pub breadcrumb_separator_size: f32,
2121 pub image_corner_radius: f32,
2122 pub color_swatch_width: f32,
2123 pub color_swatch_height: f32,
2124 pub color_swatch_inner_inset: f32,
2125 pub color_swatch_checker_size: f32,
2126 pub color_palette_swatch_size: f32,
2127 pub color_palette_gap: f32,
2128 pub color_palette_swatch_inset: f32,
2129 pub color_palette_selected_swatch_inset: f32,
2130 pub color_palette_checker_size: f32,
2131 pub brush_preview_min_width: f32,
2132 pub brush_preview_min_height: f32,
2133 pub brush_preview_padding: Insets,
2134 pub brush_preview_swatch_width: f32,
2135 pub brush_preview_swatch_gap: f32,
2136 pub brush_preview_checker_size: f32,
2137 pub brush_preview_text_height: f32,
2138 pub brush_preview_text_font_size: f32,
2139 pub brush_preview_text_line_height: f32,
2140 pub color_picker_content_inset: f32,
2141 pub color_picker_panel_gap: f32,
2142 pub color_picker_top_bar_height: f32,
2143 pub color_picker_swatch_width: f32,
2144 pub color_picker_swatch_gap: f32,
2145 pub color_picker_section_gap: f32,
2146 pub color_picker_wheel_size: f32,
2147 pub color_picker_map_size: f32,
2148 pub color_picker_row_height: f32,
2149 pub color_picker_row_gap: f32,
2150 pub color_picker_right_panel_width: f32,
2151 pub color_picker_field_height: f32,
2152 pub color_picker_field_gap: f32,
2153 pub color_picker_dropdown_gap: f32,
2154 pub color_picker_encoding_menu_row_height: f32,
2155 pub scroll_bar_thickness: f32,
2156 pub scroll_bar_min_thumb_length: f32,
2157 pub split_view_divider_thickness: f32,
2158 pub split_view_drag_target_thickness: f32,
2159 pub floating_workspace_margin: f32,
2160 pub floating_view_title_bar_height: f32,
2161 pub floating_view_title_padding: Insets,
2162 pub floating_view_resize_handle_size: f32,
2163 pub canvas_ruler_extent: f32,
2164 pub canvas_ruler_major_tick: f32,
2165 pub canvas_ruler_minor_tick: f32,
2166 pub canvas_ruler_target_major_spacing: f32,
2167 pub canvas_ruler_label_padding: Insets,
2168 pub canvas_ruler_label_max_width: f32,
2169 pub canvas_grid_step: f32,
2170 pub canvas_axis_overscan: f32,
2171 pub pixel_canvas_fit_padding: f32,
2172 pub pixel_canvas_grid_zoom: f32,
2173 pub pixel_canvas_nearest_sampling_zoom: f32,
2174 pub pixel_canvas_zoom_step: f32,
2175 pub corner_radius: f32,
2176 pub indicator_corner_radius: f32,
2177 pub border_width: f32,
2178 pub focus_ring_width: f32,
2179 pub focus_ring_outset: f32,
2180 pub caret_width: f32,
2181}
2182
2183impl ControlMetrics {
2184 pub fn from_tokens(spacing: f32, radius: ThemeRadii, density: ThemeDensity) -> Self {
2185 let unit = spacing.max(1.0);
2186 let (
2187 min_height,
2188 touch_target_size,
2189 button_padding,
2190 checkbox_padding,
2191 checkbox_indicator_size,
2192 icon_size,
2193 icon_button_size,
2194 switch_track_width,
2195 switch_track_height,
2196 switch_thumb_inset,
2197 slider_min_width,
2198 slider_padding,
2199 slider_track_height,
2200 slider_thumb_size,
2201 number_input_stepper_width,
2202 text_input_min_width,
2203 text_input_padding,
2204 text_area_min_height,
2205 select_menu_max_height,
2206 tab_height,
2207 tab_min_width,
2208 tab_padding,
2209 tab_panel_padding,
2210 tab_panel_gap,
2211 menu_row_height,
2212 menu_padding,
2213 menu_item_padding,
2214 popover_padding,
2215 action_card_min_width,
2216 action_card_min_height,
2217 action_card_padding,
2218 action_card_icon_box_size,
2219 action_card_icon_size,
2220 action_card_icon_gap,
2221 action_card_text_gap,
2222 action_card_trailing_gap,
2223 action_card_chevron_size,
2224 action_card_accent_width,
2225 action_card_accent_inset,
2226 status_bar_height,
2227 status_bar_segment_padding,
2228 status_bar_segment_min_width,
2229 status_bar_separator_inset,
2230 progress_bar_min_width,
2231 progress_bar_height,
2232 progress_bar_value_height,
2233 progress_bar_label_padding,
2234 data_viewport_padding,
2235 data_row_padding,
2236 data_row_icon_size,
2237 data_row_icon_gap,
2238 data_row_trailing_gap,
2239 list_row_height,
2240 layer_row_height,
2241 layer_action_size,
2242 layer_thumbnail_size,
2243 tree_row_height,
2244 tree_indent,
2245 tree_disclosure_size,
2246 tree_disclosure_gap,
2247 table_row_height,
2248 table_header_height,
2249 table_cell_padding,
2250 breadcrumb_height,
2251 breadcrumb_item_padding,
2252 breadcrumb_gap,
2253 breadcrumb_separator_size,
2254 ) = match density {
2255 ThemeDensity::Compact => (
2256 28.0,
2257 28.0,
2258 Insets {
2259 left: unit * 1.5,
2260 top: unit * 0.75,
2261 right: unit * 1.5,
2262 bottom: unit * 0.75,
2263 },
2264 Insets {
2265 left: unit,
2266 top: unit * 0.5,
2267 right: unit,
2268 bottom: unit * 0.5,
2269 },
2270 15.0,
2271 14.0,
2272 28.0,
2273 32.0,
2274 19.0,
2275 3.0,
2276 120.0,
2277 Insets {
2278 left: unit * 1.5,
2279 top: unit * 0.5,
2280 right: unit * 1.5,
2281 bottom: unit * 0.5,
2282 },
2283 4.0,
2284 14.0,
2285 22.0,
2286 150.0,
2287 Insets {
2288 left: unit * 2.0,
2289 top: unit * 0.75,
2290 right: unit * 2.0,
2291 bottom: unit * 0.75,
2292 },
2293 56.0,
2294 176.0,
2295 32.0,
2296 84.0,
2297 Insets {
2298 left: unit * 2.5,
2299 top: unit * 0.75,
2300 right: unit * 2.5,
2301 bottom: unit * 0.75,
2302 },
2303 Insets::all(unit * 3.0),
2304 unit * 2.0,
2305 28.0,
2306 Insets::all(unit),
2307 Insets {
2308 left: unit * 2.0,
2309 top: unit * 0.5,
2310 right: unit * 2.0,
2311 bottom: unit * 0.5,
2312 },
2313 Insets::all(unit * 2.5),
2314 252.0,
2315 84.0,
2316 Insets {
2317 left: unit * 3.0,
2318 top: unit * 2.5,
2319 right: unit * 2.5,
2320 bottom: unit * 2.5,
2321 },
2322 32.0,
2323 16.0,
2324 unit * 2.5,
2325 unit,
2326 18.0,
2327 14.0,
2328 2.0,
2329 unit * 2.0,
2330 34.0,
2331 unit * 2.0,
2332 72.0,
2333 unit * 1.25,
2334 180.0,
2335 14.0,
2336 22.0,
2337 Insets::all(unit * 0.5),
2338 Insets::all(unit * 1.5),
2339 Insets {
2340 left: unit * 3.0,
2341 top: unit * 0.5,
2342 right: unit * 2.0,
2343 bottom: unit * 0.5,
2344 },
2345 12.0,
2346 unit * 1.5,
2347 unit * 2.0,
2348 30.0,
2349 38.0,
2350 22.0,
2351 26.0,
2352 30.0,
2353 unit * 4.0,
2354 10.0,
2355 unit,
2356 30.0,
2357 28.0,
2358 unit * 2.5,
2359 28.0,
2360 Insets {
2361 left: unit * 2.0,
2362 top: unit * 0.75,
2363 right: unit * 2.0,
2364 bottom: unit * 0.75,
2365 },
2366 unit * 4.0,
2367 9.0,
2368 ),
2369 ThemeDensity::Comfortable => (
2370 32.0,
2371 36.0,
2372 Insets {
2373 left: unit * 2.0,
2374 top: unit * 1.25,
2375 right: unit * 2.0,
2376 bottom: unit * 1.25,
2377 },
2378 Insets {
2379 left: unit * 1.5,
2380 top: unit,
2381 right: unit * 1.5,
2382 bottom: unit,
2383 },
2384 15.0,
2385 16.0,
2386 32.0,
2387 32.0,
2388 19.0,
2389 3.0,
2390 140.0,
2391 Insets {
2392 left: unit * 2.0,
2393 top: unit,
2394 right: unit * 2.0,
2395 bottom: unit,
2396 },
2397 4.0,
2398 14.0,
2399 24.0,
2400 180.0,
2401 Insets {
2402 left: unit * 2.0,
2403 top: unit * 1.25,
2404 right: unit * 2.0,
2405 bottom: unit * 1.25,
2406 },
2407 64.0,
2408 200.0,
2409 36.0,
2410 96.0,
2411 Insets {
2412 left: unit * 2.5,
2413 top: unit,
2414 right: unit * 2.5,
2415 bottom: unit,
2416 },
2417 Insets::all(unit * 4.0),
2418 unit * 3.0,
2419 32.0,
2420 Insets::all(unit * 1.5),
2421 Insets {
2422 left: unit * 3.0,
2423 top: unit,
2424 right: unit * 3.0,
2425 bottom: unit,
2426 },
2427 Insets::all(unit * 3.5),
2428 280.0,
2429 104.0,
2430 Insets {
2431 left: unit * 4.0,
2432 top: unit * 3.5,
2433 right: unit * 3.5,
2434 bottom: unit * 3.5,
2435 },
2436 38.0,
2437 20.0,
2438 unit * 3.0,
2439 unit * 1.25,
2440 22.0,
2441 16.0,
2442 3.0,
2443 unit * 2.5,
2444 40.0,
2445 unit * 2.5,
2446 86.0,
2447 unit * 1.5,
2448 240.0,
2449 18.0,
2450 18.0,
2451 Insets::all(unit * 0.5),
2452 Insets::all(unit * 2.0),
2453 Insets {
2454 left: 14.0,
2455 top: unit,
2456 right: 10.0,
2457 bottom: unit,
2458 },
2459 14.0,
2460 unit * 2.0,
2461 unit * 3.0,
2462 36.0,
2463 40.0,
2464 26.0,
2465 34.0,
2466 36.0,
2467 18.0,
2468 12.0,
2469 6.0,
2470 36.0,
2471 34.0,
2472 unit * 2.5,
2473 36.0,
2474 Insets {
2475 left: unit * 2.0,
2476 top: unit,
2477 right: unit * 2.0,
2478 bottom: unit,
2479 },
2480 unit * 5.0,
2481 10.0,
2482 ),
2483 ThemeDensity::Touch => (
2484 36.0,
2485 44.0,
2486 Insets {
2487 left: unit * 2.5,
2488 top: unit * 1.5,
2489 right: unit * 2.5,
2490 bottom: unit * 1.5,
2491 },
2492 Insets {
2493 left: unit * 2.0,
2494 top: unit * 1.5,
2495 right: unit * 2.0,
2496 bottom: unit * 1.5,
2497 },
2498 15.0,
2499 18.0,
2500 36.0,
2501 32.0,
2502 19.0,
2503 3.0,
2504 160.0,
2505 Insets {
2506 left: unit * 2.5,
2507 top: unit * 1.5,
2508 right: unit * 2.5,
2509 bottom: unit * 1.5,
2510 },
2511 4.0,
2512 14.0,
2513 30.0,
2514 200.0,
2515 Insets {
2516 left: unit * 2.0,
2517 top: unit * 1.5,
2518 right: unit * 2.0,
2519 bottom: unit * 1.5,
2520 },
2521 72.0,
2522 230.0,
2523 40.0,
2524 104.0,
2525 Insets {
2526 left: unit * 2.5,
2527 top: unit * 1.5,
2528 right: unit * 2.5,
2529 bottom: unit * 1.5,
2530 },
2531 Insets::all(unit * 4.5),
2532 unit * 3.5,
2533 40.0,
2534 Insets::all(unit * 1.75),
2535 Insets {
2536 left: unit * 3.25,
2537 top: unit * 1.5,
2538 right: unit * 3.25,
2539 bottom: unit * 1.5,
2540 },
2541 Insets::all(unit * 4.0),
2542 300.0,
2543 112.0,
2544 Insets {
2545 left: unit * 4.5,
2546 top: unit * 4.0,
2547 right: unit * 4.0,
2548 bottom: unit * 4.0,
2549 },
2550 42.0,
2551 22.0,
2552 unit * 3.25,
2553 unit * 1.5,
2554 26.0,
2555 18.0,
2556 3.5,
2557 unit * 2.75,
2558 46.0,
2559 unit * 2.75,
2560 96.0,
2561 unit * 1.75,
2562 260.0,
2563 22.0,
2564 22.0,
2565 Insets::all(unit * 0.75),
2566 Insets::all(unit * 2.25),
2567 Insets {
2568 left: unit * 3.5,
2569 top: unit * 1.5,
2570 right: unit * 2.75,
2571 bottom: unit * 1.5,
2572 },
2573 16.0,
2574 unit * 2.25,
2575 unit * 3.5,
2576 40.0,
2577 44.0,
2578 32.0,
2579 38.0,
2580 40.0,
2581 22.0,
2582 14.0,
2583 unit * 1.5,
2584 40.0,
2585 38.0,
2586 unit * 2.5,
2587 40.0,
2588 Insets {
2589 left: unit * 2.5,
2590 top: unit * 1.5,
2591 right: unit * 2.5,
2592 bottom: unit * 1.5,
2593 },
2594 unit * 5.5,
2595 11.0,
2596 ),
2597 };
2598
2599 let (
2600 popover_reveal_offset,
2601 tooltip_padding,
2602 tooltip_min_width,
2603 tooltip_gap,
2604 tooltip_reveal_offset,
2605 dialog_min_width,
2606 dialog_max_width,
2607 dialog_outer_margin,
2608 dialog_padding,
2609 dialog_title_font_size,
2610 dialog_title_line_height,
2611 dialog_description_gap,
2612 dialog_body_gap,
2613 dialog_footer_gap,
2614 dialog_action_gap,
2615 dialog_action_min_width,
2616 ) = match density {
2617 ThemeDensity::Compact => (
2618 8.0,
2619 Insets {
2620 left: unit * 2.0,
2621 top: unit * 1.5,
2622 right: unit * 2.0,
2623 bottom: unit * 1.5,
2624 },
2625 80.0,
2626 unit * 2.0,
2627 6.0,
2628 240.0,
2629 440.0,
2630 unit * 4.0,
2631 Insets::all(unit * 3.5),
2632 16.0,
2633 24.0,
2634 unit * 1.5,
2635 unit * 3.0,
2636 unit * 3.5,
2637 unit * 2.0,
2638 92.0,
2639 ),
2640 ThemeDensity::Comfortable => (
2641 10.0,
2642 Insets {
2643 left: unit * 2.25,
2644 top: unit * 2.25,
2645 right: unit * 2.25,
2646 bottom: unit * 2.25,
2647 },
2648 96.0,
2649 unit * 2.5,
2650 8.0,
2651 280.0,
2652 520.0,
2653 unit * 6.0,
2654 Insets::all(18.0),
2655 16.0,
2656 24.0,
2657 unit * 2.0,
2658 14.0,
2659 18.0,
2660 unit * 2.5,
2661 110.0,
2662 ),
2663 ThemeDensity::Touch => (
2664 12.0,
2665 Insets {
2666 left: unit * 3.0,
2667 top: unit * 2.5,
2668 right: unit * 3.0,
2669 bottom: unit * 2.5,
2670 },
2671 112.0,
2672 unit * 3.0,
2673 10.0,
2674 320.0,
2675 600.0,
2676 unit * 8.0,
2677 Insets::all(unit * 6.0),
2678 18.0,
2679 26.0,
2680 unit * 2.5,
2681 unit * 4.5,
2682 unit * 5.0,
2683 unit * 3.0,
2684 128.0,
2685 ),
2686 };
2687
2688 let (
2689 layer_action_icon_inset,
2690 layer_lock_icon_inset,
2691 layer_visibility_stroke_width,
2692 layer_visibility_slash_stroke_width,
2693 layer_thumbnail_inset,
2694 layer_thumbnail_radius,
2695 layer_thumbnail_disabled_opacity,
2696 layer_thumbnail_disabled_border_opacity,
2697 ) = match density {
2698 ThemeDensity::Compact => (4.5, 3.5, 1.25, 1.45, 1.5, radius.md, 0.34, 0.52),
2699 ThemeDensity::Comfortable => (5.0, 4.0, 1.4, 1.6, 2.0, radius.md, 0.36, 0.55),
2700 ThemeDensity::Touch => (7.0, 6.0, 1.8, 2.0, 3.0, radius.lg, 0.40, 0.60),
2701 };
2702
2703 let (
2704 data_scroll_thumb_width,
2705 data_scroll_thumb_inset,
2706 data_scroll_thumb_radius,
2707 data_scroll_thumb_min_length,
2708 data_scroll_thumb_opacity,
2709 table_header_separator_inset,
2710 table_separator_width,
2711 table_row_border_opacity,
2712 ) = match density {
2713 ThemeDensity::Compact => (3.0, 5.0, radius.sm, 24.0, 0.68, 3.0, 1.0, 0.50),
2714 ThemeDensity::Comfortable => (4.0, 6.0, radius.sm, 28.0, 0.75, 4.0, 1.0, 0.55),
2715 ThemeDensity::Touch => (6.0, 8.0, radius.md, 44.0, 0.78, 8.0, 1.5, 0.60),
2716 };
2717
2718 let (
2719 toolbar_extent,
2720 toolbar_padding,
2721 toolbar_spacing,
2722 command_group_padding,
2723 command_group_spacing,
2724 command_group_radius,
2725 tool_palette_item_size,
2726 tool_palette_icon_size,
2727 preset_strip_item_height,
2728 preset_strip_item_min_width,
2729 preset_strip_item_padding,
2730 preset_strip_gap,
2731 preset_strip_label_padding,
2732 ) = match density {
2733 ThemeDensity::Compact => (
2734 40.0,
2735 Insets::all(unit * 1.5),
2736 unit * 1.5,
2737 Insets::all(unit * 0.25),
2738 unit * 0.5,
2739 radius.md,
2740 30.0,
2741 16.0,
2742 24.0,
2743 36.0,
2744 Insets {
2745 left: unit * 2.0,
2746 top: unit,
2747 right: unit * 2.0,
2748 bottom: unit,
2749 },
2750 unit,
2751 Insets::all(unit * 0.75),
2752 ),
2753 ThemeDensity::Comfortable => (
2754 52.0,
2755 Insets::all(unit * 2.0),
2756 unit * 2.0,
2757 Insets::all(unit * 0.5),
2758 unit * 0.75,
2759 radius.lg,
2760 40.0,
2761 20.0,
2762 28.0,
2763 44.0,
2764 Insets {
2765 left: unit * 3.0,
2766 top: unit,
2767 right: unit * 3.0,
2768 bottom: unit,
2769 },
2770 unit * 1.5,
2771 Insets::all(unit),
2772 ),
2773 ThemeDensity::Touch => (
2774 56.0,
2775 Insets::all(unit * 2.25),
2776 unit * 2.25,
2777 Insets::all(unit * 0.75),
2778 unit * 0.875,
2779 radius.xl,
2780 44.0,
2781 22.0,
2782 36.0,
2783 50.0,
2784 Insets {
2785 left: unit * 3.5,
2786 top: unit * 1.5,
2787 right: unit * 3.5,
2788 bottom: unit * 1.5,
2789 },
2790 unit * 1.75,
2791 Insets::all(unit * 1.5),
2792 ),
2793 };
2794
2795 let (
2796 property_row_label_width,
2797 property_row_inline_gap,
2798 property_row_stacked_gap,
2799 form_row_label_width,
2800 form_row_control_width,
2801 form_row_gap,
2802 field_group_spacing,
2803 form_section_padding,
2804 form_section_body_gap,
2805 form_section_header_gap,
2806 form_section_description_gap,
2807 form_section_max_width,
2808 form_section_radius,
2809 panel_section_gap,
2810 panel_section_action_gap,
2811 panel_section_disclosure_size,
2812 dock_panel_header_height,
2813 dock_panel_padding,
2814 ) = match density {
2815 ThemeDensity::Compact => (
2816 96.0,
2817 unit * 1.5,
2818 unit,
2819 112.0,
2820 300.0,
2821 unit * 2.0,
2822 unit * 1.5,
2823 Insets {
2824 left: unit * 2.5,
2825 top: unit * 2.0,
2826 right: unit * 2.5,
2827 bottom: unit * 2.5,
2828 },
2829 unit * 2.0,
2830 unit * 2.0,
2831 unit * 0.5,
2832 600.0,
2833 radius.md,
2834 unit * 1.5,
2835 unit,
2836 14.0,
2837 28.0,
2838 Insets {
2839 left: unit * 2.0,
2840 top: unit * 1.5,
2841 right: unit * 2.0,
2842 bottom: unit * 1.5,
2843 },
2844 ),
2845 ThemeDensity::Comfortable => (
2846 112.0,
2847 unit * 2.0,
2848 unit * 1.5,
2849 128.0,
2850 340.0,
2851 unit * 3.0,
2852 unit * 2.0,
2853 Insets {
2854 left: 14.0,
2855 top: unit * 3.0,
2856 right: 14.0,
2857 bottom: 14.0,
2858 },
2859 unit * 3.0,
2860 unit * 2.5,
2861 unit * 0.75,
2862 640.0,
2863 radius.lg,
2864 unit * 2.0,
2865 unit * 1.5,
2866 16.0,
2867 34.0,
2868 Insets {
2869 left: unit * 2.5,
2870 top: unit * 2.0,
2871 right: unit * 2.5,
2872 bottom: unit * 2.0,
2873 },
2874 ),
2875 ThemeDensity::Touch => (
2876 136.0,
2877 unit * 3.0,
2878 unit * 2.0,
2879 144.0,
2880 380.0,
2881 unit * 4.0,
2882 unit * 3.0,
2883 Insets {
2884 left: unit * 4.5,
2885 top: unit * 4.0,
2886 right: unit * 4.5,
2887 bottom: unit * 4.5,
2888 },
2889 unit * 4.0,
2890 unit * 3.0,
2891 unit,
2892 720.0,
2893 radius.xl,
2894 unit * 3.0,
2895 unit * 2.0,
2896 20.0,
2897 44.0,
2898 Insets {
2899 left: unit * 3.5,
2900 top: unit * 3.0,
2901 right: unit * 3.5,
2902 bottom: unit * 3.0,
2903 },
2904 ),
2905 };
2906
2907 let (
2908 image_corner_radius,
2909 color_swatch_width,
2910 color_swatch_height,
2911 color_swatch_inner_inset,
2912 color_swatch_checker_size,
2913 color_palette_swatch_size,
2914 color_palette_gap,
2915 color_palette_swatch_inset,
2916 color_palette_selected_swatch_inset,
2917 color_palette_checker_size,
2918 brush_preview_min_width,
2919 brush_preview_min_height,
2920 brush_preview_padding,
2921 brush_preview_swatch_width,
2922 brush_preview_swatch_gap,
2923 brush_preview_checker_size,
2924 brush_preview_text_height,
2925 brush_preview_text_font_size,
2926 brush_preview_text_line_height,
2927 color_picker_content_inset,
2928 color_picker_panel_gap,
2929 color_picker_top_bar_height,
2930 color_picker_swatch_width,
2931 color_picker_swatch_gap,
2932 color_picker_section_gap,
2933 color_picker_wheel_size,
2934 color_picker_map_size,
2935 color_picker_row_height,
2936 color_picker_row_gap,
2937 color_picker_right_panel_width,
2938 color_picker_field_height,
2939 color_picker_field_gap,
2940 color_picker_dropdown_gap,
2941 color_picker_encoding_menu_row_height,
2942 scroll_bar_thickness,
2943 scroll_bar_min_thumb_length,
2944 split_view_divider_thickness,
2945 split_view_drag_target_thickness,
2946 floating_workspace_margin,
2947 floating_view_title_bar_height,
2948 floating_view_title_padding,
2949 floating_view_resize_handle_size,
2950 canvas_ruler_extent,
2951 canvas_ruler_major_tick,
2952 canvas_ruler_minor_tick,
2953 canvas_ruler_target_major_spacing,
2954 canvas_ruler_label_padding,
2955 canvas_ruler_label_max_width,
2956 canvas_grid_step,
2957 canvas_axis_overscan,
2958 pixel_canvas_fit_padding,
2959 pixel_canvas_grid_zoom,
2960 pixel_canvas_nearest_sampling_zoom,
2961 pixel_canvas_zoom_step,
2962 ) = match density {
2963 ThemeDensity::Compact => (
2964 radius.md,
2965 48.0,
2966 28.0,
2967 1.0,
2968 5.0,
2969 24.0,
2970 unit * 1.25,
2971 2.0,
2972 3.0,
2973 5.0,
2974 220.0,
2975 58.0,
2976 Insets::all(unit * 1.5),
2977 46.0,
2978 unit * 2.0,
2979 5.0,
2980 15.0,
2981 10.0,
2982 13.0,
2983 unit * 3.0,
2984 unit * 2.5,
2985 40.0,
2986 64.0,
2987 unit * 2.0,
2988 14.0,
2989 128.0,
2990 132.0,
2991 24.0,
2992 unit * 2.0,
2993 150.0,
2994 28.0,
2995 12.0,
2996 unit,
2997 28.0,
2998 10.0,
2999 24.0,
3000 1.0,
3001 10.0,
3002 unit * 2.0,
3003 30.0,
3004 Insets {
3005 left: unit * 2.5,
3006 top: unit * 1.5,
3007 right: unit * 2.5,
3008 bottom: unit * 1.5,
3009 },
3010 16.0,
3011 20.0,
3012 9.0,
3013 4.0,
3014 84.0,
3015 Insets {
3016 left: unit * 0.5,
3017 top: unit * 0.5,
3018 right: unit * 0.5,
3019 bottom: unit * 0.5,
3020 },
3021 48.0,
3022 32.0,
3023 72.0,
3024 20.0,
3025 6.0,
3026 1.0,
3027 1.1,
3028 ),
3029 ThemeDensity::Comfortable => (
3030 radius.lg,
3031 56.0,
3032 32.0,
3033 1.0,
3034 6.0,
3035 28.0,
3036 unit * 1.5,
3037 2.0,
3038 3.0,
3039 5.0,
3040 260.0,
3041 70.0,
3042 Insets::all(unit * 2.0),
3043 54.0,
3044 unit * 2.5,
3045 6.0,
3046 16.0,
3047 11.0,
3048 14.0,
3049 14.0,
3050 14.0,
3051 52.0,
3052 96.0,
3053 unit * 2.5,
3054 14.0,
3055 166.0,
3056 210.0,
3057 24.0,
3058 unit * 2.0,
3059 226.0,
3060 30.0,
3061 12.0,
3062 unit,
3063 28.0,
3064 12.0,
3065 28.0,
3066 1.0,
3067 12.0,
3068 unit * 3.0,
3069 32.0,
3070 Insets {
3071 left: 14.0,
3072 top: unit * 2.0,
3073 right: 14.0,
3074 bottom: unit * 2.0,
3075 },
3076 18.0,
3077 22.0,
3078 10.0,
3079 5.0,
3080 96.0,
3081 Insets {
3082 left: unit * 0.75,
3083 top: unit * 0.5,
3084 right: unit * 0.75,
3085 bottom: unit * 0.5,
3086 },
3087 54.0,
3088 40.0,
3089 80.0,
3090 24.0,
3091 6.0,
3092 1.0,
3093 1.1,
3094 ),
3095 ThemeDensity::Touch => (
3096 radius.xl,
3097 72.0,
3098 44.0,
3099 1.5,
3100 8.0,
3101 40.0,
3102 unit * 2.0,
3103 3.0,
3104 4.0,
3105 7.0,
3106 320.0,
3107 88.0,
3108 Insets::all(unit * 3.0),
3109 72.0,
3110 unit * 3.5,
3111 8.0,
3112 18.0,
3113 12.0,
3114 16.0,
3115 unit * 4.5,
3116 unit * 4.5,
3117 64.0,
3118 112.0,
3119 unit * 3.0,
3120 18.0,
3121 210.0,
3122 240.0,
3123 44.0,
3124 unit * 3.0,
3125 280.0,
3126 44.0,
3127 16.0,
3128 unit * 2.0,
3129 44.0,
3130 18.0,
3131 44.0,
3132 2.0,
3133 44.0,
3134 unit * 4.5,
3135 52.0,
3136 Insets {
3137 left: unit * 4.5,
3138 top: unit * 3.5,
3139 right: unit * 4.5,
3140 bottom: unit * 3.5,
3141 },
3142 28.0,
3143 32.0,
3144 16.0,
3145 8.0,
3146 120.0,
3147 Insets::all(unit),
3148 72.0,
3149 48.0,
3150 96.0,
3151 32.0,
3152 6.0,
3153 1.0,
3154 1.1,
3155 ),
3156 };
3157
3158 Self {
3159 min_height,
3160 touch_target_size,
3161 button_min_width: 64.0,
3162 button_padding,
3163 checkbox_padding,
3164 checkbox_indicator_size,
3165 checkbox_gap: 6.0,
3166 icon_label_gap: 6.0,
3167 separator_thickness: 1.0,
3168 icon_size,
3169 icon_button_size,
3170 switch_track_width,
3171 switch_track_height,
3172 switch_thumb_inset,
3173 slider_min_width,
3174 slider_padding,
3175 slider_track_height,
3176 slider_thumb_size,
3177 number_input_stepper_width,
3178 text_input_min_width,
3179 text_input_padding,
3180 text_area_min_height,
3181 select_menu_max_height,
3182 select_menu_gap: 6.0,
3183 select_menu_edge_padding: 8.0,
3184 tab_height,
3185 tab_min_width,
3186 tab_gap: 6.0,
3187 tab_padding,
3188 tab_panel_padding,
3189 tab_panel_gap,
3190 menu_row_height,
3191 menu_padding,
3192 menu_item_padding,
3193 menu_shortcut_width: 108.0,
3194 popover_padding,
3195 popover_gap: unit * 2.0,
3196 popover_reveal_offset,
3197 tooltip_padding,
3198 tooltip_min_width,
3199 tooltip_gap,
3200 tooltip_reveal_offset,
3201 dialog_min_width,
3202 dialog_max_width,
3203 dialog_outer_margin,
3204 dialog_padding,
3205 dialog_title_font_size,
3206 dialog_title_line_height,
3207 dialog_description_gap,
3208 dialog_body_gap,
3209 dialog_footer_gap,
3210 dialog_action_gap,
3211 dialog_action_min_width,
3212 toolbar_extent,
3213 toolbar_padding,
3214 toolbar_spacing,
3215 command_group_padding,
3216 command_group_spacing,
3217 command_group_radius,
3218 tool_palette_item_size,
3219 tool_palette_icon_size,
3220 preset_strip_item_height,
3221 preset_strip_item_min_width,
3222 preset_strip_item_padding,
3223 preset_strip_gap,
3224 preset_strip_label_padding,
3225 action_card_min_width,
3226 action_card_min_height,
3227 action_card_padding,
3228 action_card_icon_box_size,
3229 action_card_icon_size,
3230 action_card_icon_gap,
3231 action_card_text_gap,
3232 action_card_trailing_gap,
3233 action_card_chevron_size,
3234 action_card_accent_width,
3235 action_card_accent_inset,
3236 status_bar_height,
3237 status_bar_segment_padding,
3238 status_bar_segment_min_width,
3239 status_bar_separator_inset,
3240 progress_bar_min_width,
3241 progress_bar_height,
3242 progress_bar_value_height,
3243 progress_bar_label_padding,
3244 property_row_label_width,
3245 property_row_inline_gap,
3246 property_row_stacked_gap,
3247 form_row_label_width,
3248 form_row_control_width,
3249 form_row_gap,
3250 field_group_spacing,
3251 form_section_padding,
3252 form_section_body_gap,
3253 form_section_header_gap,
3254 form_section_description_gap,
3255 form_section_max_width,
3256 form_section_radius,
3257 panel_section_gap,
3258 panel_section_action_gap,
3259 panel_section_disclosure_size,
3260 dock_panel_header_height,
3261 dock_panel_padding,
3262 data_viewport_padding,
3263 data_row_padding,
3264 data_row_icon_size,
3265 data_row_icon_gap,
3266 data_row_trailing_gap,
3267 data_scroll_thumb_width,
3268 data_scroll_thumb_inset,
3269 data_scroll_thumb_radius,
3270 data_scroll_thumb_min_length,
3271 data_scroll_thumb_opacity,
3272 list_row_height,
3273 layer_row_height,
3274 layer_action_size,
3275 layer_action_icon_inset,
3276 layer_lock_icon_inset,
3277 layer_visibility_stroke_width,
3278 layer_visibility_slash_stroke_width,
3279 layer_thumbnail_size,
3280 layer_thumbnail_inset,
3281 layer_thumbnail_radius,
3282 layer_thumbnail_disabled_opacity,
3283 layer_thumbnail_disabled_border_opacity,
3284 tree_row_height,
3285 tree_indent,
3286 tree_disclosure_size,
3287 tree_disclosure_gap,
3288 table_row_height,
3289 table_header_height,
3290 table_cell_padding,
3291 table_header_separator_inset,
3292 table_separator_width,
3293 table_row_border_opacity,
3294 breadcrumb_height,
3295 breadcrumb_item_padding,
3296 breadcrumb_gap,
3297 breadcrumb_separator_size,
3298 image_corner_radius,
3299 color_swatch_width,
3300 color_swatch_height,
3301 color_swatch_inner_inset,
3302 color_swatch_checker_size,
3303 color_palette_swatch_size,
3304 color_palette_gap,
3305 color_palette_swatch_inset,
3306 color_palette_selected_swatch_inset,
3307 color_palette_checker_size,
3308 brush_preview_min_width,
3309 brush_preview_min_height,
3310 brush_preview_padding,
3311 brush_preview_swatch_width,
3312 brush_preview_swatch_gap,
3313 brush_preview_checker_size,
3314 brush_preview_text_height,
3315 brush_preview_text_font_size,
3316 brush_preview_text_line_height,
3317 color_picker_content_inset,
3318 color_picker_panel_gap,
3319 color_picker_top_bar_height,
3320 color_picker_swatch_width,
3321 color_picker_swatch_gap,
3322 color_picker_section_gap,
3323 color_picker_wheel_size,
3324 color_picker_map_size,
3325 color_picker_row_height,
3326 color_picker_row_gap,
3327 color_picker_right_panel_width,
3328 color_picker_field_height,
3329 color_picker_field_gap,
3330 color_picker_dropdown_gap,
3331 color_picker_encoding_menu_row_height,
3332 scroll_bar_thickness,
3333 scroll_bar_min_thumb_length,
3334 split_view_divider_thickness,
3335 split_view_drag_target_thickness,
3336 floating_workspace_margin,
3337 floating_view_title_bar_height,
3338 floating_view_title_padding,
3339 floating_view_resize_handle_size,
3340 canvas_ruler_extent,
3341 canvas_ruler_major_tick,
3342 canvas_ruler_minor_tick,
3343 canvas_ruler_target_major_spacing,
3344 canvas_ruler_label_padding,
3345 canvas_ruler_label_max_width,
3346 canvas_grid_step,
3347 canvas_axis_overscan,
3348 pixel_canvas_fit_padding,
3349 pixel_canvas_grid_zoom,
3350 pixel_canvas_nearest_sampling_zoom,
3351 pixel_canvas_zoom_step,
3352 corner_radius: match density {
3353 ThemeDensity::Compact | ThemeDensity::Comfortable => radius.md,
3354 ThemeDensity::Touch => radius.lg,
3355 },
3356 indicator_corner_radius: radius.sm + 1.0,
3357 border_width: 1.0,
3358 focus_ring_width: 2.0,
3359 focus_ring_outset: 2.0,
3361 caret_width: 2.0,
3362 }
3363 }
3364}
3365
3366impl Default for ControlMetrics {
3367 fn default() -> Self {
3368 Self::from_tokens(4.0, ThemeRadii::default(), ThemeDensity::default())
3369 }
3370}
3371
3372#[derive(Debug, Clone, Copy, PartialEq)]
3373pub struct DefaultTheme {
3374 pub fonts: ThemeFontFamilies,
3375 pub colors: ThemeColors,
3376 pub density: ThemeDensity,
3377 pub control_size: Option<ControlSize>,
3379 pub spacing: f32,
3380 pub breakpoints: ThemeBreakpoints,
3381 pub containers: ThemeContainers,
3382 pub text: ThemeTextScale,
3383 pub font_weights: ThemeFontWeights,
3384 pub tracking: ThemeTracking,
3385 pub leading: ThemeLeading,
3386 pub radius: ThemeRadii,
3387 pub shadows: ThemeShadows,
3388 pub glows: ThemeGlows,
3391 pub blur: ThemeBlurScale,
3392 pub perspective: ThemePerspective,
3393 pub aspect: ThemeAspectRatios,
3394 pub motion: ThemeMotion,
3395 pub hdr: HdrThemeTokens,
3396 pub palette: ControlPalette,
3397 pub surfaces: SurfacePalette,
3398 pub typography: ControlTypography,
3399 pub interaction: ControlStateMetrics,
3400 pub metrics: ControlMetrics,
3401}
3402
3403impl DefaultTheme {
3404 pub fn new() -> Self {
3405 Self::default()
3406 }
3407
3408 pub fn sui() -> Self {
3410 Self::light()
3411 }
3412
3413 pub fn light() -> Self {
3414 Self::from_colors(ThemeColors::light())
3415 }
3416
3417 pub fn neutral() -> Self {
3420 Self::from_colors(ThemeColors::neutral())
3421 }
3422
3423 pub fn neutral_dark() -> Self {
3425 Self::from_colors(ThemeColors::neutral_dark())
3426 }
3427
3428 pub fn dark() -> Self {
3429 Self::from_colors(ThemeColors::dark())
3430 }
3431
3432 pub fn high_contrast() -> Self {
3433 Self::from_colors(ThemeColors::high_contrast())
3434 }
3435
3436 pub fn void() -> Self {
3439 Self::high_contrast()
3440 }
3441
3442 pub fn compact() -> Self {
3443 Self::default().with_size(ControlSize::Small)
3444 }
3445
3446 pub fn comfortable() -> Self {
3447 Self::default().with_size(ControlSize::Medium)
3448 }
3449
3450 pub fn touch() -> Self {
3451 Self::default().with_size(ControlSize::Large)
3452 }
3453
3454 pub fn from_colors(colors: ThemeColors) -> Self {
3455 let text = ThemeTextScale::default();
3456 let radius = ThemeRadii::default();
3457 let spacing = 4.0;
3458 let density = ThemeDensity::default();
3459 let hdr = HdrThemeTokens::from_colors(colors);
3460 let palette = ControlPalette::from_colors(&colors);
3461 let surfaces = SurfacePalette::from_theme_parts(&colors, &palette);
3462
3463 let mut theme = Self {
3464 fonts: ThemeFontFamilies::default(),
3465 colors,
3466 density,
3467 control_size: Some(ControlSize::Medium),
3468 spacing,
3469 breakpoints: ThemeBreakpoints::default(),
3470 containers: ThemeContainers::default(),
3471 text,
3472 font_weights: ThemeFontWeights::default(),
3473 tracking: ThemeTracking::default(),
3474 leading: ThemeLeading::default(),
3475 radius,
3476 shadows: ThemeShadows::for_colors(&colors),
3477 glows: ThemeGlows::for_colors(&colors),
3478 blur: ThemeBlurScale::default(),
3479 perspective: ThemePerspective::default(),
3480 aspect: ThemeAspectRatios::default(),
3481 motion: ThemeMotion::default(),
3482 hdr,
3483 palette,
3484 surfaces,
3485 typography: ControlTypography::for_density(&text, density),
3486 interaction: ControlStateMetrics::for_density(density),
3487 metrics: ControlMetrics::from_tokens(spacing, radius, density),
3488 };
3489 theme.sync_size_fields(ControlSize::Medium);
3490 theme
3491 }
3492
3493 pub fn with_density(mut self, density: ThemeDensity) -> Self {
3494 self.density = density;
3495 self.control_size = None;
3496 self.sync_density_fields();
3497 self
3498 }
3499
3500 pub fn with_size(mut self, size: ControlSize) -> Self {
3507 self.density = size.legacy_density();
3508 self.control_size = Some(size);
3509 self.sync_size_fields(size);
3510 self
3511 }
3512
3513 fn sync_size_fields(&mut self, size: ControlSize) {
3514 self.interaction = ControlStateMetrics::for_density(size.legacy_density());
3515 self.metrics =
3516 ControlMetrics::from_tokens(self.spacing, self.radius, size.legacy_density());
3517 self.metrics.min_height = size.control_height();
3518 self.metrics.touch_target_size = 44.0;
3519 self.metrics.icon_size = size.icon_size();
3520 self.metrics.icon_button_size = size.control_height();
3521 self.metrics.list_row_height = size.row_height();
3522 self.metrics.tree_row_height = size.row_height();
3523 self.metrics.table_row_height = size.row_height();
3524 self.metrics.menu_row_height = size.row_height();
3525 self.typography = ControlTypography::for_size(&self.text, size);
3526 }
3527
3528 fn sync_density_fields(&mut self) {
3529 if let Some(size) = self
3530 .control_size
3531 .filter(|size| size.legacy_density() == self.density)
3532 {
3533 self.sync_size_fields(size);
3534 return;
3535 }
3536 self.control_size = None;
3537 self.typography = ControlTypography::for_density(&self.text, self.density);
3538 self.interaction = ControlStateMetrics::for_density(self.density);
3539 self.metrics = ControlMetrics::from_tokens(self.spacing, self.radius, self.density);
3540 }
3541
3542 pub fn sync_derived_fields(&mut self) {
3543 self.hdr.sync_semantic_defaults(self.colors);
3544 self.palette = ControlPalette::from_colors(&self.colors);
3545 self.surfaces = SurfacePalette::from_theme_parts(&self.colors, &self.palette);
3546 self.shadows = ThemeShadows::for_colors(&self.colors);
3547 self.glows = ThemeGlows::for_colors(&self.colors);
3548 self.sync_density_fields();
3549 }
3550
3551 pub fn text_style(&self, color: Color) -> TextStyle {
3552 self.text_style_with_font_stack(color, self.fonts.sans)
3553 }
3554
3555 pub fn serif_text_style(&self, color: Color) -> TextStyle {
3557 self.text_style_with_font_stack(color, self.fonts.serif)
3558 }
3559
3560 pub fn mono_text_style(&self, color: Color) -> TextStyle {
3562 self.text_style_with_font_stack(color, self.fonts.mono)
3563 }
3564
3565 fn text_style_with_font_stack(&self, color: Color, fonts: ThemeFontStack) -> TextStyle {
3566 TextStyle {
3567 font_families: Some(fonts.into()),
3568 font_size: self.typography.body_font_size.max(1.0),
3569 line_height: self.typography.body_line_height.max(1.0),
3570 color,
3571 ..TextStyle::default()
3572 }
3573 }
3574
3575 pub fn semantic_tone_colors(&self, tone: SemanticTone) -> (Color, Color) {
3576 match tone {
3577 SemanticTone::Neutral => (self.palette.control, self.palette.text),
3578 SemanticTone::Accent => (self.palette.accent, self.palette.accent_text),
3579 SemanticTone::Info => (self.palette.info, self.palette.info_text),
3580 SemanticTone::Success => (self.palette.success, self.palette.success_text),
3581 SemanticTone::Warning => (self.palette.warning, self.palette.warning_text),
3582 SemanticTone::Danger => (self.palette.danger, self.palette.danger_text),
3583 }
3584 }
3585
3586 pub fn semantic_tone_color(&self, tone: SemanticTone) -> Color {
3587 self.semantic_tone_colors(tone).0
3588 }
3589
3590 pub fn semantic_tone_text_color(&self, tone: SemanticTone) -> Color {
3591 self.semantic_tone_colors(tone).1
3592 }
3593
3594 pub fn semantic_tone_soft_colors(&self, tone: SemanticTone) -> (Color, Color) {
3599 match tone {
3600 SemanticTone::Neutral => (self.palette.control_hover, self.palette.text_muted),
3601 SemanticTone::Accent => (self.palette.accent_soft, self.palette.accent_soft_text),
3602 SemanticTone::Info => (self.palette.info_soft, self.palette.info_soft_text),
3603 SemanticTone::Success => (self.palette.success_soft, self.palette.success_soft_text),
3604 SemanticTone::Warning => (self.palette.warning_soft, self.palette.warning_soft_text),
3605 SemanticTone::Danger => (self.palette.danger_soft, self.palette.danger_soft_text),
3606 }
3607 }
3608
3609 pub fn body_text_style(&self) -> TextStyle {
3610 self.text_style(self.palette.text)
3611 }
3612
3613 pub fn placeholder_text_style(&self) -> TextStyle {
3614 self.text_style(self.palette.placeholder)
3615 }
3616
3617 pub fn button_text_style(&self) -> TextStyle {
3618 self.text_style(self.palette.accent_text)
3619 }
3620}
3621
3622impl Default for DefaultTheme {
3623 fn default() -> Self {
3624 Self::sui()
3625 }
3626}
3627
3628fn mix(from: Color, to: Color, amount: f32) -> Color {
3629 let amount = amount.clamp(0.0, 1.0);
3630
3631 Color::new(
3632 from.space,
3633 from.red + (to.red - from.red) * amount,
3634 from.green + (to.green - from.green) * amount,
3635 from.blue + (to.blue - from.blue) * amount,
3636 from.alpha + (to.alpha - from.alpha) * amount,
3637 )
3638 .clamped()
3639}
3640
3641fn interactive_variant(color: Color, scheme: ThemeColorScheme, amount: f32) -> Color {
3642 match scheme {
3643 ThemeColorScheme::Light => mix(color, Color::BLACK, amount),
3644 ThemeColorScheme::Dark | ThemeColorScheme::HighContrast => mix(color, Color::WHITE, amount),
3645 }
3646}
3647
3648fn interactive_surface(color: Color, scheme: ThemeColorScheme, amount: f32) -> Color {
3649 match scheme {
3650 ThemeColorScheme::Light => mix(color, Color::BLACK, amount),
3651 ThemeColorScheme::Dark | ThemeColorScheme::HighContrast => mix(color, Color::WHITE, amount),
3652 }
3653}
3654
3655fn rgb8(red: u8, green: u8, blue: u8) -> Color {
3656 Color::rgba(
3657 f32::from(red) / 255.0,
3658 f32::from(green) / 255.0,
3659 f32::from(blue) / 255.0,
3660 1.0,
3661 )
3662}
3663
3664fn rgba8(red: u8, green: u8, blue: u8, alpha: f32) -> Color {
3665 rgb8(red, green, blue).with_alpha(alpha)
3666}
3667
3668fn is_neutral_theme(colors: &ThemeColors) -> bool {
3669 matches!(colors.name, "neutral" | "neutral-dark")
3670}
3671
3672fn shadow_layer(
3673 offset_x: f32,
3674 offset_y: f32,
3675 blur: f32,
3676 spread: f32,
3677 color: Color,
3678 inset: bool,
3679) -> ThemeShadowLayer {
3680 ThemeShadowLayer {
3681 offset_x,
3682 offset_y,
3683 blur,
3684 spread,
3685 color,
3686 inset,
3687 }
3688}
3689
3690#[cfg(test)]
3691mod tests {
3692 use super::{
3693 Color, ControlSize, DefaultTheme, SemanticTone, ThemeColorScheme, ThemeColors,
3694 ThemeDensity, ThemeShadow, rgb8, rgba8,
3695 };
3696 use crate::hdr_theme::HdrThemeMode;
3697
3698 #[test]
3699 fn default_theme_uses_body_text_scale_for_typography() {
3700 let theme = DefaultTheme::default();
3701
3702 assert_eq!(theme.typography.body_font_size, theme.text.base.size);
3703 assert_eq!(
3704 theme.typography.body_line_height,
3705 theme.text.base.line_height
3706 );
3707 assert_eq!(theme.typography.body_font_size, 15.0);
3708 assert_eq!(theme.typography.body_line_height, 22.0);
3709 assert_eq!(theme.control_size, Some(ControlSize::Medium));
3710 assert_eq!(theme.density, ThemeDensity::Comfortable);
3711 assert_eq!(theme.metrics.min_height, 32.0);
3712 assert_eq!(theme.metrics.touch_target_size, 44.0);
3713 assert_eq!(theme.metrics.icon_button_size, 32.0);
3714 assert_eq!(
3715 theme.body_text_style().font_families,
3716 Some(theme.fonts.sans.into())
3717 );
3718 assert_eq!(
3719 theme.serif_text_style(theme.palette.text).font_families,
3720 Some(theme.fonts.serif.into())
3721 );
3722 assert_eq!(
3723 theme.mono_text_style(theme.palette.text).font_families,
3724 Some(theme.fonts.mono.into())
3725 );
3726 }
3727
3728 #[test]
3729 fn density_presets_update_control_metrics_and_interactions() {
3730 let compact = DefaultTheme::compact();
3731 let comfortable = DefaultTheme::comfortable();
3732 let touch = DefaultTheme::touch();
3733
3734 assert_eq!(compact.density, ThemeDensity::Compact);
3735 assert_eq!(comfortable.density, ThemeDensity::Comfortable);
3736 assert_eq!(touch.density, ThemeDensity::Touch);
3737 assert!(compact.metrics.min_height < comfortable.metrics.min_height);
3738 assert!(comfortable.metrics.min_height < touch.metrics.min_height);
3739 assert!(compact.metrics.menu_row_height < comfortable.metrics.menu_row_height);
3740 assert!(comfortable.metrics.menu_row_height < touch.metrics.menu_row_height);
3741 assert!(compact.metrics.list_row_height < comfortable.metrics.list_row_height);
3742 assert!(comfortable.metrics.list_row_height < touch.metrics.list_row_height);
3743 assert!(compact.metrics.layer_row_height < comfortable.metrics.layer_row_height);
3744 assert!(comfortable.metrics.layer_row_height < touch.metrics.layer_row_height);
3745 assert!(
3746 compact.metrics.layer_action_icon_inset < comfortable.metrics.layer_action_icon_inset
3747 );
3748 assert!(
3749 comfortable.metrics.layer_action_icon_inset < touch.metrics.layer_action_icon_inset
3750 );
3751 assert!(
3752 compact.metrics.layer_visibility_stroke_width
3753 < comfortable.metrics.layer_visibility_stroke_width
3754 );
3755 assert!(
3756 comfortable.metrics.layer_visibility_stroke_width
3757 < touch.metrics.layer_visibility_stroke_width
3758 );
3759 assert!(compact.metrics.layer_thumbnail_inset < comfortable.metrics.layer_thumbnail_inset);
3760 assert!(comfortable.metrics.layer_thumbnail_inset < touch.metrics.layer_thumbnail_inset);
3761 assert!(
3762 compact.metrics.layer_thumbnail_radius <= comfortable.metrics.layer_thumbnail_radius
3763 );
3764 assert!(comfortable.metrics.layer_thumbnail_radius < touch.metrics.layer_thumbnail_radius);
3765 assert!(compact.metrics.table_row_height < comfortable.metrics.table_row_height);
3766 assert!(comfortable.metrics.table_row_height < touch.metrics.table_row_height);
3767 assert!(
3768 compact.metrics.data_scroll_thumb_width < comfortable.metrics.data_scroll_thumb_width
3769 );
3770 assert!(
3771 comfortable.metrics.data_scroll_thumb_width < touch.metrics.data_scroll_thumb_width
3772 );
3773 assert!(
3774 compact.metrics.data_scroll_thumb_min_length
3775 < comfortable.metrics.data_scroll_thumb_min_length
3776 );
3777 assert!(
3778 comfortable.metrics.data_scroll_thumb_min_length
3779 < touch.metrics.data_scroll_thumb_min_length
3780 );
3781 assert!(
3782 compact.metrics.table_header_separator_inset
3783 < comfortable.metrics.table_header_separator_inset
3784 );
3785 assert!(
3786 comfortable.metrics.table_header_separator_inset
3787 < touch.metrics.table_header_separator_inset
3788 );
3789 assert!(compact.metrics.breadcrumb_height < comfortable.metrics.breadcrumb_height);
3790 assert!(comfortable.metrics.breadcrumb_height < touch.metrics.breadcrumb_height);
3791 assert!(
3792 compact.metrics.action_card_min_height < comfortable.metrics.action_card_min_height
3793 );
3794 assert!(comfortable.metrics.action_card_min_height < touch.metrics.action_card_min_height);
3795 assert!(compact.metrics.status_bar_height < comfortable.metrics.status_bar_height);
3796 assert!(comfortable.metrics.status_bar_height < touch.metrics.status_bar_height);
3797 assert!(compact.metrics.progress_bar_height < comfortable.metrics.progress_bar_height);
3798 assert!(comfortable.metrics.progress_bar_height < touch.metrics.progress_bar_height);
3799 assert!(compact.metrics.tooltip_gap < comfortable.metrics.tooltip_gap);
3800 assert!(comfortable.metrics.tooltip_gap < touch.metrics.tooltip_gap);
3801 assert!(compact.metrics.tooltip_min_width < comfortable.metrics.tooltip_min_width);
3802 assert!(comfortable.metrics.tooltip_min_width < touch.metrics.tooltip_min_width);
3803 assert!(compact.metrics.popover_reveal_offset < comfortable.metrics.popover_reveal_offset);
3804 assert!(comfortable.metrics.popover_reveal_offset < touch.metrics.popover_reveal_offset);
3805 assert!(compact.metrics.dialog_max_width < comfortable.metrics.dialog_max_width);
3806 assert!(comfortable.metrics.dialog_max_width < touch.metrics.dialog_max_width);
3807 assert!(
3808 compact.metrics.dialog_action_min_width < comfortable.metrics.dialog_action_min_width
3809 );
3810 assert!(
3811 comfortable.metrics.dialog_action_min_width < touch.metrics.dialog_action_min_width
3812 );
3813 assert!(compact.metrics.toolbar_extent < comfortable.metrics.toolbar_extent);
3814 assert!(comfortable.metrics.toolbar_extent < touch.metrics.toolbar_extent);
3815 assert!(
3816 compact.metrics.tool_palette_item_size < comfortable.metrics.tool_palette_item_size
3817 );
3818 assert!(comfortable.metrics.tool_palette_item_size < touch.metrics.tool_palette_item_size);
3819 assert!(
3820 compact.metrics.preset_strip_item_height < comfortable.metrics.preset_strip_item_height
3821 );
3822 assert!(
3823 comfortable.metrics.preset_strip_item_height < touch.metrics.preset_strip_item_height
3824 );
3825 assert!(
3826 compact.metrics.property_row_label_width < comfortable.metrics.property_row_label_width
3827 );
3828 assert!(
3829 comfortable.metrics.property_row_label_width < touch.metrics.property_row_label_width
3830 );
3831 assert!(compact.metrics.form_row_gap < comfortable.metrics.form_row_gap);
3832 assert!(comfortable.metrics.form_row_gap < touch.metrics.form_row_gap);
3833 assert!(compact.metrics.field_group_spacing < comfortable.metrics.field_group_spacing);
3834 assert!(comfortable.metrics.field_group_spacing < touch.metrics.field_group_spacing);
3835 assert!(
3836 compact.metrics.form_section_max_width < comfortable.metrics.form_section_max_width
3837 );
3838 assert!(comfortable.metrics.form_section_max_width < touch.metrics.form_section_max_width);
3839 assert!(compact.metrics.panel_section_gap < comfortable.metrics.panel_section_gap);
3840 assert!(comfortable.metrics.panel_section_gap < touch.metrics.panel_section_gap);
3841 assert!(
3842 compact.metrics.dock_panel_header_height < comfortable.metrics.dock_panel_header_height
3843 );
3844 assert!(
3845 comfortable.metrics.dock_panel_header_height < touch.metrics.dock_panel_header_height
3846 );
3847 assert!(compact.metrics.tab_height < comfortable.metrics.tab_height);
3848 assert!(comfortable.metrics.tab_height < touch.metrics.tab_height);
3849 assert!(compact.metrics.scroll_bar_thickness < comfortable.metrics.scroll_bar_thickness);
3850 assert!(comfortable.metrics.scroll_bar_thickness < touch.metrics.scroll_bar_thickness);
3851 assert!(
3852 compact.metrics.scroll_bar_min_thumb_length
3853 < comfortable.metrics.scroll_bar_min_thumb_length
3854 );
3855 assert!(
3856 comfortable.metrics.scroll_bar_min_thumb_length
3857 < touch.metrics.scroll_bar_min_thumb_length
3858 );
3859 assert!(
3860 compact.metrics.split_view_drag_target_thickness
3861 < comfortable.metrics.split_view_drag_target_thickness
3862 );
3863 assert!(
3864 comfortable.metrics.split_view_drag_target_thickness
3865 < touch.metrics.split_view_drag_target_thickness
3866 );
3867 assert!(
3868 compact.metrics.floating_workspace_margin
3869 < comfortable.metrics.floating_workspace_margin
3870 );
3871 assert!(
3872 comfortable.metrics.floating_workspace_margin < touch.metrics.floating_workspace_margin
3873 );
3874 assert!(
3875 compact.metrics.floating_view_title_bar_height
3876 < comfortable.metrics.floating_view_title_bar_height
3877 );
3878 assert!(
3879 comfortable.metrics.floating_view_title_bar_height
3880 < touch.metrics.floating_view_title_bar_height
3881 );
3882 assert!(
3883 compact.metrics.floating_view_resize_handle_size
3884 < comfortable.metrics.floating_view_resize_handle_size
3885 );
3886 assert!(
3887 comfortable.metrics.floating_view_resize_handle_size
3888 < touch.metrics.floating_view_resize_handle_size
3889 );
3890 assert!(compact.metrics.canvas_ruler_extent < comfortable.metrics.canvas_ruler_extent);
3891 assert!(comfortable.metrics.canvas_ruler_extent < touch.metrics.canvas_ruler_extent);
3892 assert!(
3893 compact.metrics.canvas_ruler_label_max_width
3894 < comfortable.metrics.canvas_ruler_label_max_width
3895 );
3896 assert!(
3897 comfortable.metrics.canvas_ruler_label_max_width
3898 < touch.metrics.canvas_ruler_label_max_width
3899 );
3900 assert!(
3901 compact.metrics.canvas_ruler_target_major_spacing
3902 < comfortable.metrics.canvas_ruler_target_major_spacing
3903 );
3904 assert!(
3905 comfortable.metrics.canvas_ruler_target_major_spacing
3906 < touch.metrics.canvas_ruler_target_major_spacing
3907 );
3908 assert!(compact.metrics.canvas_grid_step < comfortable.metrics.canvas_grid_step);
3909 assert!(comfortable.metrics.canvas_grid_step < touch.metrics.canvas_grid_step);
3910 assert!(
3911 compact.metrics.pixel_canvas_fit_padding < comfortable.metrics.pixel_canvas_fit_padding
3912 );
3913 assert!(
3914 comfortable.metrics.pixel_canvas_fit_padding < touch.metrics.pixel_canvas_fit_padding
3915 );
3916 assert!(compact.metrics.icon_size < comfortable.metrics.icon_size);
3917 assert!(comfortable.metrics.icon_size < touch.metrics.icon_size);
3918 assert!(
3919 compact.interaction.tab_selected_blend < comfortable.interaction.tab_selected_blend
3920 );
3921 assert!(comfortable.interaction.tab_selected_blend < touch.interaction.tab_selected_blend);
3922 assert_eq!(compact.interaction.pressed_offset, 0.0);
3923 assert_eq!(comfortable.interaction.pressed_offset, 0.0);
3924 assert_eq!(touch.interaction.pressed_offset, 0.0);
3925 }
3926
3927 #[test]
3928 fn contextual_control_sizes_match_authored_geometry_and_typography() {
3929 assert_eq!(ControlSize::default(), ControlSize::Medium);
3930
3931 let base = DefaultTheme::default();
3932 let small = base.with_size(ControlSize::Small);
3933 let medium = base.with_size(ControlSize::Medium);
3934 let large = base.with_size(ControlSize::Large);
3935
3936 assert_eq!(small.density, ThemeDensity::Compact);
3937 assert_eq!(medium.density, ThemeDensity::Comfortable);
3938 assert_eq!(large.density, ThemeDensity::Touch);
3939 assert_eq!(small.metrics.min_height, 28.0);
3940 assert_eq!(medium.metrics.min_height, 32.0);
3941 assert_eq!(large.metrics.min_height, 40.0);
3942 assert_eq!(small.metrics.list_row_height, 30.0);
3943 assert_eq!(medium.metrics.list_row_height, 36.0);
3944 assert_eq!(large.metrics.list_row_height, 44.0);
3945 assert_eq!(small.metrics.touch_target_size, 44.0);
3946 assert_eq!(medium.metrics.touch_target_size, 44.0);
3947 assert_eq!(large.metrics.touch_target_size, 44.0);
3948 assert_eq!(small.typography.body_font_size, base.text.sm.size);
3949 assert_eq!(medium.typography.body_font_size, base.text.base.size);
3950 assert_eq!(large.typography.body_font_size, base.text.lg.size);
3951 assert_eq!(large.text, base.text);
3952 }
3953
3954 #[test]
3955 fn contextual_control_size_uses_the_callers_scaled_text_ramp() {
3956 let mut theme = DefaultTheme::default();
3957 theme.text.sm.size = 15.0;
3958 theme.text.base.size = 17.0;
3959 theme.text.lg.size = 19.0;
3960
3961 let small = theme.with_size(ControlSize::Small);
3962 let medium = theme.with_size(ControlSize::Medium);
3963 let large = theme.with_size(ControlSize::Large);
3964
3965 assert_eq!(small.typography.body_font_size, 15.0);
3966 assert_eq!(medium.typography.body_font_size, 17.0);
3967 assert_eq!(large.typography.body_font_size, 19.0);
3968 }
3969
3970 #[test]
3971 fn contextual_control_size_survives_derived_theme_refresh() {
3972 let mut theme = DefaultTheme::dark().with_size(ControlSize::Small);
3973 theme.text.sm.size = 14.5;
3974
3975 theme.sync_derived_fields();
3976
3977 assert_eq!(theme.control_size, Some(ControlSize::Small));
3978 assert_eq!(theme.metrics.min_height, 28.0);
3979 assert_eq!(theme.metrics.touch_target_size, 44.0);
3980 assert_eq!(theme.typography.body_font_size, 14.5);
3981 }
3982
3983 #[test]
3984 fn default_theme_initializes_hdr_tokens() {
3985 let theme = DefaultTheme::default();
3986
3987 assert_eq!(theme.hdr.mode, HdrThemeMode::Disabled);
3988 assert_eq!(theme.hdr.color_roles.surface.sdr, theme.colors.base_100);
3989 assert_eq!(theme.hdr.color_roles.accent.sdr, theme.colors.primary);
3990 assert_eq!(
3991 theme.hdr.color_roles.accent_text.sdr,
3992 theme.colors.primary_content
3993 );
3994 }
3995
3996 #[test]
3997 fn mesh_theme_colors_use_cyan_as_signal_accent_and_amber_as_warning() {
3998 let light = ThemeColors::light();
3999 assert_eq!(light.primary, rgb8(8, 124, 164));
4000 assert_eq!(light.accent, light.primary);
4001 assert_eq!(light.accent_content, light.primary_content);
4002 assert_eq!(light.secondary, rgb8(143, 125, 248));
4003 assert_eq!(light.warning, rgb8(220, 154, 16));
4004
4005 let dark = ThemeColors::dark();
4006 assert_eq!(dark.primary, rgb8(53, 210, 238));
4007 assert_eq!(dark.accent, dark.primary);
4008 assert_eq!(dark.accent_content, dark.primary_content);
4009 assert_eq!(dark.secondary, rgb8(143, 125, 248));
4010 assert_eq!(dark.base_300, rgb8(29, 36, 49));
4011 assert_eq!(dark.warning, rgb8(253, 176, 34));
4012
4013 let void = ThemeColors::high_contrast();
4014 assert_eq!(void.primary, rgb8(33, 199, 229));
4015 assert_eq!(void.accent, void.primary);
4016 assert_eq!(void.accent_content, void.primary_content);
4017 assert_eq!(void.base_100, Color::BLACK);
4018 assert_eq!(void.base_300, rgb8(19, 23, 34));
4019 }
4020
4021 #[test]
4022 fn neutral_themes_are_achromatic_professional_presets() {
4023 let light = DefaultTheme::neutral();
4024 let colors = light.colors;
4025
4026 assert_eq!(DefaultTheme::sui(), DefaultTheme::light());
4027 assert_eq!(ThemeColors::sui(), ThemeColors::light());
4028 assert_eq!(colors.name, "neutral");
4029 assert_eq!(colors.scheme, ThemeColorScheme::Light);
4030 assert_eq!(colors.primary, rgb8(23, 23, 23));
4031 assert_eq!(colors.primary_content, Color::WHITE);
4032 assert_eq!(colors.secondary, rgb8(64, 64, 64));
4033 assert_eq!(colors.accent, colors.primary);
4034 assert_eq!(light.palette.accent, colors.primary);
4035 assert_eq!(light.palette.control, rgb8(245, 245, 245));
4036 assert_eq!(light.palette.border, rgb8(229, 229, 229));
4037 assert_eq!(light.palette.focus, rgb8(64, 64, 64));
4038 assert_eq!(light.surfaces.window_subtle, rgb8(250, 250, 250));
4039 assert_eq!(light.surfaces.checkerboard_dark, rgb8(229, 229, 229));
4040 assert_eq!(light.hdr.color_roles.accent.wide_gamut, None);
4041 assert_eq!(light.hdr.color_roles.accent.hdr, None);
4042
4043 let shadow = light
4044 .shadows
4045 .box_shadow
4046 .xs
4047 .first
4048 .expect("neutral theme should retain restrained elevation");
4049 assert_eq!(shadow.color.red, shadow.color.green);
4050 assert_eq!(shadow.color.green, shadow.color.blue);
4051
4052 for color in [
4053 colors.base_100,
4054 colors.base_200,
4055 colors.base_300,
4056 colors.base_content,
4057 colors.primary,
4058 colors.secondary,
4059 colors.accent,
4060 light.palette.focus,
4061 light.palette.selection,
4062 ] {
4063 assert_eq!(color.red, color.green);
4064 assert_eq!(color.green, color.blue);
4065 }
4066
4067 let dark = DefaultTheme::neutral_dark();
4068 let dark_colors = dark.colors;
4069 assert_eq!(dark_colors.name, "neutral-dark");
4070 assert_eq!(dark_colors.scheme, ThemeColorScheme::Dark);
4071 assert_eq!(dark_colors.base_100, rgb8(10, 10, 10));
4072 assert_eq!(dark_colors.base_content, rgb8(245, 245, 245));
4073 assert_eq!(dark_colors.primary, rgb8(245, 245, 245));
4074 assert_eq!(dark_colors.primary_content, rgb8(23, 23, 23));
4075 assert_eq!(dark.palette.surface_raised, rgb8(23, 23, 23));
4076 assert_eq!(dark.palette.control, rgb8(38, 38, 38));
4077 assert_eq!(dark.palette.control_hover, rgb8(51, 51, 51));
4078 assert_eq!(dark.palette.focus, rgb8(212, 212, 212));
4079 assert_eq!(dark.surfaces.window_subtle, rgb8(10, 10, 10));
4080 assert_eq!(dark.hdr.color_roles.accent.wide_gamut, None);
4081 assert_eq!(dark.hdr.color_roles.accent.hdr, None);
4082
4083 let glow = dark
4084 .glows
4085 .accent
4086 .first
4087 .expect("neutral dark should retain a restrained live-signal glow");
4088 assert_eq!(glow.color.red, glow.color.green);
4089 assert_eq!(glow.color.green, glow.color.blue);
4090
4091 for color in [
4092 dark_colors.base_100,
4093 dark_colors.base_200,
4094 dark_colors.base_300,
4095 dark_colors.base_content,
4096 dark_colors.primary,
4097 dark_colors.secondary,
4098 dark_colors.accent,
4099 dark.palette.focus,
4100 dark.palette.selection,
4101 ] {
4102 assert_eq!(color.red, color.green);
4103 assert_eq!(color.green, color.blue);
4104 }
4105 }
4106
4107 #[test]
4108 fn built_in_themes_use_exact_mesh_role_tokens() {
4109 let light = DefaultTheme::light();
4113 let light_surface = Color::WHITE;
4114 assert_eq!(light.palette.border, rgb8(227, 232, 239));
4115 assert_eq!(light.palette.border_strong, rgb8(205, 213, 224));
4116 assert_eq!(light.palette.text_muted, rgb8(73, 84, 107));
4117 assert_eq!(light.palette.placeholder, rgb8(104, 115, 144));
4118 assert_eq!(light.palette.control, rgb8(243, 245, 248));
4119 assert_eq!(light.palette.control_hover, rgb8(234, 238, 243));
4120 assert_eq!(light.palette.field, rgb8(248, 250, 252));
4121 assert_ne!(light.palette.field, light.palette.surface);
4122 assert_eq!(light.palette.focus, rgb8(9, 148, 198));
4123 assert_eq!(
4124 light.palette.selection,
4125 rgba8(8, 124, 164, 0.18).over(light_surface)
4126 );
4127 assert_eq!(
4128 light.palette.accent_soft,
4129 rgba8(8, 124, 164, 0.08).over(light_surface)
4130 );
4131 assert_eq!(light.palette.accent_soft.alpha, 1.0);
4132 assert_eq!(light.palette.accent_soft_text, rgb8(8, 124, 164));
4133 assert_eq!(light.palette.warning_soft_text, rgb8(154, 103, 0));
4134 assert_eq!(light.palette.danger_hover, rgb8(180, 35, 24));
4135 assert_eq!(light.surfaces.window_subtle, rgb8(247, 248, 250));
4136 assert_eq!(light.surfaces.sidebar, light.surfaces.window_subtle);
4137 assert_eq!(light.surfaces.overlay, Color::WHITE);
4138
4139 let dark = DefaultTheme::dark();
4140 let dark_surface = rgb8(18, 22, 31);
4141 assert_eq!(
4142 dark.palette.border,
4143 rgba8(151, 168, 199, 0.16).over(dark_surface)
4144 );
4145 assert_eq!(
4146 dark.palette.border_strong,
4147 rgba8(151, 168, 199, 0.27).over(dark_surface)
4148 );
4149 assert_eq!(dark.palette.text_muted, rgb8(166, 178, 200));
4150 assert_eq!(dark.palette.control, rgb8(23, 28, 39));
4151 assert_eq!(dark.palette.control_hover, rgb8(29, 36, 49));
4152 assert_eq!(dark.palette.field, rgb8(15, 19, 27));
4153 assert_eq!(dark.palette.surface_raised, dark_surface);
4154 assert_eq!(dark.palette.focus, rgb8(73, 199, 234));
4155 assert_eq!(
4156 dark.palette.selection,
4157 rgba8(53, 210, 238, 0.24).over(dark_surface)
4158 );
4159 assert_eq!(dark.palette.accent_hover, rgb8(95, 224, 246));
4160 assert_eq!(
4161 dark.palette.success_soft,
4162 rgba8(74, 222, 128, 0.12).over(dark_surface)
4163 );
4164 assert_eq!(dark.palette.success_soft_text, rgb8(74, 222, 128));
4165 assert_eq!(dark.surfaces.window_subtle, rgb8(14, 18, 26));
4166 assert_eq!(dark.surfaces.overlay, rgb8(22, 27, 38));
4167 assert_eq!(
4168 dark.surfaces.border_subtle,
4169 rgba8(151, 168, 199, 0.09).over(dark_surface)
4170 );
4171 assert_eq!(dark.surfaces.text_disabled, rgb8(81, 93, 117));
4172 assert_eq!(dark.surfaces.text_invert, rgb8(13, 18, 32));
4173
4174 let void = DefaultTheme::void();
4175 assert_eq!(
4176 void.palette.border,
4177 rgba8(158, 175, 205, 0.18).over(Color::BLACK)
4178 );
4179 assert_eq!(void.palette.field, rgb8(11, 14, 20));
4180 assert_eq!(void.palette.focus, rgb8(63, 196, 228));
4181 assert_eq!(void.surfaces.window_subtle, Color::BLACK);
4182 assert_eq!(void.surfaces.overlay, rgb8(10, 13, 19));
4183 assert_eq!(void.surfaces.overlay_scrim, rgba8(0, 0, 0, 0.72));
4186 }
4187
4188 #[test]
4189 fn elevation_follows_the_mesh_ladder_per_scheme() {
4190 let light = DefaultTheme::light();
4191 let dark = DefaultTheme::dark();
4192 let void = DefaultTheme::void();
4193
4194 let light_sm = light.shadows.box_shadow.xs.first.expect("light xs shadow");
4196 assert!(light_sm.color.alpha > 0.0 && light_sm.color.alpha < 0.1);
4197 let dark_sm = dark.shadows.box_shadow.xs.first.expect("dark xs shadow");
4199 assert!(dark_sm.color.alpha > light_sm.color.alpha);
4200 assert_eq!(void.shadows.box_shadow.xs, ThemeShadow::empty());
4202 assert_eq!(void.shadows.box_shadow._2xl, ThemeShadow::empty());
4203 assert_eq!(void.shadows.drop.sm, ThemeShadow::empty());
4204
4205 assert_eq!(light.glows.accent, ThemeShadow::empty());
4207 let dark_glow = dark.glows.accent.first.expect("dark accent glow");
4208 let void_glow = void.glows.accent.first.expect("void accent glow");
4209 assert!(dark_glow.blur > void_glow.blur);
4210 assert!(dark_glow.color.alpha > void_glow.color.alpha);
4211 assert_eq!(dark_glow.offset_x, 0.0);
4212 assert_eq!(dark_glow.offset_y, 0.0);
4213 }
4214
4215 #[test]
4216 fn density_tiers_match_the_mesh_contract() {
4217 let compact = DefaultTheme::compact();
4218 let comfortable = DefaultTheme::comfortable();
4219 let touch = DefaultTheme::touch();
4220
4221 assert_eq!(compact.metrics.min_height, 28.0);
4223 assert_eq!(comfortable.metrics.min_height, 32.0);
4224 assert_eq!(touch.metrics.min_height, 40.0);
4225 assert_eq!(compact.metrics.touch_target_size, 44.0);
4226 assert_eq!(comfortable.metrics.touch_target_size, 44.0);
4227 assert_eq!(touch.metrics.touch_target_size, 44.0);
4228
4229 assert_eq!(compact.metrics.list_row_height, 30.0);
4231 assert_eq!(comfortable.metrics.list_row_height, 36.0);
4232 assert_eq!(touch.metrics.list_row_height, 44.0);
4233 assert_eq!(compact.metrics.table_row_height, 30.0);
4234
4235 assert_eq!(compact.typography.body_font_size, 13.0);
4237 assert_eq!(comfortable.typography.body_font_size, 15.0);
4238 assert_eq!(touch.typography.body_font_size, 17.0);
4239
4240 assert_eq!(compact.metrics.corner_radius, 6.0);
4242 assert_eq!(comfortable.metrics.corner_radius, 6.0);
4243 assert_eq!(touch.metrics.corner_radius, 8.0);
4244
4245 for theme in [&compact, &comfortable, &touch] {
4247 assert_eq!(theme.metrics.switch_track_width, 32.0);
4248 assert_eq!(theme.metrics.switch_track_height, 19.0);
4249 assert_eq!(theme.metrics.checkbox_indicator_size, 15.0);
4250 }
4251 }
4252
4253 #[test]
4254 fn mesh_motion_ladder_is_70_140_220_340() {
4255 let motion = super::ThemeMotion::standard();
4256 assert_eq!(motion.duration_fast, 0.07);
4257 assert_eq!(motion.duration_normal, 0.14);
4258 assert_eq!(motion.duration_slow, 0.22);
4259 assert_eq!(motion.duration_slower, 0.34);
4260 }
4261
4262 #[test]
4263 fn light_and_dark_themes_derive_hdr_role_colors_from_semantics() {
4264 let light = DefaultTheme::light();
4265 let dark = DefaultTheme::dark();
4266
4267 assert_eq!(light.hdr.color_roles.surface.sdr, light.colors.base_100);
4268 assert_eq!(light.hdr.color_roles.text.sdr, light.colors.base_content);
4269 assert_eq!(dark.hdr.color_roles.surface.sdr, dark.colors.base_100);
4270 assert_eq!(dark.hdr.color_roles.accent.sdr, dark.colors.primary);
4271 }
4272
4273 #[test]
4274 fn sync_derived_fields_updates_semantic_palette_and_typography() {
4275 let mut theme = DefaultTheme::default();
4276 theme.colors.primary = Color::rgba(0.2, 0.3, 0.4, 1.0);
4277 theme.text.base.size = 11.0;
4278 theme.text.base.line_height = 15.0;
4279 theme.text.lg.size = 15.0;
4280 theme.text.lg.line_height = 22.0;
4281 theme.density = ThemeDensity::Touch;
4282 theme.sync_derived_fields();
4283
4284 assert_eq!(theme.palette.accent, Color::rgba(0.2, 0.3, 0.4, 1.0));
4285 assert_eq!(theme.palette.caret, Color::rgba(0.2, 0.3, 0.4, 1.0));
4286 assert_eq!(theme.surfaces.accent, theme.palette.accent);
4287 assert_eq!(theme.surfaces.window, theme.palette.surface);
4288 assert_eq!(theme.surfaces.tooltip, theme.surfaces.overlay);
4290 assert_eq!(theme.surfaces.tooltip_text, theme.palette.text_muted);
4291 assert!(theme.surfaces.overlay_scrim.alpha > 0.0);
4292 assert_eq!(theme.typography.body_font_size, 15.0);
4294 assert_eq!(theme.typography.body_line_height, 22.0);
4295 assert_eq!(
4296 theme.metrics.min_height,
4297 DefaultTheme::default()
4298 .with_density(ThemeDensity::Touch)
4299 .metrics
4300 .min_height
4301 );
4302 assert_eq!(
4303 theme.interaction.pressed_offset,
4304 DefaultTheme::default()
4305 .with_density(ThemeDensity::Touch)
4306 .interaction
4307 .pressed_offset
4308 );
4309 }
4310
4311 #[test]
4312 fn control_palette_exposes_semantic_status_colors() {
4313 let theme = DefaultTheme::default();
4314
4315 assert_eq!(theme.palette.info, theme.colors.info);
4316 assert_eq!(theme.palette.info_text, theme.colors.info_content);
4317 assert_eq!(theme.palette.success, theme.colors.success);
4318 assert_eq!(theme.palette.success_text, theme.colors.success_content);
4319 assert_eq!(theme.palette.warning, theme.colors.warning);
4320 assert_eq!(theme.palette.warning_text, theme.colors.warning_content);
4321 assert_eq!(theme.palette.danger, theme.colors.error);
4322 assert_eq!(theme.palette.danger_text, theme.colors.error_content);
4323 assert_eq!(
4324 theme.semantic_tone_colors(SemanticTone::Warning),
4325 (theme.palette.warning, theme.palette.warning_text)
4326 );
4327 assert_eq!(
4328 theme.semantic_tone_color(SemanticTone::Danger),
4329 theme.palette.danger
4330 );
4331 assert_eq!(
4332 theme.semantic_tone_text_color(SemanticTone::Success),
4333 theme.palette.success_text
4334 );
4335 }
4336
4337 #[test]
4338 fn sync_derived_fields_updates_hdr_semantic_fallbacks() {
4339 let mut theme = DefaultTheme::default();
4340 let stale_wide_gamut = Color::display_p3(0.9, 0.4, 0.2, 1.0);
4341 let stale_hdr = Color::linear_display_p3(1.6, 0.5, 0.3, 1.0);
4342
4343 theme.hdr.color_roles.accent.wide_gamut = Some(stale_wide_gamut);
4344 theme.hdr.color_roles.accent.hdr = Some(stale_hdr);
4345 theme.colors = ThemeColors::dark();
4346 theme.colors.base_100 = Color::rgba(0.96, 0.97, 0.98, 1.0);
4347 theme.sync_derived_fields();
4348
4349 assert_eq!(theme.hdr.color_roles.surface.sdr, theme.colors.base_100);
4350 assert_eq!(theme.hdr.color_roles.accent.sdr, theme.colors.primary);
4351 assert_eq!(
4352 theme.hdr.color_roles.accent.wide_gamut,
4353 Some(Color::display_p3(0.13, 0.84, 0.95, 1.0))
4354 );
4355 assert_eq!(
4356 theme.hdr.color_roles.accent.hdr,
4357 Some(Color::linear_display_p3(0.16, 0.95, 1.10, 1.0))
4358 );
4359 }
4360
4361 #[test]
4362 fn dark_theme_uses_professional_dark_tokens() {
4363 let theme = DefaultTheme::dark();
4364
4365 assert_eq!(theme.colors.scheme, ThemeColorScheme::Dark);
4366 assert_eq!(theme.colors.name, "dark");
4367 assert_ne!(theme.colors.base_100, Color::BLACK);
4368 assert_eq!(theme.palette.surface, theme.colors.base_100);
4369 assert_ne!(theme.palette.surface_raised, Color::BLACK);
4370 assert_eq!(theme.palette.text, theme.colors.base_content);
4371 assert_ne!(theme.palette.text, Color::WHITE);
4372 assert_eq!(theme.palette.caret, theme.colors.primary);
4373 assert_eq!(theme.palette.accent, theme.colors.primary);
4374 assert_eq!(theme.palette.accent_text, theme.colors.primary_content);
4375 assert_eq!(theme.surfaces.window, theme.palette.surface);
4376 assert_eq!(theme.surfaces.panel, theme.palette.surface_raised);
4377 assert_eq!(theme.surfaces.border, theme.palette.border);
4378 assert_ne!(theme.surfaces.border, Color::WHITE);
4379 assert_ne!(theme.surfaces.text_faint, theme.palette.surface);
4380 }
4381
4382 #[test]
4383 fn high_contrast_scheme_uses_true_black_oled_palette() {
4384 let theme = DefaultTheme::high_contrast();
4385
4386 assert_eq!(theme.colors.scheme, ThemeColorScheme::HighContrast);
4387 assert_eq!(theme.colors.name, "void");
4388 assert_eq!(theme.palette.surface, theme.colors.base_100);
4389 assert_eq!(theme.palette.surface, Color::BLACK);
4390 assert_eq!(theme.surfaces.window, Color::BLACK);
4391 assert_eq!(theme.palette.surface_raised, Color::BLACK);
4394 assert!(theme.palette.border.alpha > 0.0);
4395 assert_ne!(theme.palette.control, Color::BLACK);
4396 assert_ne!(theme.palette.field, Color::BLACK);
4397 assert_ne!(theme.palette.text, Color::WHITE);
4398 assert_ne!(theme.palette.control_hover, Color::BLACK);
4399 assert_ne!(theme.palette.control_active, Color::BLACK);
4400 assert_ne!(theme.palette.surface_focus, Color::BLACK);
4401 assert_eq!(theme.palette.text, theme.colors.base_content);
4402 assert_eq!(
4403 theme.metrics.border_width,
4404 DefaultTheme::default().metrics.border_width
4405 );
4406 assert_eq!(
4407 theme.metrics.focus_ring_width,
4408 DefaultTheme::default().metrics.focus_ring_width
4409 );
4410
4411 let touch = DefaultTheme::high_contrast().with_density(ThemeDensity::Touch);
4412 assert_eq!(touch.density, ThemeDensity::Touch);
4413 assert!(touch.metrics.min_height > theme.metrics.min_height);
4414 assert_eq!(
4415 touch.metrics.border_width,
4416 DefaultTheme::touch().metrics.border_width
4417 );
4418 assert_eq!(
4419 touch.metrics.focus_ring_width,
4420 DefaultTheme::touch().metrics.focus_ring_width
4421 );
4422 }
4423}