Skip to main content

Crate mcu_material_color

Crate mcu_material_color 

Source
Expand description

§Material Color Utilities

Rust port of Google’s Material Color Utilities library for generating dynamic color schemes based on Material Design 3.

§Quick Start

use mcu_material_color::prelude::*;

// Create a scheme from a seed color
let seed_color = 0xFF6750A4; // Purple
let hct = Hct::from_int(seed_color);
let scheme = SchemeTonalSpot::new(hct, false, 0.0);

// Access the underlying DynamicScheme through Deref
assert!(!scheme.is_dark);
let _primary = &scheme.primary_palette;

§Modules

  • hct - HCT color space (Hue, Chroma, Tone) based on CAM16
  • palettes - Tonal and core color palette generation
  • scheme - Pre-built color scheme variants
  • dynamiccolor - Dynamic color system with runtime resolution
  • blend - Color blending in HCT and CAM16-UCS spaces
  • contrast - WCAG accessibility contrast calculations
  • quantize - Image color quantization algorithms
  • score - Color ranking for theme suitability
  • dislike - Fixing unfavorable colors
  • temperature - Color temperature calculations

§Prelude

For most use cases, import the prelude module:

use mcu_material_color::prelude::*;

This provides commonly used types without polluting your namespace.

Re-exports§

pub use mcu_blend as blend;
pub use mcu_contrast as contrast;
pub use mcu_dislike as dislike;
pub use mcu_dynamiccolor as dynamiccolor;
pub use mcu_hct as hct;
pub use mcu_palettes as palettes;
pub use mcu_quantize as quantize;
pub use mcu_scheme as scheme;
pub use mcu_score as score;
pub use mcu_temperature as temperature;
pub use mcu_utils as utils;

Modules§

prelude
Prelude module providing commonly used types.

Structs§

Blend
Color blending operations for combining colors in perceptually uniform spaces.
Cam16
CAM16, a color appearance model.
ColorSpecDelegateImpl2021
Implementation of the 2021 Material Design 3 color specification.
ColorSpecDelegateImpl2025
A delegate for the dynamic color spec of a DynamicScheme in the 2025 spec.
Contrast
Utility struct for contrast ratio calculations.
ContrastCurve
A contrast curve for dynamic color selection.
CorePalette
An intermediate concept between the key color for a UI theme, and a full color scheme.
CorePaletteColors
Color definitions for creating a CorePalette from multiple source colors.
DynamicColor
A color that adjusts itself based on UI state provided by DynamicScheme.
DynamicScheme
A dynamic color scheme generated from a source color.
DynamicSchemeOptions
Options for creating a DynamicScheme.
Hct
HCT, hue, chroma, and tone.
MaterialDynamicColors
DynamicColors for the colors in the Material Design system.
QuantizerCelebi
Celebi’s color quantization algorithm implementation.
QuantizerMap
Quantizes an image into a map of ARGB colors to their occurrence counts.
QuantizerWsmeans
Weighted squared-means color quantization algorithm.
QuantizerWu
Wu’s color quantization algorithm implementation.
SchemeContent
A content-based color scheme that extracts dominant colors from images.
SchemeExpressive
An expressive color scheme with creative color manipulation.
SchemeFidelity
A fidelity color scheme that closely follows the source color’s hue and chroma.
SchemeFruitSalad
A fruit salad color scheme with playful hue variations.
SchemeMonochrome
A monochromatic color scheme using only lightness and saturation variations.
SchemeNeutral
A neutral color scheme with subtle color shifts.
SchemeRainbow
A rainbow color scheme creating a spectrum-inspired color palette.
SchemeTonalSpot
A tonal spot color scheme emphasizing the source color with tonal adjustments.
SchemeVibrant
A vibrant color scheme with saturated, bold colors.
Score
Color scoring for ranking colors by theme suitability.
ScoreOptions
Options for customizing color scoring behavior.
TonalPalette
A convenience class for retrieving colors that are constant in hue and chroma, but vary in tone.
ToneDeltaPair
Documents a constraint between two DynamicColors, in which their tones must have a certain distance from each other.
ViewingConditions
Viewing conditions for the CAM16 color appearance model.

Enums§

DeltaConstraint
Describes how to fulfill a tone delta pair constraint.
Platform
Platform identifier for dynamic scheme. Only used in the 2025 spec.
SpecVersion
Specification version for dynamic scheme.
TonePolarity
Describes the different in tone between colors.
Variant
Enumeration of dynamic color scheme variants for Material Design 3.

Traits§

ColorSpecDelegate
A delegate that provides the dynamic color constraints for MaterialDynamicColors.