Skip to main content

mcu_scheme/
scheme_expressive.rs

1// <FILE>crates/mcu-scheme/src/scheme_expressive.rs</FILE> - <DESC>Expressive color scheme</DESC>
2// <VERS>VERSION: 2.0.0</VERS>
3// <WCTX>Full implementation of expressive scheme wrapper</WCTX>
4// <CLOG>Implement SchemeExpressive wrapping DynamicScheme with Variant::Expressive</CLOG>
5
6use mcu_dynamiccolor::{DynamicScheme, DynamicSchemeOptions, Platform, SpecVersion, Variant};
7use mcu_hct::Hct;
8use std::ops::Deref;
9
10/// An expressive color scheme with creative color manipulation.
11///
12/// Uses complex color transformations to create unexpected but harmonious combinations.
13/// Best for distinctive, artistic designs.
14///
15/// # Example
16///
17/// ```
18/// use mcu_scheme::SchemeExpressive;
19/// use mcu_hct::Hct;
20///
21/// let source = Hct::from_int(0xFF0000FF); // Blue
22/// let scheme = SchemeExpressive::new(source, false, 0.0);
23/// assert!(!scheme.is_dark);
24/// ```
25pub struct SchemeExpressive {
26    scheme: DynamicScheme,
27}
28
29impl SchemeExpressive {
30    /// Create a new expressive scheme.
31    ///
32    /// # Arguments
33    ///
34    /// * `source_color_hct` - The source color in HCT color space
35    /// * `is_dark` - Whether to generate a dark mode scheme
36    /// * `contrast_level` - Contrast level from -1.0 (minimum) to 1.0 (maximum), 0.0 is standard
37    pub fn new(source_color_hct: Hct, is_dark: bool, contrast_level: f64) -> Self {
38        let scheme = DynamicScheme::new(DynamicSchemeOptions::new(
39            source_color_hct,
40            Variant::Expressive,
41            contrast_level,
42            is_dark,
43        ));
44        Self { scheme }
45    }
46
47    /// Create a new expressive scheme with full options.
48    ///
49    /// # Arguments
50    ///
51    /// * `source_color_hct` - The source color in HCT color space
52    /// * `is_dark` - Whether to generate a dark mode scheme
53    /// * `contrast_level` - Contrast level from -1.0 (minimum) to 1.0 (maximum), 0.0 is standard
54    /// * `platform` - Target platform (Phone or Watch)
55    /// * `spec_version` - Design spec version (2021 or 2025)
56    pub fn with_options(
57        source_color_hct: Hct,
58        is_dark: bool,
59        contrast_level: f64,
60        platform: Platform,
61        spec_version: SpecVersion,
62    ) -> Self {
63        let mut options = DynamicSchemeOptions::new(
64            source_color_hct,
65            Variant::Expressive,
66            contrast_level,
67            is_dark,
68        );
69        options.platform = Some(platform);
70        options.spec_version = Some(spec_version);
71        Self {
72            scheme: DynamicScheme::new(options),
73        }
74    }
75}
76
77impl Deref for SchemeExpressive {
78    type Target = DynamicScheme;
79
80    fn deref(&self) -> &Self::Target {
81        &self.scheme
82    }
83}
84
85#[cfg(test)]
86mod tests {
87    use super::*;
88
89    #[test]
90    fn test_new_light_mode() {
91        let source = Hct::from_int(0xFF0000FF);
92        let scheme = SchemeExpressive::new(source, false, 0.0);
93
94        assert_eq!(scheme.variant, Variant::Expressive);
95        assert!(!scheme.is_dark);
96        assert_eq!(scheme.contrast_level, 0.0);
97    }
98
99    #[test]
100    fn test_new_dark_mode() {
101        let source = Hct::from_int(0xFF0000FF);
102        let scheme = SchemeExpressive::new(source, true, 0.0);
103
104        assert_eq!(scheme.variant, Variant::Expressive);
105        assert!(scheme.is_dark);
106    }
107
108    #[test]
109    fn test_contrast_levels() {
110        let source = Hct::from_int(0xFF0000FF);
111
112        let low = SchemeExpressive::new(source, false, -1.0);
113        assert_eq!(low.contrast_level, -1.0);
114
115        let high = SchemeExpressive::new(source, false, 1.0);
116        assert_eq!(high.contrast_level, 1.0);
117    }
118
119    #[test]
120    fn test_with_options() {
121        let source = Hct::from_int(0xFF0000FF);
122        let scheme = SchemeExpressive::with_options(
123            source,
124            true,
125            0.5,
126            Platform::Watch,
127            SpecVersion::Spec2025,
128        );
129
130        assert_eq!(scheme.variant, Variant::Expressive);
131        assert!(scheme.is_dark);
132        assert_eq!(scheme.contrast_level, 0.5);
133        assert_eq!(scheme.platform, Platform::Watch);
134        assert_eq!(scheme.spec_version, SpecVersion::Spec2025);
135    }
136
137    #[test]
138    fn test_deref_access() {
139        let source = Hct::from_int(0xFF0000FF);
140        let scheme = SchemeExpressive::new(source, false, 0.0);
141
142        // Access DynamicScheme fields through Deref
143        let _primary = &scheme.primary_palette;
144        let _secondary = &scheme.secondary_palette;
145        let _argb = scheme.source_color_argb;
146    }
147}
148
149// <FILE>crates/mcu-scheme/src/scheme_expressive.rs</FILE> - <DESC>Expressive color scheme</DESC>
150// <VERS>END OF VERSION: 2.0.0</VERS>