implement bold modifier

This commit is contained in:
🪞👃🪞 2024-10-19 00:07:17 +03:00
parent 794460b2e4
commit 581b0f5f3b
2 changed files with 23 additions and 1 deletions

View file

@ -258,6 +258,13 @@ impl TuiOutput {
) {
buffer_update(&mut self.buffer, area, callback);
}
pub fn fill_bold (&mut self, area: [u16;4], on: bool) {
if on {
self.buffer_update(area, &|cell,_,_|cell.modifier.insert(Modifier::BOLD))
} else {
self.buffer_update(area, &|cell,_,_|cell.modifier.remove(Modifier::BOLD))
}
}
pub fn fill_bg (&mut self, area: [u16;4], color: Color) {
self.buffer_update(area, &|cell,_,_|{cell.set_bg(color);})
}
@ -428,12 +435,25 @@ pub trait TuiStyle: Widget<Engine = Tui> + Sized {
fn bg (self, color: Color) -> impl Widget<Engine = Tui> {
Layers::new(move |add|{ add(&Background(color))?; add(&self) })
}
fn bold (self, on: bool) -> impl Widget<Engine = Tui> {
Layers::new(move |add|{ add(&Bold(on))?; add(&self) })
}
fn border (self, style: impl BorderStyle) -> impl Widget<Engine = Tui> {
Bordered(style, self)
}
}
impl<W: Widget<Engine = Tui>> TuiStyle for W {}
pub struct Bold(pub bool);
impl Widget for Bold {
type Engine = Tui;
fn layout (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
Ok(Some([0,0]))
}
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
Ok(to.fill_bold(to.area(), self.0))
}
}
pub struct Foreground(pub Color);
impl Widget for Foreground {
type Engine = Tui;

View file

@ -34,7 +34,9 @@ impl Content for ArrangerStatusBar {
Self::PhrasePool => "Phrases",
Self::PhraseEditor => "Sequencer",
};
TuiStyle::bg(format!(" {label} "), Color::Rgb(150, 160, 90)).fg(Color::Rgb(0, 0, 0))
TuiStyle::bg(format!(" {label} "), Color::Rgb(150, 160, 90))
.fg(Color::Rgb(0, 0, 0))
.bold(true)
}
}
impl Content for Arrangement<Tui> {