mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 18:49:04 +01:00
This commit is contained in:
parent
f3fcf663a8
commit
501782f8fe
18 changed files with 841 additions and 908 deletions
|
|
@ -1,5 +1,13 @@
|
|||
#![feature(type_changing_struct_update, trait_alias)]
|
||||
pub use ::{tengri_input, tengri_output, ratatui, crossterm, palette, better_panic};
|
||||
pub use ::{
|
||||
dizzle,
|
||||
tengri_input,
|
||||
tengri_output,
|
||||
ratatui,
|
||||
crossterm,
|
||||
palette,
|
||||
better_panic,
|
||||
};
|
||||
pub(crate) use ::{
|
||||
dizzle::*,
|
||||
tengri_input::*,
|
||||
|
|
@ -23,13 +31,23 @@ pub(crate) use ::{
|
|||
};
|
||||
mod tui_engine; pub use self::tui_engine::*;
|
||||
mod tui_content; pub use self::tui_content::*;
|
||||
#[macro_export] macro_rules! tui_main {
|
||||
($expr:expr) => {
|
||||
fn main () -> Usually<()> {
|
||||
let state = Arc::new(RwLock::new($expr));
|
||||
tengri_tui::Tui::new().unwrap().run(&state)?;
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)] mod tui_test {
|
||||
use crate::*;
|
||||
#[test] fn test_tui_engine () -> Usually<()> {
|
||||
//use std::sync::{Arc, RwLock};
|
||||
struct TestComponent(String);
|
||||
impl Content<TuiOut> for TestComponent {
|
||||
fn content (&self) -> impl Draw<TuiOut> {
|
||||
impl HasContent<TuiOut> for TestComponent {
|
||||
fn content (&self) -> impl Content<TuiOut> {
|
||||
Some(self.0.as_str())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,16 +40,12 @@ pub trait HasColor { fn color (&self) -> ItemColor; }
|
|||
pub okhsl: Okhsl<f32>,
|
||||
pub rgb: Color,
|
||||
}
|
||||
|
||||
from!(|okhsl: Okhsl<f32>|ItemColor = Self { okhsl, rgb: okhsl_to_rgb(okhsl) });
|
||||
|
||||
from!(ItemColor: |okhsl: Okhsl<f32>|Self { okhsl, rgb: okhsl_to_rgb(okhsl) });
|
||||
from!(ItemColor: |rgb: Color|Self { rgb, okhsl: rgb_to_okhsl(rgb) });
|
||||
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,)
|
||||
}
|
||||
|
||||
from!(|rgb: Color|ItemColor = Self { rgb, okhsl: rgb_to_okhsl(rgb) });
|
||||
|
||||
pub fn rgb_to_okhsl (color: Color) -> Okhsl<f32> {
|
||||
if let Color::Rgb(r, g, b) = color {
|
||||
Okhsl::from_color(Srgb::new(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0))
|
||||
|
|
@ -98,6 +94,8 @@ impl ItemColor {
|
|||
pub darkest: ItemColor,
|
||||
}
|
||||
|
||||
from!(ItemTheme: |base: Color| Self::from_tui_color(base));
|
||||
from!(ItemTheme: |base: ItemColor|Self::from_item_color(base));
|
||||
impl ItemTheme {
|
||||
pub const G: [Self;256] = {
|
||||
let mut builder = konst::array::ArrayBuilder::new();
|
||||
|
|
@ -170,6 +168,3 @@ impl ItemTheme {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
from!(|base: Color| ItemTheme = Self::from_tui_color(base));
|
||||
from!(|base: ItemColor|ItemTheme = Self::from_item_color(base));
|
||||
|
|
|
|||
|
|
@ -41,4 +41,4 @@ impl BigBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
from!(|size:(usize, usize)| BigBuffer = Self::new(size.0, size.1));
|
||||
from!(BigBuffer: |size:(usize, usize)| Self::new(size.0, size.1));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue