use roost::drawable::Color;
#[derive(Clone, Debug, Default, Copy)]
pub struct ColorResources {
pub background: BackgroundColor,
pub outline: OutlineColor,
pub status: StatusColor,
pub text: TextColor,
pub button: ButtonColors,
pub brand: Color,
}
impl ColorResources {
#[allow(clippy::too_many_arguments)]
pub fn new(
background: BackgroundColor,
outline: OutlineColor,
status: StatusColor,
text: TextColor,
brand: Color,
button: ButtonColors,
) -> Self {
ColorResources { background, outline, status, text, brand, button }
}
pub fn light(brand: Color) -> Self {
ColorResources {
background: BackgroundColor::light(),
outline: OutlineColor::light(),
status: StatusColor::default(),
text: TextColor::light(),
brand,
button: ButtonColors::from(brand, true),
}
}
pub fn dark(brand: Color) -> Self {
ColorResources {
background: BackgroundColor::dark(),
outline: OutlineColor::dark(),
status: StatusColor::default(),
text: TextColor::dark(),
brand,
button: ButtonColors::from(brand, false),
}
}
pub fn from(brand: Color) -> Self {
match Color::is_high_contrast(brand) {
true => Self::dark(brand),
false => Self::light(brand)
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct BackgroundColor {
pub primary: Color,
pub secondary: Color,
}
impl BackgroundColor {
pub fn dark() -> Self {
BackgroundColor {
primary: Color::BLACK,
secondary: Color::from_hex("#262322", 255),
}
}
pub fn light() -> Self {
BackgroundColor {
primary: Color::WHITE,
secondary: Color::from_hex("#DDDDDD", 255),
}
}
}
impl Default for BackgroundColor {
fn default() -> Self { Self::dark() }
}
#[derive(Copy, Clone, Debug)]
pub struct OutlineColor {
pub primary: Color,
pub secondary: Color,
}
impl OutlineColor {
pub fn dark() -> Self {
OutlineColor {
primary: Color::WHITE,
secondary: Color::from_hex("#585250", 255),
}
}
pub fn light() -> Self {
OutlineColor {
primary: Color::from_hex("#9e9e9e", 255),
secondary: Color::from_hex("#444444", 255),
}
}
}
impl Default for OutlineColor {
fn default() -> Self { Self::dark() }
}
#[derive(Copy, Clone, Debug)]
pub struct TextColor {
pub heading: Color,
pub primary: Color,
pub secondary: Color,
}
impl TextColor {
pub fn dark() -> Self {
TextColor {
heading: Color::WHITE,
primary: Color::from_hex("#e2e1df", 255),
secondary: Color::from_hex("#a7a29d", 255),
}
}
pub fn light() -> Self {
TextColor {
heading: Color::BLACK,
primary: Color::BLACK,
secondary: Color::from_hex("#9e9e9e", 255),
}
}
}
impl Default for TextColor {
fn default() -> Self { Self::dark() }
}
#[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(Copy, Clone, Debug)]
pub struct ButtonColors {
pub primary: ButtonColorSet,
pub secondary: ButtonColorSet,
pub ghost: ButtonColorSet,
}
impl ButtonColors {
pub fn from(brand: Color, is_light: bool) -> Self {
let label = if is_light {Color::WHITE} else {Color::BLACK};
ButtonColors {
primary: ButtonColorSet::primary(brand, label),
secondary: ButtonColorSet::secondary(is_light),
ghost: ButtonColorSet::ghost(is_light),
}
}
}
impl Default for ButtonColors {
fn default() -> Self {
ButtonColors {
primary: ButtonColorSet::primary(Color::from_hex("#02f0cc", 255), Color::WHITE),
secondary: ButtonColorSet::secondary(false),
ghost: ButtonColorSet::ghost(false),
}
}
}
#[derive(Copy, Clone, Debug)]
pub struct ButtonColorScheme {
pub background: Color,
pub label: Color,
pub outline: Color,
}
#[derive(Copy, Clone, Debug)]
pub struct ButtonColorSet {
pub default: ButtonColorScheme,
pub disabled: ButtonColorScheme,
pub hover: ButtonColorScheme,
pub pressed: ButtonColorScheme,
}
impl ButtonColorSet {
pub fn primary(brand: Color, label: Color) -> Self {
ButtonColorSet {
default: ButtonColorScheme {
background: brand,
label,
outline: Color::TRANSPARENT,
},
disabled: ButtonColorScheme {
background: Color::from_hex("#443f3f", 255),
label: Color::BLACK,
outline: Color::TRANSPARENT,
},
hover: ButtonColorScheme {
background: Color::darken(brand, 0.85),
label,
outline: Color::TRANSPARENT,
},
pressed: ButtonColorScheme {
background: Color::darken(brand, 0.8),
label,
outline: Color::TRANSPARENT
}
}
}
pub fn secondary(is_light: bool) -> Self {
ButtonColorSet {
default: ButtonColorScheme {
background: Color::TRANSPARENT,
label: if is_light {Color::BLACK} else {Color::WHITE},
outline: Color::from_hex("#585250", 255),
},
disabled: ButtonColorScheme {
background: Color::from_hex("#78716c", 255),
label: Color::BLACK,
outline:Color::from_hex("#585250", 255),
},
hover: ButtonColorScheme {
background: if is_light {Color::from_hex("#dcdbda", 255)} else {Color::from_hex("#262322", 255)},
label: if is_light {Color::BLACK} else {Color::WHITE},
outline: Color::from_hex("#585250", 255),
},
pressed: ButtonColorScheme {
background: if is_light {Color::from_hex("#dcdbda", 255)} else {Color::from_hex("#262322", 255)},
label: Color::WHITE,
outline: if is_light {Color::BLACK} else {Color::WHITE},
}
}
}
pub fn ghost(is_light: bool) -> Self {
ButtonColorSet {
default: ButtonColorScheme {
background: Color::TRANSPARENT,
label: if is_light {Color::BLACK} else {Color::WHITE},
outline: Color::TRANSPARENT,
},
disabled: ButtonColorScheme {
background: Color::TRANSPARENT,
label: Color::from_hex("#78716c", 255),
outline: Color::TRANSPARENT,
},
hover: ButtonColorScheme {
background: if is_light {Color::from_hex("#dcdbda", 255)} else {Color::from_hex("#262322", 255)},
label: if is_light {Color::BLACK} else {Color::WHITE},
outline: Color::TRANSPARENT,
},
pressed: ButtonColorScheme {
background: if is_light {Color::from_hex("#dcdbda", 255)} else {Color::from_hex("#262322", 255)},
label: if is_light {Color::BLACK} else {Color::WHITE},
outline: Color::TRANSPARENT,
}
}
}
}