mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +01:00
separate Input and Output impls
This commit is contained in:
parent
a6efde40f8
commit
0e821e098f
77 changed files with 465 additions and 454 deletions
|
|
@ -1,86 +1,84 @@
|
|||
use crate::*;
|
||||
|
||||
pub trait TuiStyle {
|
||||
fn fg <R: Content<Tui>> (color: Color, w: R) -> Foreground<R> {
|
||||
fn fg <R: Content<TuiOut>> (color: Color, w: R) -> Foreground<R> {
|
||||
Foreground(color, w)
|
||||
}
|
||||
fn bg <R: Content<Tui>> (color: Color, w: R) -> Background<R> {
|
||||
fn bg <R: Content<TuiOut>> (color: Color, w: R) -> Background<R> {
|
||||
Background(color, w)
|
||||
}
|
||||
fn fg_bg <R: Content<Tui>> (fg: Color, bg: Color, w: R) -> Background<Foreground<R>> {
|
||||
fn fg_bg <R: Content<TuiOut>> (fg: Color, bg: Color, w: R) -> Background<Foreground<R>> {
|
||||
Background(bg, Foreground(fg, w))
|
||||
}
|
||||
fn bold <R: Content<Tui>> (on: bool, w: R) -> Bold<R> {
|
||||
fn bold <R: Content<TuiOut>> (on: bool, w: R) -> Bold<R> {
|
||||
Bold(on, w)
|
||||
}
|
||||
fn border <R: Content<Tui>, S: BorderStyle> (style: S, w: R) -> Bordered<S, R> {
|
||||
fn border <R: Content<TuiOut>, S: BorderStyle> (style: S, w: R) -> Bordered<S, R> {
|
||||
Bordered(style, w)
|
||||
}
|
||||
}
|
||||
|
||||
impl TuiStyle for Tui {}
|
||||
|
||||
pub struct Bold<R: Content<Tui>>(pub bool, R);
|
||||
impl<R: Content<Tui>> Content<Tui> for Bold<R> {
|
||||
fn content (&self) -> impl Render<Tui> { &self.1 }
|
||||
pub struct Bold<R: Content<TuiOut>>(pub bool, R);
|
||||
impl<R: Content<TuiOut>> Content<TuiOut> for Bold<R> {
|
||||
fn content (&self) -> impl Render<TuiOut> { &self.1 }
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
to.fill_bold(to.area(), self.0);
|
||||
self.1.render(to)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Foreground<R: Content<Tui>>(pub Color, R);
|
||||
impl<R: Content<Tui>> Content<Tui> for Foreground<R> {
|
||||
fn content (&self) -> impl Render<Tui> { &self.1 }
|
||||
pub struct Foreground<R: Content<TuiOut>>(pub Color, R);
|
||||
impl<R: Content<TuiOut>> Content<TuiOut> for Foreground<R> {
|
||||
fn content (&self) -> impl Render<TuiOut> { &self.1 }
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
to.fill_fg(to.area(), self.0);
|
||||
self.1.render(to)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Background<R: Content<Tui>>(pub Color, R);
|
||||
impl<R: Content<Tui>> Content<Tui> for Background<R> {
|
||||
fn content (&self) -> impl Render<Tui> { &self.1 }
|
||||
pub struct Background<R: Content<TuiOut>>(pub Color, R);
|
||||
impl<R: Content<TuiOut>> Content<TuiOut> for Background<R> {
|
||||
fn content (&self) -> impl Render<TuiOut> { &self.1 }
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
to.fill_bg(to.area(), self.0);
|
||||
self.1.render(to)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Styled<R: Content<Tui>>(pub Option<Style>, pub R);
|
||||
impl Content<Tui> for Styled<&str> {
|
||||
fn content (&self) -> impl Render<Tui> { &self.1 }
|
||||
pub struct Styled<R: Content<TuiOut>>(pub Option<Style>, pub R);
|
||||
impl<R: Content<TuiOut>> Content<TuiOut> for Styled<R> {
|
||||
fn content (&self) -> impl Render<TuiOut> { &self.1 }
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
// FIXME
|
||||
let [x, y, ..] = to.area();
|
||||
//let [w, h] = self.min_size(to.area().wh())?.unwrap();
|
||||
to.blit(&self.1, x, y, None)
|
||||
to.place(self.content().layout(to.area()), &self.content());
|
||||
// TODO write style over area
|
||||
}
|
||||
}
|
||||
|
||||
//pub trait TuiStyle: Render<Tui> + Sized {
|
||||
//fn fg (self, color: Color) -> impl Render<Tui> {
|
||||
//pub trait TuiStyle: Render<TuiOut> + Sized {
|
||||
//fn fg (self, color: Color) -> impl Render<TuiOut> {
|
||||
//Layers::new(move |add|{ add(&Foreground(color))?; add(&self) })
|
||||
//}
|
||||
//fn bg (self, color: Color) -> impl Render<Tui> {
|
||||
//fn bg (self, color: Color) -> impl Render<TuiOut> {
|
||||
//Layers::new(move |add|{ add(&Background(color))?; add(&self) })
|
||||
//}
|
||||
//fn bold (self, on: bool) -> impl Render<Tui> {
|
||||
//fn bold (self, on: bool) -> impl Render<TuiOut> {
|
||||
//Layers::new(move |add|{ add(&Bold(on))?; add(&self) })
|
||||
//}
|
||||
//fn border <S: BorderStyle> (self, style: S) -> impl Render<Tui> {
|
||||
//fn border <S: BorderStyle> (self, style: S) -> impl Render<TuiOut> {
|
||||
//Bordered(style, self)
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl<R: Content<Tui>> TuiStyle for R {}
|
||||
//impl<R: Content<TuiOut>> TuiStyle for R {}
|
||||
|
||||
//impl<S: BorderStyle> Content<Tui> for Border<S> {
|
||||
//impl<S: BorderStyle> Content<TuiOut> for Border<S> {
|
||||
//}
|
||||
|
||||
//impl<S: BorderStyle, R: Content<Tui>> Content<Tui> for Bordered<S, R> {
|
||||
//fn content (&self) -> impl Render<Tui> {
|
||||
//let content: &dyn Content<Tui> = &self.1;
|
||||
//impl<S: BorderStyle, R: Content<TuiOut>> Content<TuiOut> for Bordered<S, R> {
|
||||
//fn content (&self) -> impl Render<TuiOut> {
|
||||
//let content: &dyn Content<TuiOut> = &self.1;
|
||||
//lay! { content.padding_xy(1, 1), Border(self.0) }.fill_xy()
|
||||
//}
|
||||
//}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue