use super::*; /// Draw border around item shrunk by 1 on each side. /// /// ``` /// /// TODO /// ``` pub const fn border (on: bool, style: impl BorderStyle, draw: impl Draw) -> impl Draw { let content = wh_pad(1, 1, draw); let outline = when(on, thunk(move|to: &mut Tui|{ let XYWH(x, y, w, h) = to.1; if w > 0 && h > 0 { to.blit(&style.border_nw(), x, y, style.style()); to.blit(&style.border_ne(), x + w - 1, y, style.style()); to.blit(&style.border_sw(), x, y + h - 1, style.style()); to.blit(&style.border_se(), x + w - 1, y + h - 1, style.style()); for x in x+1..x+w-1 { to.blit(&style.border_n(), x, y, style.style()); to.blit(&style.border_s(), x, y + h - 1, style.style()); } for y in y+1..y+h-1 { to.blit(&style.border_w(), x, y, style.style()); to.blit(&style.border_e(), x + w - 1, y, style.style()); } } Ok(Some(XYWH(x, y, w, h))) })); above(outline, content) } macro_rules! border { ($($T:ident { $nw:literal $n:literal $ne:literal $w:literal $e:literal $sw:literal $s:literal $se:literal $($x:tt)* }),+) => {$( impl BorderStyle for $T { const NW: &'static str = $nw; const N: &'static str = $n; const NE: &'static str = $ne; const W: &'static str = $w; const E: &'static str = $e; const SW: &'static str = $sw; const S: &'static str = $s; const SE: &'static str = $se; $($x)* fn enabled (&self) -> bool { self.0 } } #[derive(Copy, Clone)] pub struct $T(pub bool, pub Style); //impl Layout for $T {} impl Draw for $T { fn draw (self, to: &mut Tui) -> Perhaps> { when(self.enabled(), thunk(|to: &mut Tui|BorderStyle::draw(self, to))).draw(to) } } )+} } border! { Square { "┌" "─" "┐" "│" "│" "└" "─" "┘" fn style (&self) -> Option