use crate::{Error, Rgb};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PaletteKind {
Static,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PaletteSpec {
family: &'static str,
variant: &'static str,
}
impl PaletteSpec {
#[must_use]
pub const fn new(family: &'static str, variant: &'static str) -> Self {
Self { family, variant }
}
#[must_use]
pub const fn family(self) -> &'static str {
self.family
}
#[must_use]
pub const fn variant(self) -> &'static str {
self.variant
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Palette {
family: &'static str,
variant: &'static str,
kind: PaletteKind,
colors: &'static [Rgb],
}
impl Palette {
#[must_use]
pub const fn new(
family: &'static str,
variant: &'static str,
kind: PaletteKind,
colors: &'static [Rgb],
) -> Self {
Self {
family,
variant,
kind,
colors,
}
}
#[must_use]
pub const fn family(&self) -> &'static str {
self.family
}
#[must_use]
pub const fn variant(&self) -> &'static str {
self.variant
}
#[must_use]
pub const fn kind(&self) -> PaletteKind {
self.kind
}
#[must_use]
pub const fn spec(&self) -> PaletteSpec {
PaletteSpec::new(self.family, self.variant)
}
#[must_use]
pub const fn colors(&self) -> &'static [Rgb] {
self.colors
}
#[must_use]
pub const fn len(&self) -> usize {
self.colors.len()
}
#[must_use]
pub const fn is_empty(&self) -> bool {
self.colors.is_empty()
}
pub fn take(&self, n: usize) -> Result<Vec<Rgb>, Error> {
if n > self.colors.len() {
return Err(Error::TooManyColorsRequested {
family: self.family,
variant: self.variant,
requested: n,
available: self.colors.len(),
});
}
Ok(self.colors[..n].to_vec())
}
pub fn take_hex(&self, n: usize) -> Result<Vec<String>, Error> {
self.take(n)
.map(|colors| colors.into_iter().map(Rgb::to_hex_string).collect())
}
pub fn cycle(&self) -> impl Iterator<Item = Rgb> + '_ {
self.colors.iter().copied().cycle()
}
}