mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: big flat pt.2: extract engine crate
This commit is contained in:
parent
4a3de618d0
commit
a5628fb663
31 changed files with 1738 additions and 888 deletions
96
src/style.rs
Normal file
96
src/style.rs
Normal 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.padding_xy(1, 1), Border(self.0) }.fill_xy()
|
||||
//}
|
||||
//}
|
||||
Loading…
Add table
Add a link
Reference in a new issue