mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
edn stub examples are now runnable
the Render/Content trait pair is very finicky
This commit is contained in:
parent
f1b3fc0040
commit
f6c603bf73
9 changed files with 69 additions and 56 deletions
30
src/style.rs
30
src/style.rs
|
|
@ -1,27 +1,27 @@
|
|||
use crate::*;
|
||||
|
||||
pub trait TuiStyle {
|
||||
fn fg <W: Content<Tui>> (color: Color, w: W) -> Foreground<W> {
|
||||
fn fg <R: Content<Tui>> (color: Color, w: R) -> Foreground<R> {
|
||||
Foreground(color, w)
|
||||
}
|
||||
fn bg <W: Content<Tui>> (color: Color, w: W) -> Background<W> {
|
||||
fn bg <R: Content<Tui>> (color: Color, w: R) -> Background<R> {
|
||||
Background(color, w)
|
||||
}
|
||||
fn fg_bg <W: Content<Tui>> (fg: Color, bg: Color, w: W) -> Background<Foreground<W>> {
|
||||
fn fg_bg <R: Content<Tui>> (fg: Color, bg: Color, w: R) -> Background<Foreground<R>> {
|
||||
Background(bg, Foreground(fg, w))
|
||||
}
|
||||
fn bold <W: Content<Tui>> (on: bool, w: W) -> Bold<W> {
|
||||
fn bold <R: Content<Tui>> (on: bool, w: R) -> Bold<R> {
|
||||
Bold(on, w)
|
||||
}
|
||||
fn border <W: Content<Tui>, S: BorderStyle> (style: S, w: W) -> Bordered<S, W> {
|
||||
fn border <R: Content<Tui>, S: BorderStyle> (style: S, w: R) -> Bordered<S, R> {
|
||||
Bordered(style, w)
|
||||
}
|
||||
}
|
||||
|
||||
impl TuiStyle for Tui {}
|
||||
|
||||
pub struct Bold<W: Content<Tui>>(pub bool, W);
|
||||
impl<W: Content<Tui>> Content<Tui> for Bold<W> {
|
||||
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 }
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
to.fill_bold(to.area(), self.0);
|
||||
|
|
@ -29,8 +29,8 @@ impl<W: Content<Tui>> Content<Tui> for Bold<W> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Foreground<W: Content<Tui>>(pub Color, W);
|
||||
impl<W: Content<Tui>> Content<Tui> for Foreground<W> {
|
||||
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 }
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
to.fill_fg(to.area(), self.0);
|
||||
|
|
@ -38,8 +38,8 @@ impl<W: Content<Tui>> Content<Tui> for Foreground<W> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Background<W: Content<Tui>>(pub Color, W);
|
||||
impl<W: Content<Tui>> Content<Tui> for Background<W> {
|
||||
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 }
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
to.fill_bg(to.area(), self.0);
|
||||
|
|
@ -47,7 +47,7 @@ impl<W: Content<Tui>> Content<Tui> for Background<W> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Styled<T: Content<Tui>>(pub Option<Style>, pub T);
|
||||
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 }
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
|
|
@ -58,7 +58,7 @@ impl Content<Tui> for Styled<&str> {
|
|||
}
|
||||
}
|
||||
|
||||
//pub trait TuiStyle: Content<Tui> + Sized {
|
||||
//pub trait TuiStyle: Render<Tui> + Sized {
|
||||
//fn fg (self, color: Color) -> impl Render<Tui> {
|
||||
//Layers::new(move |add|{ add(&Foreground(color))?; add(&self) })
|
||||
//}
|
||||
|
|
@ -73,12 +73,12 @@ impl Content<Tui> for Styled<&str> {
|
|||
//}
|
||||
//}
|
||||
|
||||
//impl<W: Content<Tui>> TuiStyle for W {}
|
||||
//impl<R: Content<Tui>> TuiStyle for R {}
|
||||
|
||||
//impl<S: BorderStyle> Content<Tui> for Border<S> {
|
||||
//}
|
||||
|
||||
//impl<S: BorderStyle, W: Content<Tui>> Content<Tui> for Bordered<S, W> {
|
||||
//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;
|
||||
//lay! { content.padding_xy(1, 1), Border(self.0) }.fill_xy()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue