0.5.0: Tui::modify, Bold -> Modify

This commit is contained in:
🪞👃🪞 2025-04-04 00:33:16 +03:00
parent a42e17a9d4
commit b43cd0f64f
4 changed files with 38 additions and 35 deletions

View file

@ -152,8 +152,11 @@ pub trait TuiStyle {
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>> (enable: bool, w: R) -> Bold<R> {
Bold(enable, 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)
@ -162,16 +165,7 @@ pub trait TuiStyle {
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);
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) {
@ -180,7 +174,7 @@ impl<R: Content<TuiOut>> Content<TuiOut> for Foreground<R> {
}
}
pub struct Background<R: Content<TuiOut>>(pub Color, R);
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) {
@ -189,6 +183,15 @@ impl<R: Content<TuiOut>> Content<TuiOut> for Background<R> {
}
}
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 }

View file

@ -111,8 +111,8 @@ impl TuiOut {
}
pub fn tint_all (&mut self, fg: Color, bg: Color, modifier: Modifier) {
for cell in self.buffer.content.iter_mut() {
cell.bg = bg;
cell.fg = fg;
cell.bg = bg;
cell.modifier = modifier;
}
}