mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
84 lines
2.7 KiB
Rust
84 lines
2.7 KiB
Rust
use crate::*;
|
|
|
|
pub trait TuiStyle {
|
|
fn fg <R: Content<TuiOut>> (color: Color, w: R) -> Foreground<R> {
|
|
Foreground(color, w)
|
|
}
|
|
fn bg <R: Content<TuiOut>> (color: Color, w: R) -> Background<R> {
|
|
Background(color, w)
|
|
}
|
|
fn fg_bg <R: Content<TuiOut>> (fg: Color, bg: Color, w: R) -> Background<Foreground<R>> {
|
|
Background(bg, Foreground(fg, w))
|
|
}
|
|
fn bold <R: Content<TuiOut>> (on: bool, w: R) -> Bold<R> {
|
|
Bold(on, w)
|
|
}
|
|
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<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<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<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<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) {
|
|
to.place(self.content().layout(to.area()), &self.content());
|
|
// TODO write style over area
|
|
}
|
|
}
|
|
|
|
//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<TuiOut> {
|
|
//Layers::new(move |add|{ add(&Background(color))?; add(&self) })
|
|
//}
|
|
//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<TuiOut> {
|
|
//Bordered(style, self)
|
|
//}
|
|
//}
|
|
|
|
//impl<R: Content<TuiOut>> TuiStyle for R {}
|
|
|
|
//impl<S: BorderStyle> Content<TuiOut> for Border<S> {
|
|
//}
|
|
|
|
//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()
|
|
//}
|
|
//}
|