wip: theme update & some cleanup
This commit is contained in:
parent
54d47a1b38
commit
620c1adb74
17 changed files with 181 additions and 905 deletions
|
|
@ -1,26 +0,0 @@
|
|||
/// Cosmic theme custom constraints which are used to pick colors
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct ThemeConstraints {
|
||||
/// requested contrast ratio for elevated surfaces
|
||||
pub elevated_contrast_ratio: f32,
|
||||
/// requested contrast ratio for dividers
|
||||
pub divider_contrast_ratio: f32,
|
||||
/// requested contrast ratio for text
|
||||
pub text_contrast_ratio: f32,
|
||||
/// gray scale or color for dividers
|
||||
pub divider_gray_scale: bool,
|
||||
/// elevated surfaces are lightened or darkened
|
||||
pub lighten: bool,
|
||||
}
|
||||
|
||||
impl Default for ThemeConstraints {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
elevated_contrast_ratio: 1.1,
|
||||
divider_contrast_ratio: 1.51,
|
||||
text_contrast_ratio: 7.0,
|
||||
divider_gray_scale: true,
|
||||
lighten: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ use palette::Srgba;
|
|||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
use crate::{util::over, CosmicPalette};
|
||||
use crate::{composite::over, CosmicPalette};
|
||||
|
||||
/// Theme Container colors of a theme, can be a theme background container, primary container, or secondary container
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
#[cfg(feature = "contrast-derivation")]
|
||||
pub use constraint::*;
|
||||
pub use cosmic_palette::*;
|
||||
pub use derivation::*;
|
||||
#[cfg(feature = "contrast-derivation")]
|
||||
pub use selection::*;
|
||||
pub use theme::*;
|
||||
#[cfg(feature = "contrast-derivation")]
|
||||
mod constraint;
|
||||
|
||||
mod cosmic_palette;
|
||||
mod derivation;
|
||||
#[cfg(feature = "contrast-derivation")]
|
||||
mod selection;
|
||||
mod theme;
|
||||
|
|
|
|||
|
|
@ -1,99 +0,0 @@
|
|||
use palette::{named, IntoColor, Lch, Srgba};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
/// A Selection is a group of colors from which a cosmic palette can be derived
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
pub struct Selection<C> {
|
||||
/// base background container color
|
||||
pub background: C,
|
||||
/// base primary container color
|
||||
pub primary_container: C,
|
||||
/// base secondary container color
|
||||
pub secondary_container: C,
|
||||
/// base accent color
|
||||
pub accent: C,
|
||||
/// custom accent color (overrides base)
|
||||
pub accent_fg: Option<C>,
|
||||
/// custom accent nav handle text color (overrides base)
|
||||
pub accent_nav_handle_fg: Option<C>,
|
||||
/// base destructive element color
|
||||
pub destructive: C,
|
||||
/// base destructive element color
|
||||
pub warning: C,
|
||||
/// base destructive element color
|
||||
pub success: C,
|
||||
}
|
||||
|
||||
// vector should be in order of most common
|
||||
impl<C> TryFrom<Vec<Srgba>> for Selection<C>
|
||||
where
|
||||
C: Clone + From<Srgba>,
|
||||
{
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(mut colors: Vec<Srgba>) -> Result<Self, Self::Error> {
|
||||
if colors.len() < 8 {
|
||||
anyhow::bail!("length of inputted vector must be at least 8.")
|
||||
} else {
|
||||
let lch_colors: Vec<Lch> = colors
|
||||
.iter()
|
||||
.map(|x| {
|
||||
let srgba: Srgba = x.clone().into();
|
||||
srgba.color.into_format().into_color()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let red_lch: Lch = named::CRIMSON.into_format().into_color();
|
||||
let mut reddest_i = 1;
|
||||
for (i, c) in lch_colors[1..].iter().enumerate() {
|
||||
let d_cur = (c.hue.to_degrees() - red_lch.hue.to_degrees()).abs();
|
||||
let reddest_d = (lch_colors[reddest_i].hue.to_degrees().abs()
|
||||
- red_lch.hue.to_degrees().abs())
|
||||
.abs();
|
||||
if d_cur < reddest_d {
|
||||
reddest_i = i;
|
||||
}
|
||||
}
|
||||
|
||||
let yellow_lch: Lch = named::YELLOW.into_format().into_color();
|
||||
let mut yellow_i = 1;
|
||||
for (i, c) in lch_colors[1..].iter().enumerate() {
|
||||
let d_cur = (c.hue.to_degrees() - yellow_lch.hue.to_degrees()).abs();
|
||||
let reddest_d = (lch_colors[yellow_i].hue.to_degrees().abs()
|
||||
- yellow_lch.hue.to_degrees().abs())
|
||||
.abs();
|
||||
if d_cur < reddest_d {
|
||||
yellow_i = i;
|
||||
}
|
||||
}
|
||||
|
||||
let green_lch: Lch = named::GREEN.into_format().into_color();
|
||||
let mut green_i = 1;
|
||||
for (i, c) in lch_colors[1..].iter().enumerate() {
|
||||
let d_cur = (c.hue.to_degrees() - green_lch.hue.to_degrees()).abs();
|
||||
let reddest_d = (lch_colors[green_i].hue.to_degrees().abs()
|
||||
- green_lch.hue.to_degrees().abs())
|
||||
.abs();
|
||||
if d_cur < reddest_d {
|
||||
green_i = i;
|
||||
}
|
||||
}
|
||||
|
||||
let red = colors.remove(reddest_i);
|
||||
let green = colors.remove(green_i);
|
||||
let yellow = colors.remove(yellow_i);
|
||||
|
||||
Ok(Self {
|
||||
background: colors[0].into(),
|
||||
primary_container: colors[1].into(),
|
||||
secondary_container: colors[3].into(),
|
||||
accent: colors[2].into(),
|
||||
accent_fg: Some(colors[2].into()),
|
||||
accent_nav_handle_fg: Some(colors[2].into()),
|
||||
destructive: red.into(),
|
||||
warning: yellow.into(),
|
||||
success: green.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue