use crate::*; pub struct Bordered(pub bool, pub S, pub W); impl> Content for Bordered { fn content (&self) -> Option + '_> { Some(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); impl Render for Border { fn layout (&self, area: [u16;4]) -> [u16;4] { self.1.layout(area) } fn render (&self, to: &mut TuiOut) { 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: Render + Copy { fn enabled (&self) -> bool; fn enclose > (self, w: W) -> impl Render { Bsp::b(Fill::xy(Border(self.enabled(), self)), w) } fn enclose2 > (self, w: W) -> impl Render { Bsp::b(Margin::xy(1, 1, Fill::xy(Border(self.enabled(), self))), w) } fn enclose_bg > (self, w: W) -> impl Render { 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