remove tek_proc; add Border

This commit is contained in:
🪞👃🪞 2024-09-13 03:26:59 +03:00
parent 6624fb476c
commit 70cef99931
9 changed files with 103 additions and 81 deletions

View file

@ -619,21 +619,35 @@ impl<T: Widget<Engine = Tui>> Widget for Outset<u16, T> {
}.render(to)
}
}
//impl<T: Widget<Engine = Tui>> Content for Outset<u16, T> {
//type Engine = Tui;
//fn content (&self) -> impl Widget<Engine = Tui> {
//match *self {
//Self::X(x, ref inner) =>
//Grow::X(x + x, inner as &dyn Widget<Engine = Tui>),
//Self::Y(y, ref inner) =>
//Grow::Y(y + y, inner as &dyn Widget<Engine = Tui>),
//Self::XY(x, y, ref inner) =>
//Grow::XY(x, y, inner as &dyn Widget<Engine = Tui>),
//}
//}
//}
pub trait BorderStyle {
pub struct Border<S: BorderStyle>(pub S);
impl<S: BorderStyle> Widget for Border<S> {
type Engine = Tui;
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
Outset::XY(1, 1, "").layout(to)
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
let area = to.area();
if area.w() > 2 && area.y() > 2 {
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(Some(area))
}
}
pub trait BorderStyle: Send + Sync {
const NW: &'static str = "";
const N: &'static str = "";
const NE: &'static str = "";
@ -643,6 +657,31 @@ pub trait BorderStyle {
const SW: &'static str = "";
const W: &'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 Tui) -> Perhaps<[u16;4]> {
self.draw_horizontal(to, None)?;
@ -743,8 +782,11 @@ macro_rules! border {
)+}
}
pub struct Square(pub Style);
pub struct SquareBold(pub Style);
pub struct Tab(pub Style);
pub struct Lozenge(pub Style);
pub struct LozengeV(pub Style);
pub struct Brace(pub Style);
pub struct LozengeDotted(pub Style);
pub struct Quarter(pub Style);
pub struct QuarterV(pub Style);
@ -752,6 +794,30 @@ pub struct Chamfer(pub Style);
pub struct Corners(pub Style);
border! {
Square {
"" "" ""
"" ""
"" "" ""
fn style (&self) -> Option<Style> {
Some(self.0)
}
},
SquareBold {
"" "" ""
"" ""
"" "" ""
fn style (&self) -> Option<Style> {
Some(self.0)
}
},
Tab {
"" "" ""
"" ""
"" " " ""
fn style (&self) -> Option<Style> {
Some(self.0)
}
},
Lozenge {
"" "" ""
"" ""
@ -760,7 +826,7 @@ border! {
Some(self.0)
}
},
LozengeV {
Brace {
"" "" ""
"" ""
"" "" ""