use wgpu_canvas::Color;
use std::collections::HashMap;
#[derive(Clone, Debug, Default)]
pub struct ColorResources {
pub background: BackgroundColor,
pub outline: OutlineColor,
pub status: StatusColor,
pub text: TextColor,
pub button: ButtonColors,
pub brand: BrandColor,
pub shades: ShadesColor,
pub illustration: IllustrationColors,
}
impl ColorResources {
#[allow(clippy::too_many_arguments)]
pub fn new(
background: BackgroundColor,
outline: OutlineColor,
status: StatusColor,
text: TextColor,
brand: BrandColor,
button: ButtonColors,
illustration: IllustrationColors,
) -> Self {
ColorResources { background, outline, status, text, brand, shades: ShadesColor::default(), button, illustration }
}
pub fn light(primary: Color) -> Self {
ColorResources {
background: BackgroundColor {
primary: Color::from_hex("#FFFFFF", 255),
secondary: Color::from_hex("#DDDDDD", 255),
},
outline: OutlineColor {
primary: Color::from_hex("#000000", 255),
secondary: Color::from_hex("#444444", 255),
},
status: StatusColor::default(),
text: TextColor {
heading: Color::from_hex("#000000", 255),
primary: Color::from_hex("#000000", 255),
secondary: Color::from_hex("#444444", 255),
},
brand: BrandColor {
primary,
secondary: Color::from_hex("#000000", 255),
},
shades: ShadesColor::default(),
button: ButtonColors::from_brand(primary),
illustration: IllustrationColors::default(),
}
}
pub fn dark(primary: Color) -> Self {
ColorResources {
background: BackgroundColor {
primary: Color::from_hex("#000000", 255),
secondary: Color::from_hex("#222222", 255),
},
outline: OutlineColor {
primary: Color::from_hex("#FFFFFF", 255),
secondary: Color::from_hex("#AAAAAA", 255),
},
status: StatusColor::default(),
text: TextColor {
heading: Color::from_hex("#FFFFFF", 255),
primary: Color::from_hex("#FFFFFF", 255),
secondary: Color::from_hex("#AAAAAA", 255),
},
brand: BrandColor {
primary,
secondary: Color::from_hex("#FFFFFF", 255),
},
shades: ShadesColor::default(),
button: ButtonColors::from_brand(primary),
illustration: IllustrationColors::default(),
}
}
pub fn new_from(primary: Color) -> Self {
let (r, g, b) = (primary.0, primary.1, primary.2);
let brightness = 0.299 * r as f32 + 0.587 * g as f32 + 0.114 * b as f32;
match brightness > 100.0 {
true => Self::dark(primary),
false => Self::light(primary)
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct ShadesColor {
pub black: Color,
pub white: Color,
pub lighten: Color,
pub lighten2: Color,
pub darken: Color,
pub darken2: Color,
pub transparent: Color,
}
impl Default for ShadesColor {
fn default() -> Self {
ShadesColor {
black: Color::from_hex("000000", 255),
white: Color::from_hex("ffffff", 255),
lighten: Color::from_hex("ffffff", 110),
lighten2: Color::from_hex("ffffff", 180),
darken: Color::from_hex("000000", 110),
darken2: Color::from_hex("000000", 180),
transparent: Color::from_hex("000000", 0),
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct BackgroundColor {
pub primary: Color,
pub secondary: Color,
}
impl Default for BackgroundColor {
fn default() -> Self {
BackgroundColor {
primary: Color::from_hex("000000", 255),
secondary: Color::from_hex("262322", 255),
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct BrandColor {
pub primary: Color,
pub secondary: Color,
}
impl Default for BrandColor {
fn default() -> Self {
BrandColor {
primary: Color::from_hex("eb343a", 255),
secondary: Color::from_hex("ffffff", 255),
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct OutlineColor {
pub primary: Color,
pub secondary: Color,
}
impl Default for OutlineColor {
fn default() -> Self {
OutlineColor {
primary: Color::from_hex("ffffff", 255),
secondary: Color::from_hex("585250", 255),
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct TextColor {
pub heading: Color,
pub primary: Color,
pub secondary: Color,
}
impl Default for TextColor {
fn default() -> Self {
TextColor {
heading: Color::from_hex("ffffff", 255),
primary: Color::from_hex("e2e1df", 255),
secondary: Color::from_hex("a7a29d", 255),
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct StatusColor {
pub success: Color,
pub warning: Color,
pub danger: Color,
}
impl Default for StatusColor {
fn default() -> Self {
StatusColor {
success: Color::from_hex("3ccb5a", 255),
warning: Color::from_hex("f5bd14", 255),
danger: Color::from_hex("ff330a", 255),
}
}
}
#[derive(Clone, Debug, Default)]
pub struct IllustrationColors {
pub colors: HashMap<&'static str, Color>,
}
#[derive(Copy, Clone, Debug)]
pub struct ButtonColors {
pub primary_default: ButtonColorScheme,
pub primary_disabled: ButtonColorScheme,
pub primary_hover: ButtonColorScheme,
pub primary_selected: ButtonColorScheme,
pub primary_pressed: ButtonColorScheme,
pub secondary_default: ButtonColorScheme,
pub secondary_disabled: ButtonColorScheme,
pub secondary_hover: ButtonColorScheme,
pub secondary_selected: ButtonColorScheme,
pub secondary_pressed: ButtonColorScheme,
pub ghost_default: ButtonColorScheme,
pub ghost_disabled: ButtonColorScheme,
pub ghost_hover: ButtonColorScheme,
pub ghost_selected: ButtonColorScheme,
pub ghost_pressed: ButtonColorScheme,
}
impl ButtonColors {
pub fn from_brand(brand: Color) -> Self {
ButtonColors {
primary_default: ButtonColorScheme {
background: brand,
label: Color::from_hex("FFFFFF", 255),
outline: Color::from_hex("000000", 0),
},
primary_disabled: ButtonColorScheme {
background: Color::from_hex("443f3f", 255),
label: Color::from_hex("000000", 255),
outline: Color::from_hex("000000", 0),
},
primary_hover: ButtonColorScheme {
background: Self::darken(brand, 0.85),
label: Color::from_hex("FFFFFF", 255),
outline: Color::from_hex("000000", 0),
},
primary_selected: ButtonColorScheme {
background: Self::darken(brand, 0.85),
label: Color::from_hex("FFFFFF", 255),
outline: Color::from_hex("000000", 0),
},
primary_pressed: ButtonColorScheme {
background: Self::darken(brand, 0.85),
label: Color::from_hex("FFFFFF", 255),
outline: Color::from_hex("000000", 0),
},
secondary_default: ButtonColorScheme {
background: Color::from_hex("000000", 0),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("585250", 255),
},
secondary_disabled: ButtonColorScheme {
background: Color::from_hex("78716c", 255),
label: Color::from_hex("000000", 255),
outline:Color::from_hex("585250", 255),
},
secondary_hover: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("585250", 255),
},
secondary_selected: ButtonColorScheme {
background: Color::from_hex("000000", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("ffffff", 255),
},
secondary_pressed: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("585250", 255),
},
ghost_default: ButtonColorScheme {
background: Color::from_hex("000000", 0),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
ghost_disabled: ButtonColorScheme {
background: Color::from_hex("000000", 0),
label: Color::from_hex("78716c", 255),
outline: Color::from_hex("000000", 0),
},
ghost_hover: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
ghost_selected: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
ghost_pressed: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
}
}
fn darken(c: Color, factor: f32) -> Color {
Color (
(c.0 as f32 * factor) as u8,
(c.1 as f32 * factor) as u8,
(c.2 as f32 * factor) as u8,
c.3,
)
}
}
impl Default for ButtonColors {
fn default() -> Self {
ButtonColors {
primary_default: ButtonColorScheme {
background: Color::from_hex("eb343a", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
primary_disabled: ButtonColorScheme {
background: Color::from_hex("443f3f", 255),
label: Color::from_hex("000000", 255),
outline: Color::from_hex("000000", 0),
},
primary_hover: ButtonColorScheme {
background: Color::from_hex("da282e", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
primary_selected: ButtonColorScheme {
background: Color::from_hex("da282e", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
primary_pressed: ButtonColorScheme {
background: Color::from_hex("da282e", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
secondary_default: ButtonColorScheme {
background: Color::from_hex("000000", 0),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("585250", 255),
},
secondary_disabled: ButtonColorScheme {
background: Color::from_hex("78716c", 255),
label: Color::from_hex("000000", 255),
outline:Color::from_hex("585250", 255),
},
secondary_hover: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("585250", 255),
},
secondary_selected: ButtonColorScheme {
background: Color::from_hex("000000", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("ffffff", 255),
},
secondary_pressed: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("585250", 255),
},
ghost_default: ButtonColorScheme {
background: Color::from_hex("000000", 0),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
ghost_disabled: ButtonColorScheme {
background: Color::from_hex("000000", 0),
label: Color::from_hex("78716c", 255),
outline: Color::from_hex("000000", 0),
},
ghost_hover: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
ghost_selected: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
ghost_pressed: ButtonColorScheme {
background: Color::from_hex("262322", 255),
label: Color::from_hex("ffffff", 255),
outline: Color::from_hex("000000", 0),
},
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct ButtonColorScheme {
pub background: Color,
pub label: Color,
pub outline: Color,
}