0.4.0: fill_mod, tint

This commit is contained in:
🪞👃🪞 2025-03-23 21:42:25 +02:00
parent b0bb7f818b
commit 81e7f50363
3 changed files with 56 additions and 41 deletions

10
Cargo.lock generated
View file

@ -934,7 +934,7 @@ dependencies = [
[[package]] [[package]]
name = "tengri" name = "tengri"
version = "0.3.4" version = "0.4.0"
dependencies = [ dependencies = [
"tengri_dsl", "tengri_dsl",
"tengri_input", "tengri_input",
@ -944,7 +944,7 @@ dependencies = [
[[package]] [[package]]
name = "tengri_dsl" name = "tengri_dsl"
version = "0.3.4" version = "0.4.0"
dependencies = [ dependencies = [
"itertools 0.14.0", "itertools 0.14.0",
"konst", "konst",
@ -955,7 +955,7 @@ dependencies = [
[[package]] [[package]]
name = "tengri_input" name = "tengri_input"
version = "0.3.4" version = "0.4.0"
dependencies = [ dependencies = [
"tengri_dsl", "tengri_dsl",
"tengri_tui", "tengri_tui",
@ -963,7 +963,7 @@ dependencies = [
[[package]] [[package]]
name = "tengri_output" name = "tengri_output"
version = "0.3.4" version = "0.4.0"
dependencies = [ dependencies = [
"proptest", "proptest",
"proptest-derive", "proptest-derive",
@ -974,7 +974,7 @@ dependencies = [
[[package]] [[package]]
name = "tengri_tui" name = "tengri_tui"
version = "0.3.4" version = "0.4.0"
dependencies = [ dependencies = [
"atomic_float", "atomic_float",
"better-panic", "better-panic",

View file

@ -1,5 +1,5 @@
[workspace.package] [workspace.package]
version = "0.3.4" version = "0.4.0"
[workspace] [workspace]
resolver = "2" resolver = "2"

View file

@ -55,37 +55,10 @@ impl TuiOut {
std::thread::sleep(timer); std::thread::sleep(timer);
}) })
} }
pub fn buffer_update (&mut self, area: [u16;4], callback: &impl Fn(&mut Cell, u16, u16)) { #[inline]
buffer_update(&mut self.buffer, area, callback); pub fn with_rect (&mut self, area: [u16;4]) -> &mut Self {
} self.area = area;
pub fn fill_bold (&mut self, area: [u16;4], on: bool) { self
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);})
}
pub fn fill_fg (&mut self, area: [u16;4], color: Color) {
self.buffer_update(area, &|cell,_,_|{cell.set_fg(color);})
}
pub fn fill_ul (&mut self, area: [u16;4], color: Color) {
self.buffer_update(area, &|cell,_,_|{
cell.modifier = ratatui::prelude::Modifier::UNDERLINED;
cell.underline_color = color;
})
}
pub fn fill_char (&mut self, area: [u16;4], c: char) {
self.buffer_update(area, &|cell,_,_|{cell.set_char(c);})
}
pub fn make_dim (&mut self) {
for cell in self.buffer.content.iter_mut() {
cell.bg = ratatui::style::Color::Rgb(30,30,30);
cell.fg = ratatui::style::Color::Rgb(100,100,100);
cell.modifier = ratatui::style::Modifier::DIM;
}
} }
pub fn blit ( pub fn blit (
&mut self, text: &impl AsRef<str>, x: u16, y: u16, style: Option<Style> &mut self, text: &impl AsRef<str>, x: u16, y: u16, style: Option<Style>
@ -96,9 +69,51 @@ impl TuiOut {
buf.set_string(x, y, text, style.unwrap_or(Style::default())); buf.set_string(x, y, text, style.unwrap_or(Style::default()));
} }
} }
#[inline] pub fn buffer_update (&mut self, area: [u16;4], callback: &impl Fn(&mut Cell, u16, u16)) {
pub fn with_rect (&mut self, area: [u16;4]) -> &mut Self { buffer_update(&mut self.buffer, area, callback);
self.area = area; }
self pub fn fill_char (&mut self, area: [u16;4], c: char) {
self.buffer_update(area, &|cell,_,_|{cell.set_char(c);})
}
pub fn fill_bg (&mut self, area: [u16;4], color: Color) {
self.buffer_update(area, &|cell,_,_|{cell.set_bg(color);})
}
pub fn fill_fg (&mut self, area: [u16;4], color: Color) {
self.buffer_update(area, &|cell,_,_|{cell.set_fg(color);})
}
pub fn fill_mod (&mut self, area: [u16;4], on: bool, modifier: Modifier) {
if on {
self.buffer_update(area, &|cell,_,_|cell.modifier.insert(modifier))
} else {
self.buffer_update(area, &|cell,_,_|cell.modifier.remove(modifier))
}
}
pub fn fill_bold (&mut self, area: [u16;4], on: bool) {
self.fill_mod(area, on, Modifier::BOLD)
}
pub fn fill_reversed (&mut self, area: [u16;4], on: bool) {
self.fill_mod(area, on, Modifier::REVERSED)
}
pub fn fill_crossed_out (&mut self, area: [u16;4], on: bool) {
self.fill_mod(area, on, Modifier::CROSSED_OUT)
}
pub fn fill_ul (&mut self, area: [u16;4], color: Option<Color>) {
if let Some(color) = color {
self.buffer_update(area, &|cell,_,_|{
cell.modifier.insert(ratatui::prelude::Modifier::UNDERLINED);
cell.underline_color = color;
})
} else {
self.buffer_update(area, &|cell,_,_|{
cell.modifier.remove(ratatui::prelude::Modifier::UNDERLINED);
})
}
}
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.modifier = modifier;
}
} }
} }