mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-31 10:56:41 +01:00
output: more big refactors
This commit is contained in:
parent
194f2f9874
commit
5e6338fad8
68 changed files with 1604 additions and 1016 deletions
|
|
@ -1,56 +1,128 @@
|
|||
use crate::*;
|
||||
#[allow(unused)] use crate::*;
|
||||
|
||||
macro_rules! impl_content_layout_render {
|
||||
($Output:ty: |$self:ident: $Struct:ty, $to:ident|
|
||||
layout = $layout:expr;
|
||||
render = $render:expr) =>
|
||||
{
|
||||
impl Render<$Output> for $Struct {
|
||||
fn layout (&$self, $to: [u16;4]) -> [u16;4] { $layout }
|
||||
fn render (&$self, $to: &mut $Output) { $render }
|
||||
impl Tui {
|
||||
pub const fn fg <T> (color: Color, w: T) -> TuiForeground<T> {
|
||||
TuiForeground(Foreground(color, w))
|
||||
}
|
||||
pub const fn bg <T> (color: Color, w: T) -> TuiBackground<T> {
|
||||
TuiBackground(Background(color, w))
|
||||
}
|
||||
pub const fn fg_bg <T> (fg: Color, bg: Color, w: T) -> TuiBackground<TuiForeground<T>> {
|
||||
TuiBackground(Background(bg, TuiForeground(Foreground(fg, w))))
|
||||
}
|
||||
pub const fn modify <T> (enable: bool, modifier: Modifier, w: T) -> Modify<T> {
|
||||
Modify(enable, modifier, w)
|
||||
}
|
||||
pub const fn bold <T> (enable: bool, w: T) -> Modify<T> {
|
||||
Self::modify(enable, Modifier::BOLD, w)
|
||||
}
|
||||
pub const fn border <S, T> (enable: bool, style: S, w: T) -> Bordered<S, T> {
|
||||
Bordered(enable, style, w)
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! tui_layout ((|$self:ident:$Self:ty, $to:ident|$expr:expr)=>{
|
||||
impl Layout<TuiOut> for $Self {
|
||||
fn layout (&$self, $to: [u16;4]) -> [u16;4] {
|
||||
$expr
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
#[macro_export] macro_rules! tui_draw ((|$self:ident:$Self:ty, $to:ident|$expr:expr)=>{
|
||||
impl Draw<TuiOut> for $Self {
|
||||
fn draw (&$self, $to: &mut TuiOut) {
|
||||
$expr
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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_error; pub use self::tui_error::*;
|
||||
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_scroll; pub use self::tui_scroll::*;
|
||||
mod tui_string; pub use self::tui_string::*;
|
||||
|
||||
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_error; pub use self::tui_error::*;
|
||||
mod tui_field; pub use self::tui_field::*;
|
||||
mod tui_number; //pub use self::tui_number::*;
|
||||
mod tui_phat; pub use self::tui_phat::*;
|
||||
mod tui_repeat; pub use self::tui_repeat::*;
|
||||
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::*;
|
||||
mod tui_tryptich; //pub use self::tui_tryptich::*;
|
||||
|
||||
impl<T: Render<TuiOut>> Render<TuiOut> for std::sync::Arc<T> {
|
||||
pub struct TuiForeground<T>(pub(crate) Foreground<Color, T>);
|
||||
pub struct TuiBackground<T>(pub(crate) Background<Color, T>);
|
||||
pub struct Modify<T>(pub bool, pub Modifier, pub T);
|
||||
pub struct Styled<T>(pub Option<Style>, pub T);
|
||||
|
||||
impl<T: Layout<TuiOut>> Layout<TuiOut> for TuiForeground<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
Render::<TuiOut>::layout(&**self, to)
|
||||
self.0.layout(to)
|
||||
}
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
Render::<TuiOut>::render(&**self, to)
|
||||
}
|
||||
impl<T: Layout<TuiOut> + Draw<TuiOut>> Draw<TuiOut> for TuiForeground<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let area = self.layout(to.area());
|
||||
to.fill_bg(area, self.0.0);
|
||||
to.place_at(area, &self.0.1);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Render<TuiOut>> Content<TuiOut> for Result<T, Box<dyn std::error::Error>> {
|
||||
fn content (&self) -> Option<impl Render<TuiOut> + '_> {
|
||||
Some(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: Layout<TuiOut>> Layout<TuiOut> for TuiBackground<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.0.layout(to)
|
||||
}
|
||||
}
|
||||
impl<T: Layout<TuiOut> + Draw<TuiOut>> Draw<TuiOut> for TuiBackground<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let area = self.layout(to.area());
|
||||
to.fill_bg(area, self.0.0);
|
||||
to.place_at(area, &self.0.1);
|
||||
}
|
||||
}
|
||||
|
||||
//impl<T: Render<TuiOut>> Render<TuiOut> for Result<T, Box<dyn std::error::Error>> {
|
||||
impl<T: Layout<TuiOut>> Layout<TuiOut> for Modify<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.2.layout(to)
|
||||
}
|
||||
}
|
||||
impl<T: Draw<TuiOut>> Draw<TuiOut> for Modify<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
to.fill_mod(to.area(), self.0, self.1);
|
||||
self.2.draw(to)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Layout<TuiOut>> Layout<TuiOut> for Styled<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.1.layout(to)
|
||||
}
|
||||
}
|
||||
impl<T: Layout<TuiOut> + Draw<TuiOut>> Draw<TuiOut> for Styled<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
to.place(&self.1);
|
||||
// TODO write style over area
|
||||
}
|
||||
}
|
||||
|
||||
//impl<T: Draw<TuiOut> + Layout<TuiOut>> Content<TuiOut> for Result<T, Box<dyn std::error::Error>> {
|
||||
//fn content (&self) -> impl Draw<TuiOut> + Layout<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: Draw<TuiOut>> Draw<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) {
|
||||
//fn draw (&self, to: &mut TuiOut) {
|
||||
//match self {
|
||||
//Ok(content) => content.render(to),
|
||||
//Ok(content) => content.draw(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))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue