improv(theme): theme generation improvements
This commit is contained in:
parent
950a1a54f5
commit
14bd633356
6 changed files with 146 additions and 88 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -43,16 +43,15 @@ pub fn get_surface_color(
|
|||
|
||||
is_dark = is_dark || base_index < 91;
|
||||
|
||||
get_index(base_index, steps, step_array.len(), is_dark)
|
||||
.and_then(|i| step_array.get(i).cloned())
|
||||
.unwrap_or_else(|| fallback.to_owned())
|
||||
*get_index(base_index, steps, step_array.len(), is_dark)
|
||||
.and_then(|i| step_array.get(i))
|
||||
.unwrap_or(fallback)
|
||||
}
|
||||
|
||||
/// get text color given a base background color
|
||||
pub fn get_text(
|
||||
base_index: usize,
|
||||
step_array: &Vec<Srgba>,
|
||||
is_dark: bool,
|
||||
fallback: &Srgba,
|
||||
tint_array: Option<&Vec<Srgba>>,
|
||||
) -> Srgba {
|
||||
|
|
@ -63,16 +62,14 @@ pub fn get_text(
|
|||
} else {
|
||||
step_array
|
||||
};
|
||||
let Some(index) = get_index(base_index, 70, step_array.len(), is_dark)
|
||||
.or_else(|| get_index(base_index, 50, step_array.len(), is_dark))
|
||||
else {
|
||||
return fallback.to_owned();
|
||||
};
|
||||
|
||||
step_array
|
||||
.get(index)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| fallback.to_owned())
|
||||
let is_dark = base_index < 60;
|
||||
|
||||
let index = get_index(base_index, 70, step_array.len(), is_dark)
|
||||
.or_else(|| get_index(base_index, 50, step_array.len(), is_dark))
|
||||
.unwrap_or_else(|| if is_dark { 99 } else { 0 });
|
||||
|
||||
*step_array.get(index).unwrap_or(fallback)
|
||||
}
|
||||
|
||||
/// get the index into the steps array for a given color
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue