From 0b09b27b955dd4872fef4534c0b6c6b8392cc33e Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sun, 21 Sep 2025 00:28:45 -0600 Subject: [PATCH] Color provenance hack via f32 next_up / next_down --- crates/theme/src/theme.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 29269c15074a158acd742c7f6e258b0c94b7bebe..af422643782c97353033a68089a5d81f84e304b8 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -238,6 +238,14 @@ impl ThemeFamily { .map(Into::into) .unwrap_or_default(); + #[cfg(debug_assertions)] + { + use collections::HashMap; + let mut color_to_count: HashMap = HashMap::default(); + make_colors_unique(&mut refined_status_colors, &mut color_to_count); + make_colors_unique(&mut refined_theme_colors, &mut color_to_count); + } + Theme { id: uuid::Uuid::new_v4().to_string(), name: theme.name.clone().into(), @@ -280,6 +288,33 @@ pub fn refine_theme_family(theme_family_content: ThemeFamilyContent) -> ThemeFam theme_family } +/// Make theme colors unique via tiny adjustments to luminance. This is a hack to provide color +/// provenance information to the inspector (which is only available in debug builds). +/// +/// Since luminance is an f32, `next_down` / `next_up` should rarely affect RGB. +#[cfg(debug_assertions)] +fn make_colors_unique(colors: &mut T, color_to_count: &mut collections::HashMap) +where + F: Copy + strum::IntoEnumIterator, + T: util::FieldAccessByEnum, +{ + for field in F::iter() { + let mut color = *colors.get_field_by_enum(field); + let count = color_to_count.entry(color).or_default(); + *count += 1; + if color.l > 0.5 { + for _ in 0..*count { + color.l = color.l.next_down(); + } + } else { + for _ in 0..*count { + color.l = color.l.next_up(); + } + } + colors.set_field_by_enum(field, color); + } +} + /// A theme is the primary mechanism for defining the appearance of the UI. #[derive(Clone, Debug, PartialEq)] pub struct Theme {