use crate::*; pub struct Bordered>(pub S, pub W); render!(|self: Bordered>|{ Fill::wh(lay!([Border(self.0), Padding::xy(1, 1, &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 = ""; 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 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