Skip to content

Commit

Permalink
Added color for warning for TERRA, and added warning field to Extende…
Browse files Browse the repository at this point in the history
…d with the needed struct and generate
  • Loading branch information
DavidAguilo committed Sep 25, 2024
1 parent 139e1fe commit cc5a498
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions core/src/theme/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ impl Palette {
primary: color!(0xd1d1e0),
success: color!(0xb1b695),
danger: color!(0xe06b75),
warning: color!(0xf5d76e), // Honey
};
}

Expand All @@ -333,6 +334,8 @@ pub struct Extended {
pub success: Success,
/// The set of danger colors.
pub danger: Danger,
/// The set of warning colors.
pub warning: Warning,
/// Whether the palette is dark or not.
pub is_dark: bool,
}
Expand Down Expand Up @@ -446,6 +449,11 @@ impl Extended {
palette.background,
palette.text,
),
warning: Warning::generate(
palette.warning,
palette.background,
palette.text,
),
is_dark: is_dark(palette.background),
}
}
Expand Down Expand Up @@ -601,6 +609,31 @@ impl Danger {
}
}

/// A set of warning colors.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Warning {
/// The base warning color.
pub base: Pair,
/// A weaker version of the base warning color.
pub weak: Pair,
/// A stronger version of the base warning color.
pub strong: Pair,
}

impl Warning {
/// Generates a set of [`Warning`] colors from the base, background, and text colors.
pub fn generate(base: Color, background: Color, text: Color) -> Self {
let weak = mix(base, background, 0.4);
let strong = deviate(base, 0.1);

Self {
base: Pair::new(base, text),
weak: Pair::new(weak, text),
strong: Pair::new(strong, text),
}
}
}

fn darken(color: Color, amount: f32) -> Color {
let mut hsl = to_hsl(color);

Expand Down

0 comments on commit cc5a498

Please sign in to comment.