flatten workspace into 1 crate

This commit is contained in:
🪞👃🪞 2024-12-29 00:10:30 +01:00
parent 7c4e1e2166
commit d926422c67
147 changed files with 66 additions and 126 deletions

96
src/tui/tui_style.rs Normal file
View file

@ -0,0 +1,96 @@
use crate::*;
impl Tui {
pub(crate) fn fg <W: Render<Tui>> (color: Color, w: W) -> Foreground<W> {
Foreground(color, w)
}
pub(crate) fn bg <W: Render<Tui>> (color: Color, w: W) -> Background<W> {
Background(color, w)
}
pub(crate) fn fg_bg <W: Render<Tui>> (fg: Color, bg: Color, w: W) -> Background<Foreground<W>> {
Background(bg, Foreground(fg, w))
}
pub(crate) fn bold <W: Render<Tui>> (on: bool, w: W) -> Bold<W> {
Bold(on, w)
}
pub(crate) fn border <W: Render<Tui>, S: BorderStyle> (style: S, w: W) -> Bordered<S, W> {
Bordered(style, w)
}
}
pub struct Bold<W: Render<Tui>>(pub bool, W);
impl<W: Render<Tui>> Render<Tui> for Bold<W> {
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
self.1.min_size(to)
}
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
to.fill_bold(to.area(), self.0);
self.1.render(to)
}
}
pub struct Foreground<W: Render<Tui>>(pub Color, W);
impl<W: Render<Tui>> Render<Tui> for Foreground<W> {
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
self.1.min_size(to)
}
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
to.fill_fg(to.area(), self.0);
self.1.render(to)
}
}
pub struct Background<W: Render<Tui>>(pub Color, W);
impl<W: Render<Tui>> Render<Tui> for Background<W> {
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
self.1.min_size(to)
}
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
to.fill_bg(to.area(), self.0);
self.1.render(to)
}
}
pub struct Styled<T: Render<Tui>>(pub Option<Style>, pub T);
impl Render<Tui> for Styled<&str> {
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
Ok(Some([self.1.chars().count() as u16, 1]))
}
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
// FIXME
let [x, y, ..] = to.area();
//let [w, h] = self.min_size(to.area().wh())?.unwrap();
Ok(to.blit(&self.1, x, y, None))
}
}
//pub trait TuiStyle: Render<Tui> + Sized {
//fn fg (self, color: Color) -> impl Render<Tui> {
//Layers::new(move |add|{ add(&Foreground(color))?; add(&self) })
//}
//fn bg (self, color: Color) -> impl Render<Tui> {
//Layers::new(move |add|{ add(&Background(color))?; add(&self) })
//}
//fn bold (self, on: bool) -> impl Render<Tui> {
//Layers::new(move |add|{ add(&Bold(on))?; add(&self) })
//}
//fn border <S: BorderStyle> (self, style: S) -> impl Render<Tui> {
//Bordered(style, self)
//}
//}
//impl<W: Render<Tui>> TuiStyle for W {}
//impl<S: BorderStyle> Render<Tui> for Border<S> {
//}
//impl<S: BorderStyle, W: Render<Tui>> Content<Tui> for Bordered<S, W> {
//fn content (&self) -> impl Render<Tui> {
//let content: &dyn Render<Tui> = &self.1;
//lay! { content.inset_xy(1, 1), Border(self.0) }.fill_xy()
//}
//}