mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 04:06:48 +01:00
60 lines
2 KiB
Rust
60 lines
2 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 modify <R: Content<TuiOut>> (enable: bool, modifier: Modifier, w: R) -> Modify<R> {
|
|
Modify(enable, modifier, w)
|
|
}
|
|
fn bold <R: Content<TuiOut>> (enable: bool, w: R) -> Modify<R> {
|
|
Self::modify(enable, Modifier::BOLD, w)
|
|
}
|
|
fn border <R: Content<TuiOut>, S: BorderStyle> (enable: bool, style: S, w: R) -> Bordered<S, R> {
|
|
Bordered(enable, style, w)
|
|
}
|
|
}
|
|
|
|
impl TuiStyle for Tui {}
|
|
|
|
pub struct Foreground<R: Content<TuiOut>>(pub Color, pub 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, pub 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 Modify<R: Content<TuiOut>>(pub bool, pub Modifier, pub R);
|
|
impl<R: Content<TuiOut>> Content<TuiOut> for Modify<R> {
|
|
fn content (&self) -> impl Render<TuiOut> { &self.2 }
|
|
fn render (&self, to: &mut TuiOut) {
|
|
to.fill_mod(to.area(), self.0, self.1);
|
|
self.2.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
|
|
}
|
|
}
|