This commit is contained in:
same mf who else 2026-03-21 17:35:31 +02:00
parent 5d627f7669
commit eb899906f9
8 changed files with 627 additions and 728 deletions

View file

@ -1,6 +1,10 @@
use ::ratatui::style::Color;
use crate::lang::impl_from;
pub(crate) use ::palette::{Okhsl, Srgb, OklabHue, okhsl::UniformOkhsl};
pub(crate) use ::palette::{
Okhsl, Srgb, OklabHue, Mix, okhsl::UniformOkhsl,
convert::{FromColor, FromColorUnclamped}
};
use rand::distributions::uniform::UniformSampler;
pub fn rgb (r: u8, g: u8, b: u8) -> ItemColor { todo!(); }
@ -26,13 +30,17 @@ pub trait HasColor { fn color (&self) -> ItemColor; }
}
}
pub struct ItemColor {}
impl_from!(ItemColor: |rgb: Color| Self { rgb, okhsl: rgb_to_okhsl(rgb) });
impl_from!(ItemColor: |okhsl: Okhsl<f32>| Self { okhsl, rgb: okhsl_to_rgb(okhsl) });
#[derive(Copy, Clone, Debug, Default)]
pub struct ItemColor {
term: Color,
okhsl: Okhsl<f32>
}
impl_from!(ItemColor: |term: Color| Self { term, okhsl: rgb_to_okhsl(term) });
impl_from!(ItemColor: |okhsl: Okhsl<f32>| Self { okhsl, term: okhsl_to_rgb(okhsl) });
// A single color within item theme parameters, in OKHSL and RGB representations.
impl ItemColor {
#[cfg(feature = "tui")] pub const fn from_tui (rgb: Color) -> Self {
Self { rgb, okhsl: Okhsl::new_const(OklabHue::new(0.0), 0.0, 0.0) }
#[cfg(feature = "term")] pub const fn from_tui (term: Color) -> Self {
Self { term, okhsl: Okhsl::new_const(OklabHue::new(0.0), 0.0, 0.0) }
}
pub fn random () -> Self {
let mut rng = ::rand::thread_rng();
@ -67,8 +75,8 @@ pub struct ItemTheme {
impl_from!(ItemTheme: |base: ItemColor| Self::from_item_color(base));
impl_from!(ItemTheme: |base: Color| Self::from_tui_color(base));
impl ItemTheme {
#[cfg(feature = "tui")] pub const G: [Self;256] = {
let mut builder = konst::array::ArrayBuilder::new();
#[cfg(feature = "term")] pub const G: [Self;256] = {
let mut builder = dizzle::konst::array::ArrayBuilder::new();
while !builder.is_full() {
let index = builder.len() as u8;
let light = (index as f64 * 1.15) as u8;
@ -96,7 +104,7 @@ impl ItemTheme {
pub const G00: Self = {
let color: ItemColor = ItemColor {
okhsl: Okhsl { hue: OklabHue::new(0.0), lightness: 0.0, saturation: 0.0 },
rgb: Color::Rgb(0, 0, 0)
term: Color::Rgb(0, 0, 0)
};
Self {
base: color,
@ -108,7 +116,7 @@ impl ItemTheme {
darkest: color,
}
};
#[cfg(feature = "tui")] pub fn from_tui_color (base: Color) -> Self {
#[cfg(feature = "term")] pub fn from_tui_color (base: Color) -> Self {
Self::from_item_color(ItemColor::from_tui(base))
}
pub fn from_item_color (base: ItemColor) -> Self {