use crate::*; pub struct Bordered>(pub S, pub W); render!(TuiOut: (self: Bordered>) => { Fill::xy(lay!(Border(self.0), Padding::xy(1, 1, &self.1))) }); pub struct Border(pub S); render!(TuiOut: |self: Border, to| { 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()); } } }); pub trait BorderStyle: Send + Sync + Copy { fn wrap > (self, w: W) -> Bordered { Bordered(self, w) } fn enclose > (self, w: W) -> impl Content { lay!(Fill::xy(Border(self)), w) } fn enclose_bg > (self, w: W) -> impl Content { Tui::bg(self.style().unwrap().bg.unwrap_or(Color::Reset), lay!( Fill::xy(Border(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<()> { 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