mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
sweeeeping sweep
This commit is contained in:
parent
c9b09b7dea
commit
e677d1d7d4
38 changed files with 766 additions and 691 deletions
|
|
@ -1,39 +1,34 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct Bordered<S: BorderStyle, W: Render<Tui>>(pub S, pub W);
|
||||
pub struct Bordered<S: BorderStyle, W: Content<Tui>>(pub S, pub W);
|
||||
|
||||
render!(<Tui>|self: Bordered<S: BorderStyle, W: Render<Tui>>|{
|
||||
render!(Tui: (self: Bordered<S: BorderStyle, W: Content<Tui>>) => {
|
||||
Fill::xy(lay!([Border(self.0), Padding::xy(1, 1, &self.1)]))
|
||||
});
|
||||
|
||||
pub struct Border<S: BorderStyle>(pub S);
|
||||
|
||||
impl<S: BorderStyle> Render<Tui> for Border<S> {
|
||||
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());
|
||||
}
|
||||
render!(Tui: |self: Border<S: BorderStyle>, to| {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
|
||||
pub trait BorderStyle: Send + Sync + Copy {
|
||||
fn wrap <W: Render<Tui>> (self, w: W) -> Bordered<Self, W> {
|
||||
fn wrap <W: Content<Tui>> (self, w: W) -> Bordered<Self, W> {
|
||||
Bordered(self, w)
|
||||
}
|
||||
const NW: &'static str = "";
|
||||
|
|
@ -134,7 +129,7 @@ macro_rules! border {
|
|||
}
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct $T(pub Style);
|
||||
impl Render<Tui> for $T {
|
||||
impl Content<Tui> for $T {
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
|
||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> { self.draw(to) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue