mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 12:16:44 +01:00
refactor: extract more tui_content modules
This commit is contained in:
parent
86236b76cd
commit
ea01deb854
6 changed files with 192 additions and 183 deletions
60
tui/src/tui_content/tui_style.rs
Normal file
60
tui/src/tui_content/tui_style.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue