diff --git a/tui/src/tui_content.rs b/tui/src/tui_content.rs index d2a6b9a..f6048e6 100644 --- a/tui/src/tui_content.rs +++ b/tui/src/tui_content.rs @@ -5,6 +5,7 @@ mod tui_color; pub use self::tui_color::*; mod tui_file; pub use self::tui_file::*; mod tui_scroll; pub use self::tui_scroll::*; mod tui_string; pub use self::tui_string::*; +mod tui_border; pub use self::tui_border::*; macro_rules! impl_content_layout_render { ($Output:ty: |$self:ident: $Struct:ty, $to:ident| layout = $layout:expr; render = $render:expr) => { @@ -200,263 +201,3 @@ impl> Content for Styled { // TODO write style over area } } - -pub struct Bordered>(pub bool, pub S, pub W); -content!(TuiOut: |self: Bordered>|Fill::xy( - lay!(When::new(self.0, Border(self.0, self.1)), Padding::xy(1, 1, &self.2)) -)); - -pub struct Border(pub bool, pub S); -render!(TuiOut: |self: Border, to| { - if self.0 { - let area = to.area(); - if area.w() > 0 && area.y() > 0 { - to.blit(&self.1.nw(), area.x(), area.y(), self.1.style()); - to.blit(&self.1.ne(), area.x() + area.w() - 1, area.y(), self.1.style()); - to.blit(&self.1.sw(), area.x(), area.y() + area.h() - 1, self.1.style()); - to.blit(&self.1.se(), area.x() + area.w() - 1, area.y() + area.h() - 1, self.1.style()); - for x in area.x()+1..area.x()+area.w()-1 { - to.blit(&self.1.n(), x, area.y(), self.1.style()); - to.blit(&self.1.s(), x, area.y() + area.h() - 1, self.1.style()); - } - for y in area.y()+1..area.y()+area.h()-1 { - to.blit(&self.1.w(), area.x(), y, self.1.style()); - to.blit(&self.1.e(), area.x() + area.w() - 1, y, self.1.style()); - } - } - } -}); - -pub trait BorderStyle: Send + Sync + Copy { - fn enabled (&self) -> bool; - fn enclose > (self, w: W) -> impl Content { - Bsp::b(Fill::xy(Border(self.enabled(), self)), w) - } - fn enclose2 > (self, w: W) -> impl Content { - Bsp::b(Margin::xy(1, 1, Fill::xy(Border(self.enabled(), self))), w) - } - fn enclose_bg > (self, w: W) -> impl Content { - Tui::bg(self.style().unwrap().bg.unwrap_or(Color::Reset), - Bsp::b(Fill::xy(Border(self.enabled(), 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 = ""; - - const N0: &'static str = ""; - const S0: &'static str = ""; - const W0: &'static str = ""; - const E0: &'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 TuiOut - ) -> Usually<()> { - if self.enabled() { - self.draw_horizontal(to, None)?; - self.draw_vertical(to, None)?; - self.draw_corners(to, None)?; - } - Ok(()) - } - #[inline] fn draw_horizontal ( - &self, to: &mut TuiOut, style: Option