| Crates.io | material-color-rs |
| lib.rs | material-color-rs |
| version | 0.1.0 |
| created_at | 2025-12-30 10:28:38.601823+00 |
| updated_at | 2025-12-30 10:28:38.601823+00 |
| description | Rust implementation of Material Design 3 color generation algorithms with HCT color space and dynamic theme system |
| homepage | https://github.com/KitsuneX07/material-color-utilities |
| repository | https://github.com/KitsuneX07/material-color-utilities |
| max_upload_size | |
| id | 2012438 |
| size | 246,843 |
Rust 实现的 Material Design 3 颜色生成工具库,提供 HCT 颜色空间和动态主题系统。
[dependencies]
material-color-rs = "0.1"
# 可选:启用 iced 框架支持
material-color-rs = { version = "0.1", features = ["iced"] }
use material_color_rs::generate_theme_from_color;
// 生成主题
let theme = generate_theme_from_color("#39C5BB")?;
let light_scheme = theme.schemes.get("light").unwrap();
// 获取颜色(多种格式)
let primary_argb = light_scheme.get_argb("primary").unwrap(); // u32 ARGB
let (r, g, b) = light_scheme.get_rgb("primary").unwrap(); // RGB 元组
let rgba = light_scheme.get_rgba("primary").unwrap(); // [u8; 4]
// 导出 JSON
let json = serde_json::to_string_pretty(&theme.to_json())?;
// 启用 features = ["iced"]
let primary = light_scheme.get_iced("primary").unwrap();
container(content)
.style(|_theme| container::Style {
background: Some(primary.into()),
..Default::default()
})
主色: primary, onPrimary, primaryContainer, onPrimaryContainer
次要色: secondary, onSecondary, secondaryContainer, onSecondaryContainer
第三色: tertiary, onTertiary, tertiaryContainer, onTertiaryContainer
表面色: surface, onSurface, surfaceVariant, onSurfaceVariant
容器色: surfaceContainer, surfaceContainerLow, surfaceContainerHigh, ...
其他: error, outline, shadow, scrim, inverseSurface, ...
项目采用双层数据结构设计:
MaterialTheme 使用 u32 ARGB 格式存储,提供极致性能MaterialThemeJson 用于 JSON 导入/导出这种设计确保内部操作零开销,同时保持灵活的数据交换能力。
MIT License - 详见 LICENSE 文件