Skip to content

Commit

Permalink
Merge pull request #23 from PoSayDone/add_additional_surfaces
Browse files Browse the repository at this point in the history
Added new surfaces, fixed colors, removed deprecated colors, changed chroma for neutral palette
  • Loading branch information
InioX authored Nov 14, 2023
2 parents ceead3e + dc41b5d commit a381826
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 28 deletions.
8 changes: 4 additions & 4 deletions material-color-utilities-rs/src/palettes/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl CorePalette {
a1: TonalPalette::from_hue_and_chroma(hue, chroma),
a2: TonalPalette::from_hue_and_chroma(hue, chroma / 3.),
a3: TonalPalette::from_hue_and_chroma(hue + 60., chroma / 2.),
n1: TonalPalette::from_hue_and_chroma(hue, (chroma / 12.).min(4.0)),
n1: TonalPalette::from_hue_and_chroma(hue, (chroma / 12.).min(6.0)),
n2: TonalPalette::from_hue_and_chroma(hue, (chroma / 6.).min(8.0)),
error,
},
Expand All @@ -44,7 +44,7 @@ impl CorePalette {
a1: TonalPalette::from_hue_and_chroma(hue, chroma),
a2: TonalPalette::from_hue_and_chroma(hue + angle, chroma / 3.),
a3: TonalPalette::from_hue_and_chroma(hue - angle, chroma / 2.),
n1: TonalPalette::from_hue_and_chroma(hue, (chroma / 12.).min(4.0)),
n1: TonalPalette::from_hue_and_chroma(hue, (chroma / 12.).min(6.0)),
n2: TonalPalette::from_hue_and_chroma(hue, (chroma / 6.).min(8.0)),
error,
}
Expand All @@ -55,7 +55,7 @@ impl CorePalette {
a1: TonalPalette::from_hue_and_chroma(hue, chroma),
a2: TonalPalette::from_hue_and_chroma(hue + angle, chroma / 3.),
a3: TonalPalette::from_hue_and_chroma(hue - angle, chroma / 2.),
n1: TonalPalette::from_hue_and_chroma(hue, (chroma / 12.).min(4.0)),
n1: TonalPalette::from_hue_and_chroma(hue, (chroma / 12.).min(6.0)),
n2: TonalPalette::from_hue_and_chroma(hue, (chroma / 6.).min(8.0)),
error,
}
Expand All @@ -66,7 +66,7 @@ impl CorePalette {
a1: TonalPalette::from_hue_and_chroma(hue, 48.0f64.max(chroma)),
a2: TonalPalette::from_hue_and_chroma(hue, 16.),
a3: TonalPalette::from_hue_and_chroma(hue + 60., 24.),
n1: TonalPalette::from_hue_and_chroma(hue, 4.),
n1: TonalPalette::from_hue_and_chroma(hue, 6.),
n2: TonalPalette::from_hue_and_chroma(hue, 8.),
error,
}
Expand Down
114 changes: 97 additions & 17 deletions material-color-utilities-rs/src/scheme/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,35 @@ use serde::{ser::SerializeStruct, Serialize};
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
pub struct Scheme {
pub primary: [u8; 4],
pub primary_fixed: [u8; 4],
pub primary_fixed_dim: [u8; 4],
pub on_primary: [u8; 4],
pub on_primary_fixed: [u8; 4],
pub on_primary_fixed_variant: [u8; 4],
pub primary_container: [u8; 4],
pub on_primary_container: [u8; 4],
pub secondary: [u8; 4],
pub secondary_fixed: [u8; 4],
pub secondary_fixed_dim: [u8; 4],
pub on_secondary: [u8; 4],
pub on_secondary_fixed: [u8; 4],
pub on_secondary_fixed_variant: [u8; 4],
pub secondary_container: [u8; 4],
pub on_secondary_container: [u8; 4],
pub tertiary: [u8; 4],
pub tertiary_fixed: [u8; 4],
pub tertiary_fixed_dim: [u8; 4],
pub on_tertiary: [u8; 4],
pub on_tertiary_fixed: [u8; 4],
pub on_tertiary_fixed_variant: [u8; 4],
pub tertiary_container: [u8; 4],
pub on_tertiary_container: [u8; 4],
pub error: [u8; 4],
pub on_error: [u8; 4],
pub error_container: [u8; 4],
pub on_error_container: [u8; 4],
pub background: [u8; 4],
pub on_background: [u8; 4],
pub surface: [u8; 4],
pub on_surface: [u8; 4],
pub surface_variant: [u8; 4],
pub on_surface_variant: [u8; 4],
pub outline: [u8; 4],
pub outline_variant: [u8; 4],
Expand All @@ -36,6 +45,13 @@ pub struct Scheme {
pub inverse_surface: [u8; 4],
pub inverse_on_surface: [u8; 4],
pub inverse_primary: [u8; 4],
pub surface_dim: [u8; 4],
pub surface_bright: [u8; 4],
pub surface_container_lowest: [u8; 4],
pub surface_container_low: [u8; 4],
pub surface_container: [u8; 4],
pub surface_container_high: [u8; 4],
pub surface_container_highest: [u8; 4],
}

#[cfg(feature = "serde")]
Expand All @@ -55,26 +71,35 @@ impl Serialize for Scheme {
}

ser!(primary);
ser!(primary_fixed);
ser!(primary_fixed_dim);
ser!(on_primary);
ser!(on_primary_fixed);
ser!(on_primary_fixed_variant);
ser!(primary_container);
ser!(on_primary_container);
ser!(secondary);
ser!(secondary_fixed);
ser!(secondary_fixed_dim);
ser!(on_secondary);
ser!(on_secondary_fixed);
ser!(on_secondary_fixed_variant);
ser!(secondary_container);
ser!(on_secondary_container);
ser!(tertiary);
ser!(tertiary_fixed);
ser!(tertiary_fixed_dim);
ser!(on_tertiary);
ser!(on_tertiary_fixed);
ser!(on_tertiary_fixed_variant);
ser!(tertiary_container);
ser!(on_tertiary_container);
ser!(error);
ser!(on_error);
ser!(error_container);
ser!(on_error_container);
ser!(background);
ser!(on_background);
ser!(surface);
ser!(on_surface);
ser!(surface_variant);
ser!(on_surface_variant);
ser!(outline);
ser!(outline_variant);
Expand All @@ -83,6 +108,13 @@ impl Serialize for Scheme {
ser!(inverse_surface);
ser!(inverse_on_surface);
ser!(inverse_primary);
ser!(surface_dim);
ser!(surface_bright);
ser!(surface_container_lowest);
ser!(surface_container_low);
ser!(surface_container);
ser!(surface_container_high);
ser!(surface_container_highest);

state.end()
}
Expand All @@ -92,26 +124,35 @@ impl Scheme {
pub fn light_from_core_palette(core: &mut CorePalette) -> Scheme {
Scheme {
primary: core.a1.tone(40),
primary_fixed: core.a1.tone(90),
primary_fixed_dim: core.a1.tone(80),
on_primary: core.a1.tone(100),
on_primary_fixed: core.a1.tone(10),
on_primary_fixed_variant: core.a1.tone(30),
primary_container: core.a1.tone(90),
on_primary_container: core.a1.tone(10),
secondary: core.a2.tone(40),
secondary_fixed: core.a2.tone(90),
secondary_fixed_dim: core.a2.tone(80),
on_secondary: core.a2.tone(100),
on_secondary_fixed: core.a2.tone(10),
on_secondary_fixed_variant: core.a2.tone(30),
secondary_container: core.a2.tone(90),
on_secondary_container: core.a2.tone(10),
tertiary: core.a3.tone(40),
tertiary_fixed: core.a3.tone(90),
tertiary_fixed_dim: core.a3.tone(80),
on_tertiary: core.a3.tone(100),
on_tertiary_fixed: core.a3.tone(10),
on_tertiary_fixed_variant: core.a3.tone(30),
tertiary_container: core.a3.tone(90),
on_tertiary_container: core.a3.tone(10),
error: core.error.tone(40),
on_error: core.error.tone(100),
error_container: core.error.tone(90),
on_error_container: core.error.tone(10),
background: core.n1.tone(99),
on_background: core.n1.tone(10),
surface: core.n1.tone(99),
surface: core.n1.tone(98),
on_surface: core.n1.tone(10),
surface_variant: core.n2.tone(90),
on_surface_variant: core.n2.tone(30),
outline: core.n2.tone(50),
outline_variant: core.n2.tone(80),
Expand All @@ -120,32 +161,48 @@ impl Scheme {
inverse_surface: core.n1.tone(20),
inverse_on_surface: core.n1.tone(95),
inverse_primary: core.a1.tone(80),
surface_dim: core.n1.tone(87),
surface_bright: core.n1.tone(98),
surface_container_lowest: core.n1.tone(100),
surface_container_low: core.n1.tone(96),
surface_container: core.n1.tone(94),
surface_container_high: core.n1.tone(92),
surface_container_highest: core.n1.tone(90),
}
}

pub fn dark_from_core_palette(core: &mut CorePalette) -> Scheme {
Scheme {
primary: core.a1.tone(80),
primary_fixed: core.a1.tone(90),
primary_fixed_dim: core.a1.tone(80),
on_primary: core.a1.tone(20),
on_primary_fixed: core.a1.tone(10),
on_primary_fixed_variant: core.a1.tone(30),
primary_container: core.a1.tone(30),
on_primary_container: core.a1.tone(90),
secondary: core.a2.tone(80),
secondary_fixed: core.a2.tone(90),
secondary_fixed_dim: core.a2.tone(80),
on_secondary: core.a2.tone(20),
on_secondary_fixed: core.a2.tone(10),
on_secondary_fixed_variant: core.a2.tone(30),
secondary_container: core.a2.tone(30),
on_secondary_container: core.a2.tone(90),
tertiary: core.a3.tone(80),
tertiary_fixed: core.a3.tone(90),
tertiary_fixed_dim: core.a3.tone(80),
on_tertiary: core.a3.tone(20),
on_tertiary_fixed: core.a3.tone(10),
on_tertiary_fixed_variant: core.a3.tone(30),
tertiary_container: core.a3.tone(30),
on_tertiary_container: core.a3.tone(90),
error: core.error.tone(80),
on_error: core.error.tone(20),
error_container: core.error.tone(30),
on_error_container: core.error.tone(80),
background: core.n1.tone(10),
on_background: core.n1.tone(90),
surface: core.n1.tone(10),
surface: core.n1.tone(6),
on_surface: core.n1.tone(90),
surface_variant: core.n2.tone(30),
on_surface_variant: core.n2.tone(80),
outline: core.n2.tone(60),
outline_variant: core.n2.tone(30),
Expand All @@ -154,32 +211,48 @@ impl Scheme {
inverse_surface: core.n1.tone(90),
inverse_on_surface: core.n1.tone(20),
inverse_primary: core.a1.tone(40),
surface_dim: core.n1.tone(6),
surface_bright: core.n1.tone(24),
surface_container_lowest: core.n1.tone(4),
surface_container_low: core.n1.tone(10),
surface_container: core.n1.tone(12),
surface_container_high: core.n1.tone(17),
surface_container_highest: core.n1.tone(22),
}
}

pub fn pure_dark_from_core_palette(core: &mut CorePalette) -> Scheme {
Scheme {
primary: core.a1.tone(80),
primary_fixed: core.a1.tone(90),
primary_fixed_dim: core.a1.tone(80),
on_primary: core.a1.tone(20),
on_primary_fixed: core.a1.tone(10),
on_primary_fixed_variant: core.a1.tone(30),
primary_container: core.a1.tone(30),
on_primary_container: core.a1.tone(90),
secondary: core.a2.tone(80),
secondary_fixed: core.a2.tone(90),
secondary_fixed_dim: core.a2.tone(80),
on_secondary: core.a2.tone(20),
on_secondary_fixed: core.a2.tone(10),
on_secondary_fixed_variant: core.a2.tone(30),
secondary_container: core.a2.tone(30),
on_secondary_container: core.a2.tone(90),
tertiary: core.a3.tone(80),
tertiary_fixed: core.a3.tone(90),
tertiary_fixed_dim: core.a3.tone(80),
on_tertiary: core.a3.tone(20),
on_tertiary_fixed: core.a3.tone(10),
on_tertiary_fixed_variant: core.a3.tone(30),
tertiary_container: core.a3.tone(30),
on_tertiary_container: core.a3.tone(90),
error: core.error.tone(80),
on_error: core.error.tone(20),
error_container: core.error.tone(30),
on_error_container: core.error.tone(80),
background: core.n1.tone(0),
on_background: core.n1.tone(90),
surface: core.n1.tone(0),
on_surface: core.n1.tone(90),
surface_variant: core.n2.tone(5),
on_surface_variant: core.n2.tone(80),
outline: core.n2.tone(60),
outline_variant: core.n2.tone(30),
Expand All @@ -188,6 +261,13 @@ impl Scheme {
inverse_surface: core.n1.tone(90),
inverse_on_surface: core.n1.tone(20),
inverse_primary: core.a1.tone(40),
surface_dim: core.n1.tone(87),
surface_bright: core.n1.tone(98),
surface_container_lowest: core.n1.tone(100),
surface_container_low: core.n1.tone(96),
surface_container: core.n1.tone(94),
surface_container_high: core.n1.tone(92),
surface_container_highest: core.n1.tone(90),
}
}
}
Loading

0 comments on commit a381826

Please sign in to comment.