summaryrefslogtreecommitdiff
path: root/crates/material_theme/src/utils.rs
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-04-28 10:56:49 +0200
committerpml68 <contact@pml68.dev>2025-04-28 10:56:49 +0200
commitdac7e82e0bff128097653fe05829b2d576fcdb2f (patch)
tree6f36736e79eecd6904933c6876af1df58e6b605b /crates/material_theme/src/utils.rs
parentfeat(material_theme): implement `image::Catalog` (under feature flag) (diff)
downloadiced-builder-dac7e82e0bff128097653fe05829b2d576fcdb2f.tar.gz
refactor(material_theme)!: make `Theme` an enum with `Custom` variant
Diffstat (limited to 'crates/material_theme/src/utils.rs')
-rw-r--r--crates/material_theme/src/utils.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/material_theme/src/utils.rs b/crates/material_theme/src/utils.rs
index 5ad137e..963c9fc 100644
--- a/crates/material_theme/src/utils.rs
+++ b/crates/material_theme/src/utils.rs
@@ -30,6 +30,20 @@ pub fn shadow_from_elevation(elevation: f32, color: Color) -> Shadow {
}
}
+pub fn disabled_text(color: Color) -> Color {
+ Color {
+ a: DISABLED_TEXT_OPACITY,
+ ..color
+ }
+}
+
+pub fn disabled_container(color: Color) -> Color {
+ Color {
+ a: DISABLED_CONTAINER_OPACITY,
+ ..color
+ }
+}
+
pub fn parse_argb(s: &str) -> Option<Color> {
let hex = s.strip_prefix('#').unwrap_or(s);
@@ -88,6 +102,10 @@ pub fn color_to_argb(color: Color) -> String {
hex
}
+pub const fn lightness(color: Color) -> f32 {
+ color.r * 0.299 + color.g * 0.587 + color.b * 0.114
+}
+
pub fn mix(color1: Color, color2: Color, p2: f32) -> Color {
if p2 <= 0.0 {
return color1;