Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add warning color to palette #2607

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
64 changes: 64 additions & 0 deletions core/src/theme/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct Palette {
pub success: Color,
/// The danger [`Color`] of the [`Palette`].
pub danger: Color,
/// The warning [`Color`] of the [`Palette`].
pub warning: Color,
}

impl Palette {
Expand All @@ -41,6 +43,11 @@ impl Palette {
0x42 as f32 / 255.0,
0x3F as f32 / 255.0,
),
warning: Color::from_rgb(
0xFF as f32 / 255.0,
0xC1 as f32 / 255.0,
0x4E as f32 / 255.0,
),
};

/// The built-in dark variant of a [`Palette`].
Expand All @@ -66,6 +73,11 @@ impl Palette {
0x42 as f32 / 255.0,
0x3F as f32 / 255.0,
),
warning: Color::from_rgb(
0xFF as f32 / 255.0,
0xC1 as f32 / 255.0,
0x4E as f32 / 255.0,
),
};

/// The built-in [Dracula] variant of a [`Palette`].
Expand All @@ -77,6 +89,7 @@ impl Palette {
primary: color!(0xbd93f9), // PURPLE
success: color!(0x50fa7b), // GREEN
danger: color!(0xff5555), // RED
warning: color!(0xf1fa8c), // YELLOW
};

/// The built-in [Nord] variant of a [`Palette`].
Expand All @@ -88,6 +101,7 @@ impl Palette {
primary: color!(0x8fbcbb), // nord7
success: color!(0xa3be8c), // nord14
danger: color!(0xbf616a), // nord11
warning: color!(0xebcb8b), // nord13
};

/// The built-in [Solarized] Light variant of a [`Palette`].
Expand All @@ -99,6 +113,7 @@ impl Palette {
primary: color!(0x2aa198), // cyan
success: color!(0x859900), // green
danger: color!(0xdc322f), // red
warning: color!(0xb58900), // yellow
};

/// The built-in [Solarized] Dark variant of a [`Palette`].
Expand All @@ -110,6 +125,7 @@ impl Palette {
primary: color!(0x2aa198), // cyan
success: color!(0x859900), // green
danger: color!(0xdc322f), // red
warning: color!(0xb58900), // yellow
};

/// The built-in [Gruvbox] Light variant of a [`Palette`].
Expand All @@ -121,6 +137,7 @@ impl Palette {
primary: color!(0x458588), // light BLUE_4
success: color!(0x98971a), // light GREEN_2
danger: color!(0xcc241d), // light RED_1
warning: color!(0xd79921), // light YELLOW_3
};

/// The built-in [Gruvbox] Dark variant of a [`Palette`].
Expand All @@ -132,6 +149,7 @@ impl Palette {
primary: color!(0x458588), // dark BLUE_4
success: color!(0x98971a), // dark GREEN_2
danger: color!(0xcc241d), // dark RED_1
warning: color!(0xd79921), // dark YELLOW_3
};

/// The built-in [Catppuccin] Latte variant of a [`Palette`].
Expand All @@ -143,6 +161,7 @@ impl Palette {
primary: color!(0x1e66f5), // Blue
success: color!(0x40a02b), // Green
danger: color!(0xd20f39), // Red
warning: color!(0xdf8e1d), // Yellow
};

/// The built-in [Catppuccin] Frappé variant of a [`Palette`].
Expand All @@ -154,6 +173,7 @@ impl Palette {
primary: color!(0x8caaee), // Blue
success: color!(0xa6d189), // Green
danger: color!(0xe78284), // Red
warning: color!(0xe5c890), // Yellow
};

/// The built-in [Catppuccin] Macchiato variant of a [`Palette`].
Expand All @@ -165,6 +185,7 @@ impl Palette {
primary: color!(0x8aadf4), // Blue
success: color!(0xa6da95), // Green
danger: color!(0xed8796), // Red
warning: color!(0xeed49f), // Yellow
};

/// The built-in [Catppuccin] Mocha variant of a [`Palette`].
Expand All @@ -176,6 +197,7 @@ impl Palette {
primary: color!(0x89b4fa), // Blue
success: color!(0xa6e3a1), // Green
danger: color!(0xf38ba8), // Red
warning: color!(0xf9e2af), // Yellow
};

/// The built-in [Tokyo Night] variant of a [`Palette`].
Expand All @@ -187,6 +209,7 @@ impl Palette {
primary: color!(0x2ac3de), // Blue
success: color!(0x9ece6a), // Green
danger: color!(0xf7768e), // Red
warning: color!(0xe0af68), // Yellow
};

/// The built-in [Tokyo Night] Storm variant of a [`Palette`].
Expand All @@ -198,6 +221,7 @@ impl Palette {
primary: color!(0x2ac3de), // Blue
success: color!(0x9ece6a), // Green
danger: color!(0xf7768e), // Red
warning: color!(0xe0af68), // Yellow
};

/// The built-in [Tokyo Night] Light variant of a [`Palette`].
Expand All @@ -209,6 +233,7 @@ impl Palette {
primary: color!(0x166775), // Blue
success: color!(0x485e30), // Green
danger: color!(0x8c4351), // Red
warning: color!(0x8f5e15), // Yellow
};

/// The built-in [Kanagawa] Wave variant of a [`Palette`].
Expand All @@ -220,6 +245,7 @@ impl Palette {
primary: color!(0x2D4F67), // Wave Blue 2
success: color!(0x76946A), // Autumn Green
danger: color!(0xC34043), // Autumn Red
warning: color!(0xff9e3b), // Ronin Yellow
};

/// The built-in [Kanagawa] Dragon variant of a [`Palette`].
Expand All @@ -231,6 +257,7 @@ impl Palette {
primary: color!(0x223249), // Wave Blue 1
success: color!(0x8a9a7b), // Dragon Green 2
danger: color!(0xc4746e), // Dragon Red
warning: color!(0xff9e3b), // Ronin Yellow
};

/// The built-in [Kanagawa] Lotus variant of a [`Palette`].
Expand All @@ -242,6 +269,7 @@ impl Palette {
primary: color!(0xc9cbd1), // Lotus Violet 3
success: color!(0x6f894e), // Lotus Green
danger: color!(0xc84053), // Lotus Red
warning: color!(0xe98a00), // Lotus Orange 2
};

/// The built-in [Moonfly] variant of a [`Palette`].
Expand All @@ -253,6 +281,7 @@ impl Palette {
primary: color!(0x80a0ff), // Blue (normal)
success: color!(0x8cc85f), // Green (normal)
danger: color!(0xff5454), // Red (normal)
warning: color!(0xe3c78a), // Yellow (normal)
};

/// The built-in [Nightfly] variant of a [`Palette`].
Expand All @@ -264,6 +293,7 @@ impl Palette {
primary: color!(0x82aaff), // Blue (normal)
success: color!(0xa1cd5e), // Green (normal)
danger: color!(0xfc514e), // Red (normal)
warning: color!(0xe3d18a), // Yellow (normal)
};

/// The built-in [Oxocarbon] variant of a [`Palette`].
Expand All @@ -275,6 +305,7 @@ impl Palette {
primary: color!(0x00b4ff),
success: color!(0x00c15a),
danger: color!(0xf62d0f),
warning: color!(0xbe95ff), // Base 14
};

/// The built-in [Ferra] variant of a [`Palette`].
Expand All @@ -286,6 +317,7 @@ impl Palette {
primary: color!(0xd1d1e0),
success: color!(0xb1b695),
danger: color!(0xe06b75),
warning: color!(0xf5d76e), // Honey
};
}

Expand All @@ -302,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 @@ -415,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 @@ -570,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