diff --git a/crates/tek/src/tui.rs b/crates/tek/src/tui.rs index e5628203..2f9b5f1c 100644 --- a/crates/tek/src/tui.rs +++ b/crates/tek/src/tui.rs @@ -4,6 +4,7 @@ mod tui_input; pub(crate) use tui_input::*; mod tui_style; pub(crate) use tui_style::*; mod tui_theme; pub(crate) use tui_theme::*; mod tui_output; pub(crate) use tui_output::*; +mod tui_border; pub(crate) use tui_border::*; //////////////////////////////////////////////////////// diff --git a/crates/tek/src/tui/tui_border.rs b/crates/tek/src/tui/tui_border.rs new file mode 100644 index 00000000..76e615d9 --- /dev/null +++ b/crates/tek/src/tui/tui_border.rs @@ -0,0 +1,211 @@ +use crate::*; + +pub struct Bordered>(pub S, pub W); + +render!(|self: Bordered>|{ + Tui::fill_xy(lay!([Border(self.0), Tui::inset_xy(1, 1, widget(&self.1))])) +}); + +pub struct Border(pub S); + +impl Render for Border { + fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { + Ok(Some([0, 0])) + } + fn render (&self, to: &mut TuiOutput) -> Usually<()> { + let area = to.area(); + if area.w() > 0 && area.y() > 0 { + to.blit(&self.0.nw(), area.x(), area.y(), self.0.style()); + to.blit(&self.0.ne(), area.x() + area.w() - 1, area.y(), self.0.style()); + to.blit(&self.0.sw(), area.x(), area.y() + area.h() - 1, self.0.style()); + to.blit(&self.0.se(), area.x() + area.w() - 1, area.y() + area.h() - 1, self.0.style()); + for x in area.x()+1..area.x()+area.w()-1 { + to.blit(&self.0.n(), x, area.y(), self.0.style()); + to.blit(&self.0.s(), x, area.y() + area.h() - 1, self.0.style()); + } + for y in area.y()+1..area.y()+area.h()-1 { + to.blit(&self.0.w(), area.x(), y, self.0.style()); + to.blit(&self.0.e(), area.x() + area.w() - 1, y, self.0.style()); + } + } + Ok(()) + } +} + +pub trait BorderStyle: Send + Sync + Copy { + fn wrap > (self, w: W) -> Bordered { + Bordered(self, w) + } + const NW: &'static str = ""; + const N: &'static str = ""; + const NE: &'static str = ""; + const E: &'static str = ""; + const SE: &'static str = ""; + const S: &'static str = ""; + const SW: &'static str = ""; + const W: &'static str = ""; + fn n (&self) -> &str { Self::N } + fn s (&self) -> &str { Self::S } + fn e (&self) -> &str { Self::E } + fn w (&self) -> &str { Self::W } + fn nw (&self) -> &str { Self::NW } + fn ne (&self) -> &str { Self::NE } + fn sw (&self) -> &str { Self::SW } + fn se (&self) -> &str { Self::SE } + #[inline] fn draw <'a> ( + &self, to: &mut TuiOutput + ) -> Usually<()> { + self.draw_horizontal(to, None)?; + self.draw_vertical(to, None)?; + self.draw_corners(to, None)?; + Ok(()) + } + #[inline] fn draw_horizontal ( + &self, to: &mut TuiOutput, style: Option