mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-11 18:46:41 +01:00
parent
ca862b9802
commit
3ebdf9e71f
38 changed files with 602 additions and 1108 deletions
|
|
@ -1,47 +1,45 @@
|
|||
use crate::*;
|
||||
|
||||
impl<S: BorderStyle, W: Draw<TuiOut> + Layout<TuiOut>> Content<TuiOut> for Bordered<S, W> {
|
||||
fn content (&self) -> impl Draw<TuiOut> + Layout<TuiOut> + '_ {
|
||||
Fill::xy(lay!(
|
||||
When::new(self.0, Border(self.0, self.1)),
|
||||
Padding::xy(1, 1, &self.2)
|
||||
))
|
||||
impl<S: BorderStyle, W: Content<TuiOut>> HasContent<TuiOut> for Bordered<S, W> {
|
||||
fn content (&self) -> impl Content<TuiOut> {
|
||||
Fill::XY(lay!( When::new(self.0, Border(self.0, self.1)), Pad::XY(1, 1, &self.2) ))
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: BorderStyle> Draw<TuiOut> for Border<S> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
if self.0 {
|
||||
let Border(enabled, style) = self.0;
|
||||
if enabled {
|
||||
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());
|
||||
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(&self.1.n(), x, area.y(), self.1.style());
|
||||
to.blit(&self.1.s(), x, area.y() + area.h() - 1, self.1.style());
|
||||
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(&self.1.w(), area.x(), y, self.1.style());
|
||||
to.blit(&self.1.e(), area.x() + area.w() - 1, y, self.1.style());
|
||||
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: Draw<TuiOut> + Layout<TuiOut> + Copy {
|
||||
pub trait BorderStyle: Content<TuiOut> + Copy {
|
||||
fn enabled (&self) -> bool;
|
||||
fn enclose (self, w: impl Draw<TuiOut> + Layout<TuiOut>) -> impl Draw<TuiOut> + Layout<TuiOut> {
|
||||
Bsp::b(Fill::xy(Border(self.enabled(), self)), w)
|
||||
fn enclose (self, w: impl Draw<TuiOut>) -> impl Draw<TuiOut> {
|
||||
Bsp::b(Fill::XY(Border(self.enabled(), self)), w)
|
||||
}
|
||||
fn enclose2 (self, w: impl Draw<TuiOut> + Layout<TuiOut>) -> impl Draw<TuiOut> + Layout<TuiOut> {
|
||||
Bsp::b(Margin::xy(1, 1, Fill::xy(Border(self.enabled(), self))), w)
|
||||
fn enclose2 (self, w: impl Draw<TuiOut>) -> impl Draw<TuiOut> {
|
||||
Bsp::b(Pad::XY(1, 1, Fill::XY(Border(self.enabled(), self))), w)
|
||||
}
|
||||
fn enclose_bg (self, w: impl Draw<TuiOut> + Layout<TuiOut>) -> impl Draw<TuiOut> + Layout<TuiOut> {
|
||||
fn enclose_bg (self, w: impl Draw<TuiOut>) -> impl Draw<TuiOut> {
|
||||
Tui::bg(self.style().unwrap().bg.unwrap_or(Color::Reset),
|
||||
Bsp::b(Fill::xy(Border(self.enabled(), self)), w))
|
||||
Bsp::b(Fill::XY(Border(self.enabled(), self)), w))
|
||||
}
|
||||
const NW: &'static str = "";
|
||||
const N: &'static str = "";
|
||||
|
|
@ -57,14 +55,14 @@ pub trait BorderStyle: Draw<TuiOut> + Layout<TuiOut> + Copy {
|
|||
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 }
|
||||
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<()> {
|
||||
|
|
@ -143,7 +141,6 @@ macro_rules! border {
|
|||
fn enabled (&self) -> bool { self.0 }
|
||||
}
|
||||
#[derive(Copy, Clone)] pub struct $T(pub bool, pub Style);
|
||||
impl Layout<TuiOut> for $T {}
|
||||
impl Draw<TuiOut> for $T {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
if self.enabled() { let _ = BorderStyle::draw(self, to); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue