From dae262f4662c63e6f34ddffac9344246ca385555 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 4 Aug 2023 17:30:32 -0400 Subject: [PATCH] fix: make surfaces lighter if possible in light mode --- cosmic-theme/src/model/theme.rs | 11 ++++++----- cosmic-theme/src/steps.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cosmic-theme/src/model/theme.rs b/cosmic-theme/src/model/theme.rs index 07addca1..61a13742 100644 --- a/cosmic-theme/src/model/theme.rs +++ b/cosmic-theme/src/model/theme.rs @@ -620,16 +620,16 @@ impl ThemeBuilder { let primary_container_bg = if let Some(primary_container_bg_color) = primary_container_bg { primary_container_bg_color } else { - get_color(bg_index, 5, &step_array, is_dark, &p_ref.neutral_1) + get_surface_color(bg_index, 5, &step_array, is_dark, &p_ref.neutral_1) }; let secondary_container_bg = if let Some(secondary_container_bg) = secondary_container_bg { secondary_container_bg } else { - get_color(bg_index, 10, &step_array, is_dark, &p_ref.neutral_2) + get_surface_color(bg_index, 10, &step_array, is_dark, &p_ref.neutral_2) }; - let bg_component = get_color(bg_index, 8, &step_array, is_dark, &p_ref.neutral_2); + let bg_component = get_surface_color(bg_index, 8, &step_array, is_dark, &p_ref.neutral_2); let on_bg_component = get_text( color_index(bg_component, step_array.len()), &step_array, @@ -646,7 +646,8 @@ impl ThemeBuilder { ); let primary_index = color_index(primary_container_bg, step_array.len()); - let primary_component = get_color(primary_index, 6, &step_array, is_dark, &p_ref.neutral_3); + let primary_component = + get_surface_color(primary_index, 6, &step_array, is_dark, &p_ref.neutral_3); let on_primary_component = get_text( color_index(primary_component, step_array.len()), &step_array, @@ -664,7 +665,7 @@ impl ThemeBuilder { let secondary_index = color_index(secondary_container_bg, step_array.len()); let secondary_component = - get_color(secondary_index, 3, &step_array, is_dark, &p_ref.neutral_4); + get_surface_color(secondary_index, 3, &step_array, is_dark, &p_ref.neutral_4); let on_secondary_component = get_text( color_index(secondary_component, step_array.len()), &step_array, diff --git a/cosmic-theme/src/steps.rs b/cosmic-theme/src/steps.rs index 58117e5d..de23e52c 100644 --- a/cosmic-theme/src/steps.rs +++ b/cosmic-theme/src/steps.rs @@ -31,15 +31,18 @@ pub fn get_index(base_index: usize, steps: usize, step_len: usize, is_dark: bool .filter(|i| *i < step_len) } -/// get color given a base and some steps -pub fn get_color( +/// get surface color given a base and some steps +pub fn get_surface_color( base_index: usize, steps: usize, step_array: &Vec, - is_dark: bool, + mut is_dark: bool, fallback: &Srgba, ) -> Srgba { assert!(step_array.len() == 100); + if !is_dark && base_index >= 88 { + is_dark = true; + } get_index(base_index, steps, step_array.len(), is_dark) .and_then(|i| step_array.get(i).cloned()) .unwrap_or_else(|| fallback.to_owned())