tengri/tui/src/tui_content.rs

58 lines
2 KiB
Rust

use crate::*;
macro_rules! impl_content_layout_render {
($Output:ty: |$self:ident: $Struct:ty, $to:ident|
layout = $layout:expr;
render = $render:expr) =>
{
impl Content<$Output> for $Struct {
fn layout (&$self, $to: [u16;4]) -> [u16;4] { $layout }
fn render (&$self, $to: &mut $Output) { $render }
}
}
}
mod tui_border; pub use self::tui_border::*;
mod tui_button; //pub use self::tui_button::*;
mod tui_color; pub use self::tui_color::*;
mod tui_field; pub use self::tui_field::*;
mod tui_phat; pub use self::tui_phat::*;
mod tui_repeat; pub use self::tui_repeat::*;
mod tui_number; //pub use self::tui_number::*;
mod tui_scroll; pub use self::tui_scroll::*;
mod tui_string; pub use self::tui_string::*;
mod tui_style; pub use self::tui_style::*;
mod tui_tryptich; pub use self::tui_tryptich::*;
impl<T: Content<TuiOut>> Content<TuiOut> for std::sync::Arc<T> {
fn layout (&self, to: [u16;4]) -> [u16;4] {
Content::<TuiOut>::layout(&**self, to)
}
fn render (&self, to: &mut TuiOut) {
Content::<TuiOut>::render(&**self, to)
}
}
impl<T: Content<TuiOut>> Content<TuiOut> for Result<T, Box<dyn std::error::Error>> {
fn content (&self) -> impl Render<TuiOut> {
Bsp::a(self.as_ref().ok(), self.as_ref().err()
.map(|e|Tui::fg_bg(Color::Rgb(255,255,255), Color::Rgb(32,32,32), e.to_string())))
}
}
//impl<T: Render<TuiOut>> Render<TuiOut> for Result<T, Box<dyn std::error::Error>> {
//fn layout (&self, to: [u16;4]) -> [u16;4] {
//match self {
//Ok(content) => content.layout(to),
//Err(e) => [0, 0, to.w(), to.h()]
//}
//}
//fn render (&self, to: &mut TuiOut) {
//match self {
//Ok(content) => content.render(to),
//Err(e) => to.blit(&e.to_string(), 0, 0, Some(Style::default()
//.bg(Color::Rgb(32,32,32))
//.fg(Color::Rgb(255,255,255))))
//}
//}
//}