use crate::*; impl> HasContent for Bordered { fn content (&self) -> impl Content { Fill::XY(lay!( When::new(self.0, Border(self.0, self.1)), Pad::XY(1, 1, &self.2) )) } } impl Draw for Border { fn draw (&self, to: &mut TuiOut) { let Border(enabled, style) = self.0; if enabled { let area = to.area(); if area.w() > 0 && area.y() > 0 { to.blit(&style.border_nw(), area.x(), area.y(), style.style()); to.blit(&style.border_ne(), area.x() + area.w() - 1, area.y(), style.style()); to.blit(&style.border_sw(), area.x(), area.y() + area.h() - 1, style.style()); to.blit(&style.border_se(), area.x() + area.w() - 1, area.y() + area.h() - 1, style.style()); for x in area.x()+1..area.x()+area.w()-1 { to.blit(&style.border_n(), x, area.y(), style.style()); to.blit(&style.border_s(), x, area.y() + area.h() - 1, style.style()); } for y in area.y()+1..area.y()+area.h()-1 { to.blit(&style.border_w(), area.x(), y, style.style()); to.blit(&style.border_e(), area.x() + area.w() - 1, y, style.style()); } } } } } pub trait BorderStyle: Content + Copy { fn enabled (&self) -> bool; fn enclose (self, w: impl Draw) -> impl Draw { Bsp::b(Fill::XY(Border(self.enabled(), self)), w) } fn enclose2 (self, w: impl Draw) -> impl Draw { Bsp::b(Pad::XY(1, 1, Fill::XY(Border(self.enabled(), self))), w) } fn enclose_bg (self, w: impl Draw) -> impl Draw { 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 border_n (&self) -> &str { Self::N } fn border_s (&self) -> &str { Self::S } fn border_e (&self) -> &str { Self::E } fn border_w (&self) -> &str { Self::W } fn border_nw (&self) -> &str { Self::NW } fn border_ne (&self) -> &str { Self::NE } fn border_sw (&self) -> &str { Self::SW } fn border_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