Rust: Add methods to Flavour
to get each colour
This adds method to get each of the colors directly from the `Flavour` variants like so ```rust Flavour::Latte.teal() ``` rather than needing to go through the `FlavourColours` struct This closes #27
This commit is contained in:
parent
468da426f5
commit
8f885d4339
3 changed files with 23 additions and 2 deletions
|
@ -13,7 +13,7 @@ impl Colour {
|
|||
/// ```
|
||||
/// use catppuccin::Flavour;
|
||||
///
|
||||
/// let hex = Flavour::Mocha.colours().teal.hex();
|
||||
/// let hex = Flavour::Mocha.teal().hex();
|
||||
/// assert_eq!(hex, "94E2D5");
|
||||
/// ```
|
||||
pub fn hex(&self) -> String {
|
||||
|
|
|
@ -8,6 +8,21 @@ pub enum Flavour {
|
|||
Mocha,
|
||||
}
|
||||
|
||||
macro_rules! impl_colour_method {
|
||||
($x:ident) => (
|
||||
pub fn $x(self) -> $crate::Colour {
|
||||
self.colours().$x
|
||||
}
|
||||
);
|
||||
($x:ident, $($y:ident),+ $(,)?) => (
|
||||
pub fn $x(self) -> $crate::Colour {
|
||||
self.colours().$x
|
||||
}
|
||||
|
||||
impl_colour_method!($($y),+);
|
||||
);
|
||||
}
|
||||
|
||||
impl Flavour {
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
|
@ -18,6 +33,12 @@ impl Flavour {
|
|||
}
|
||||
}
|
||||
|
||||
impl_colour_method!(
|
||||
rosewater, flamingo, pink, mauve, red, maroon, peach, yellow, green, teal, sky, sapphire,
|
||||
blue, lavender, text, subtext1, subtext0, overlay2, overlay1, overlay0, surface2, surface1,
|
||||
surface0, base, mantle, crust,
|
||||
);
|
||||
|
||||
pub fn colours(self) -> FlavourColours {
|
||||
match self {
|
||||
Self::Latte => FlavourColours {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
//! fn confirm(text: String) -> Button {
|
||||
//! Button {
|
||||
//! text,
|
||||
//! background_colour: Flavour::Mocha.colours().green.hex(),
|
||||
//! background_colour: Flavour::Mocha.green().hex(),
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
|
|
Loading…
Reference in a new issue