mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
impl TuiTheme on Tui; need to to reduce number of ItemPalette invocations
This commit is contained in:
parent
9d250daa04
commit
cfa3cad5cb
9 changed files with 157 additions and 177 deletions
|
|
@ -1,5 +1,30 @@
|
|||
use crate::*;
|
||||
use rand::{thread_rng, distributions::uniform::UniformSampler};
|
||||
impl Theme for Tui {}
|
||||
pub trait Theme {
|
||||
const HOTKEY_FG: Color = Color::Rgb(255, 255, 0);
|
||||
fn null () -> Color { Color::Reset }
|
||||
fn g (g: u8) -> Color { Color::Rgb(g, g, g) }
|
||||
//fn bg0 () -> Color { Color::Rgb(20, 20, 20) }
|
||||
//fn bg () -> Color { Color::Rgb(28, 35, 25) }
|
||||
//fn border_bg () -> Color { Color::Rgb(40, 50, 30) }
|
||||
//fn border_fg (f: bool) -> Color { if f { Self::bo1() } else { Self::bo2() } }
|
||||
//fn title_fg (f: bool) -> Color { if f { Self::ti1() } else { Self::ti2() } }
|
||||
//fn separator_fg (_: bool) -> Color { Color::Rgb(0, 0, 0) }
|
||||
//fn mode_bg () -> Color { Color::Rgb(150, 160, 90) }
|
||||
//fn mode_fg () -> Color { Color::Rgb(255, 255, 255) }
|
||||
//fn status_bar_bg () -> Color { Color::Rgb(28, 35, 25) }
|
||||
//fn bo1 () -> Color { Color::Rgb(100, 110, 40) }
|
||||
//fn bo2 () -> Color { Color::Rgb(70, 80, 50) }
|
||||
//fn ti1 () -> Color { Color::Rgb(150, 160, 90) }
|
||||
//fn ti2 () -> Color { Color::Rgb(120, 130, 100) }
|
||||
fn red () -> Color { Color::Rgb(255,0, 0) }
|
||||
fn orange () -> Color { Color::Rgb(255,128,0) }
|
||||
fn yellow () -> Color { Color::Rgb(255,255,0) }
|
||||
fn brown () -> Color { Color::Rgb(128,255,0) }
|
||||
fn green () -> Color { Color::Rgb(0, 255,0) }
|
||||
fn electric () -> Color { Color::Rgb(0, 255,128) }
|
||||
}
|
||||
pub trait HasColor { fn color (&self) -> ItemColor; }
|
||||
#[macro_export] macro_rules! has_color {
|
||||
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
|
||||
|
|
@ -13,16 +38,6 @@ pub trait HasColor { fn color (&self) -> ItemColor; }
|
|||
pub okhsl: Okhsl<f32>,
|
||||
pub rgb: Color,
|
||||
}
|
||||
/// A color in OKHSL and RGB with lighter and darker variants.
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct ItemPalette {
|
||||
pub base: ItemColor,
|
||||
pub light: ItemColor,
|
||||
pub lighter: ItemColor,
|
||||
pub lightest: ItemColor,
|
||||
pub dark: ItemColor,
|
||||
pub darker: ItemColor,
|
||||
pub darkest: ItemColor,
|
||||
}
|
||||
from!(|okhsl: Okhsl<f32>|ItemColor = Self { okhsl, rgb: okhsl_to_rgb(okhsl) });
|
||||
from!(|rgb: Color|ItemColor = Self { rgb, okhsl: rgb_to_okhsl(rgb) });
|
||||
// A single color within item theme parameters, in OKHSL and RGB representations.
|
||||
|
|
@ -47,6 +62,37 @@ impl ItemColor {
|
|||
self.okhsl.mix(other.okhsl, distance).into()
|
||||
}
|
||||
}
|
||||
/// A color in OKHSL and RGB with lighter and darker variants.
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct ItemPalette {
|
||||
pub base: ItemColor,
|
||||
pub light: ItemColor,
|
||||
pub lighter: ItemColor,
|
||||
pub lightest: ItemColor,
|
||||
pub dark: ItemColor,
|
||||
pub darker: ItemColor,
|
||||
pub darkest: ItemColor,
|
||||
}
|
||||
impl ItemPalette {
|
||||
pub fn random () -> Self { ItemColor::random().into() }
|
||||
pub fn random_near (color: Self, distance: f32) -> Self {
|
||||
color.base.mix(ItemColor::random(), distance).into()
|
||||
}
|
||||
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)
|
||||
};
|
||||
Self {
|
||||
base: color,
|
||||
light: color,
|
||||
lighter: color,
|
||||
lightest: color,
|
||||
dark: color,
|
||||
darker: color,
|
||||
darkest: color,
|
||||
}
|
||||
};
|
||||
}
|
||||
from!(|base: Color|ItemPalette = Self::from(ItemColor::from(base)));
|
||||
from!(|base: ItemColor|ItemPalette = {
|
||||
let mut light = base.okhsl;
|
||||
|
|
@ -74,12 +120,6 @@ from!(|base: ItemColor|ItemPalette = {
|
|||
darkest: darkest.into(),
|
||||
}
|
||||
});
|
||||
impl ItemPalette {
|
||||
pub fn random () -> Self { ItemColor::random().into() }
|
||||
pub fn random_near (color: Self, distance: f32) -> Self {
|
||||
color.base.mix(ItemColor::random(), distance).into()
|
||||
}
|
||||
}
|
||||
pub fn okhsl_to_rgb (color: Okhsl<f32>) -> Color {
|
||||
let Srgb { red, green, blue, .. }: Srgb<f32> = Srgb::from_color_unclamped(color);
|
||||
Color::Rgb((red * 255.0) as u8, (green * 255.0) as u8, (blue * 255.0) as u8,)
|
||||
|
|
|
|||
|
|
@ -64,66 +64,6 @@ impl<T, U> Content<TuiOut> for FieldV<T, U>
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy,Clone)]
|
||||
pub struct TuiTheme;
|
||||
|
||||
impl Theme for TuiTheme {}
|
||||
|
||||
pub trait Theme {
|
||||
const HOTKEY_FG: Color = Color::Rgb(255, 255, 0);
|
||||
fn null () -> Color {
|
||||
Color::Reset
|
||||
}
|
||||
fn bg0 () -> Color {
|
||||
Color::Rgb(20, 20, 20)
|
||||
}
|
||||
fn bg () -> Color {
|
||||
Color::Rgb(28, 35, 25)
|
||||
}
|
||||
fn border_bg () -> Color {
|
||||
Color::Rgb(40, 50, 30)
|
||||
}
|
||||
fn border_fg (focused: bool) -> Color {
|
||||
if focused { Self::bo1() } else { Self::bo2() }
|
||||
}
|
||||
fn title_fg (focused: bool) -> Color {
|
||||
if focused { Self::ti1() } else { Self::ti2() }
|
||||
}
|
||||
fn separator_fg (_: bool) -> Color {
|
||||
Color::Rgb(0, 0, 0)
|
||||
}
|
||||
fn mode_bg () -> Color {
|
||||
Color::Rgb(150, 160, 90)
|
||||
}
|
||||
fn mode_fg () -> Color {
|
||||
Color::Rgb(255, 255, 255)
|
||||
}
|
||||
fn status_bar_bg () -> Color {
|
||||
Color::Rgb(28, 35, 25)
|
||||
}
|
||||
fn bo1 () -> Color {
|
||||
Color::Rgb(100, 110, 40)
|
||||
}
|
||||
fn bo2 () -> Color {
|
||||
Color::Rgb(70, 80, 50)
|
||||
}
|
||||
fn ti1 () -> Color {
|
||||
Color::Rgb(150, 160, 90)
|
||||
}
|
||||
fn ti2 () -> Color {
|
||||
Color::Rgb(120, 130, 100)
|
||||
}
|
||||
fn orange () -> Color {
|
||||
Color::Rgb(255,128,0)
|
||||
}
|
||||
fn yellow () -> Color {
|
||||
Color::Rgb(255,255,0)
|
||||
}
|
||||
fn g (g: u8) -> Color {
|
||||
Color::Rgb(g, g, g)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Repeat<'a>(pub &'a str);
|
||||
|
||||
impl Content<TuiOut> for Repeat<'_> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue