improv(theme): theme generation improvements

This commit is contained in:
Michael Aaron Murphy 2024-04-24 03:22:45 +02:00 committed by Michael Murphy
parent 950a1a54f5
commit 14bd633356
6 changed files with 146 additions and 88 deletions

View file

@ -15,18 +15,28 @@ pub struct Container {
pub divider: Srgba,
/// the color of text in the container
pub on: Srgba,
/// the color of @small_widget_container
pub small_widget: Srgba,
}
impl Container {
pub(crate) fn new(component: Component, base: Srgba, on: Srgba) -> Self {
pub(crate) fn new(
component: Component,
base: Srgba,
on: Srgba,
mut small_widget: Srgba,
) -> Self {
let mut divider_c = on;
divider_c.alpha = 0.2;
small_widget.alpha = 0.25;
Self {
base,
component,
divider: over(divider_c, base),
on,
small_widget,
}
}
}

View file

@ -5,7 +5,7 @@ use crate::{
DARK_PALETTE, LIGHT_PALETTE, NAME,
};
use cosmic_config::{Config, CosmicConfigEntry};
use palette::{IntoColor, Oklcha, Srgb, Srgba};
use palette::{rgb::Rgb, IntoColor, Oklcha, Srgb, Srgba};
use serde::{Deserialize, Serialize};
use std::num::NonZeroUsize;
@ -182,13 +182,6 @@ impl Theme {
self.warning.base
}
#[must_use]
#[allow(clippy::doc_markdown)]
/// get @small_container_widget
pub fn small_container_widget(&self) -> Srgba {
self.palette.gray_2
}
#[must_use]
#[allow(clippy::doc_markdown)]
/// get @small_widget_divider
@ -774,6 +767,11 @@ impl ThemeBuilder {
let p_ref = palette.as_ref();
let neutral_steps = steps(
neutral_tint.unwrap_or(Rgb::new(0.0, 0.0, 0.0)),
NonZeroUsize::new(100).unwrap(),
);
let bg = if let Some(bg_color) = bg_color {
bg_color
} else {
@ -783,10 +781,14 @@ impl ThemeBuilder {
let step_array = steps(bg, NonZeroUsize::new(100).unwrap());
let bg_index = color_index(bg, step_array.len());
let mut component_hovered_overlay = p_ref.neutral_0;
let mut component_hovered_overlay = if bg_index < 91 {
p_ref.neutral_10
} else {
p_ref.neutral_0
};
component_hovered_overlay.alpha = 0.1;
let mut component_pressed_overlay = p_ref.neutral_0;
let mut component_pressed_overlay = component_hovered_overlay;
component_pressed_overlay.alpha = 0.2;
// Standard button background is neutral 7 with 25% opacity
@ -805,7 +807,6 @@ impl ThemeBuilder {
let on_bg_component = get_text(
color_index(bg_component, step_array.len()),
&step_array,
is_dark,
&p_ref.neutral_8,
text_steps_array.as_ref(),
);
@ -831,10 +832,16 @@ impl ThemeBuilder {
get_text(
bg_index,
&step_array,
is_dark,
&p_ref.neutral_8,
text_steps_array.as_ref(),
),
get_surface_color(
bg_index,
5,
&neutral_steps,
bg_index <= 65,
&p_ref.neutral_6,
),
),
primary: {
let container_bg = if let Some(primary_container_bg_color) = primary_container_bg {
@ -843,10 +850,20 @@ impl ThemeBuilder {
get_surface_color(bg_index, 5, &step_array, is_dark, &p_ref.neutral_1)
};
let base_index = color_index(container_bg, step_array.len());
let base_index: usize = color_index(container_bg, step_array.len());
let component_base =
get_surface_color(base_index, 6, &step_array, is_dark, &p_ref.neutral_3);
component_hovered_overlay = if base_index < 91 {
p_ref.neutral_10
} else {
p_ref.neutral_0
};
component_hovered_overlay.alpha = 0.1;
component_pressed_overlay = component_hovered_overlay;
component_pressed_overlay.alpha = 0.2;
let container = Container::new(
Component::component(
component_base,
@ -854,7 +871,6 @@ impl ThemeBuilder {
get_text(
color_index(component_base, step_array.len()),
&step_array,
is_dark,
&p_ref.neutral_8,
text_steps_array.as_ref(),
),
@ -867,10 +883,16 @@ impl ThemeBuilder {
get_text(
base_index,
&step_array,
is_dark,
&p_ref.neutral_8,
text_steps_array.as_ref(),
),
get_surface_color(
base_index,
5,
&neutral_steps,
base_index <= 65,
&p_ref.neutral_6,
),
);
container
@ -886,6 +908,16 @@ impl ThemeBuilder {
let secondary_component =
get_surface_color(base_index, 3, &step_array, is_dark, &p_ref.neutral_4);
component_hovered_overlay = if base_index < 91 {
p_ref.neutral_10
} else {
p_ref.neutral_0
};
component_hovered_overlay.alpha = 0.1;
component_pressed_overlay = component_hovered_overlay;
component_pressed_overlay.alpha = 0.2;
Container::new(
Component::component(
secondary_component,
@ -893,7 +925,6 @@ impl ThemeBuilder {
get_text(
color_index(secondary_component, step_array.len()),
&step_array,
is_dark,
&p_ref.neutral_8,
text_steps_array.as_ref(),
),
@ -906,10 +937,16 @@ impl ThemeBuilder {
get_text(
base_index,
&step_array,
is_dark,
&p_ref.neutral_8,
text_steps_array.as_ref(),
),
get_surface_color(
base_index,
5,
&neutral_steps,
base_index <= 65,
&p_ref.neutral_6,
),
)
},
accent: Component::colored_component(