mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 03:36:42 +01:00
uuugh
This commit is contained in:
parent
ca862b9802
commit
90fc869e14
42 changed files with 645 additions and 1158 deletions
|
|
@ -28,19 +28,18 @@ impl ExampleCommand {
|
|||
}
|
||||
}
|
||||
|
||||
tui_draw!(|self: Example, to|{
|
||||
to.place(&self.content());
|
||||
});
|
||||
content!(TuiOut: |self: Example|{
|
||||
let index = self.0 + 1;
|
||||
let wh = self.1.wh();
|
||||
let src = Self::VIEWS.get(self.0).unwrap_or(&"");
|
||||
let heading = format!("Example {}/{} in {:?}", index, Self::VIEWS.len(), &wh);
|
||||
let title = Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(heading)));
|
||||
let code = Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", src))));
|
||||
let content = ();//Tui::bg(Color::Rgb(10, 10, 60), View(self, CstIter::new(src)));
|
||||
self.1.of(Bsp::s(title, Bsp::n(""/*code*/, content)))
|
||||
});
|
||||
impl Draw<TuiOut> for Example {
|
||||
fn content (&self) -> impl Draw<TuiOut> {
|
||||
let index = self.0 + 1;
|
||||
let wh = self.1.wh();
|
||||
let src = Self::VIEWS.get(self.0).unwrap_or(&"");
|
||||
let heading = format!("Example {}/{} in {:?}", index, Self::VIEWS.len(), &wh);
|
||||
let title = Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(heading)));
|
||||
let code = Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", src))));
|
||||
let content = ();//Tui::bg(Color::Rgb(10, 10, 60), View(self, CstIter::new(src)));
|
||||
self.1.of(Bsp::s(title, Bsp::n(""/*code*/, content)))
|
||||
}
|
||||
}
|
||||
impl View<TuiOut, ()> for Example {
|
||||
fn view_expr <'a> (&'a self, to: &mut TuiOut, expr: &'a impl DslExpr) -> Usually<()> {
|
||||
if evaluate_output_expression(self, to, expr)?
|
||||
|
|
|
|||
|
|
@ -12,25 +12,25 @@ fn main () {}
|
|||
|
||||
//#[tengri_proc::view(TuiOut)]
|
||||
//impl Example {
|
||||
//pub fn title (&self) -> impl Draw<TuiOut> + use<'_> {
|
||||
//pub fn title (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, VIEWS.len())))).boxed()
|
||||
//}
|
||||
//pub fn code (&self) -> impl Draw<TuiOut> + use<'_> {
|
||||
//pub fn code (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", VIEWS[self.0])))).boxed()
|
||||
//}
|
||||
//pub fn hello (&self) -> impl Draw<TuiOut> + use<'_> {
|
||||
//pub fn hello (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed()
|
||||
//}
|
||||
//pub fn world (&self) -> impl Draw<TuiOut> + use<'_> {
|
||||
//pub fn world (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Tui::bg(Color::Rgb(100, 10, 10), "world").boxed()
|
||||
//}
|
||||
//pub fn hello_world (&self) -> impl Draw<TuiOut> + use<'_> {
|
||||
//pub fn hello_world (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//"Hello world!".boxed()
|
||||
//}
|
||||
//pub fn map_e (&self) -> impl Draw<TuiOut> + use<'_> {
|
||||
//pub fn map_e (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Map::east(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
|
||||
//}
|
||||
//pub fn map_s (&self) -> impl Draw<TuiOut> + use<'_> {
|
||||
//pub fn map_s (&self) -> impl Content<TuiOut> + use<'_> {
|
||||
//Map::south(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
|
||||
//}
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,50 +1,12 @@
|
|||
#[allow(unused)] use crate::*;
|
||||
|
||||
impl Tui {
|
||||
pub const fn fg <T> (color: Color, w: T) -> TuiForeground<T> {
|
||||
TuiForeground(Foreground(color, w))
|
||||
}
|
||||
pub const fn bg <T> (color: Color, w: T) -> TuiBackground<T> {
|
||||
TuiBackground(Background(color, w))
|
||||
}
|
||||
pub const fn fg_bg <T> (fg: Color, bg: Color, w: T) -> TuiBackground<TuiForeground<T>> {
|
||||
TuiBackground(Background(bg, TuiForeground(Foreground(fg, w))))
|
||||
}
|
||||
pub const fn modify <T> (enable: bool, modifier: Modifier, w: T) -> Modify<T> {
|
||||
Modify(enable, modifier, w)
|
||||
}
|
||||
pub const fn bold <T> (enable: bool, w: T) -> Modify<T> {
|
||||
Self::modify(enable, Modifier::BOLD, w)
|
||||
}
|
||||
pub const fn border <S, T> (enable: bool, style: S, w: T) -> Bordered<S, T> {
|
||||
Bordered(enable, style, w)
|
||||
}
|
||||
pub const fn fg <T> (color: Color, w: T) -> Foreground<Color, T> { Foreground(color, w) }
|
||||
pub const fn bg <T> (color: Color, w: T) -> Background<Color, T> { Background(color, w) }
|
||||
pub const fn fg_bg <T> (fg: Color, bg: Color, w: T) -> Background<Color, Foreground<Color, T>> { Background(bg, Foreground(fg, w)) }
|
||||
pub const fn modify <T> (enable: bool, modifier: Modifier, w: T) -> Modify<T> { Modify(enable, modifier, w) }
|
||||
pub const fn bold <T> (enable: bool, w: T) -> Modify<T> { Self::modify(enable, Modifier::BOLD, w) }
|
||||
pub const fn border <S, T> (enable: bool, style: S, w: T) -> Bordered<S, T> { Bordered(enable, style, w) }
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! tui_layout ((|$self:ident:$Self:ty, $to:ident|$expr:expr)=>{
|
||||
impl Layout<TuiOut> for $Self {
|
||||
fn layout (&$self, $to: [u16;4]) -> [u16;4] {
|
||||
$expr
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
#[macro_export] macro_rules! tui_draw ((|$self:ident:$Self:ty, $to:ident|$expr:expr)=>{
|
||||
impl Draw<TuiOut> for $Self {
|
||||
fn draw (&$self, $to: &mut TuiOut) {
|
||||
$expr
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
#[macro_export] macro_rules! tui_content ((|$self:ident:$Self:ty|$sexpr:expr)=>{
|
||||
impl Content<TuiOut> for $Self {
|
||||
fn content (&$self) -> impl Draw<TuiOut> + Layout<TuiOut> + '_ {
|
||||
$expr
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mod tui_border; pub use self::tui_border::*;
|
||||
mod tui_button; pub use self::tui_button::*;
|
||||
mod tui_color; pub use self::tui_color::*;
|
||||
|
|
@ -54,67 +16,41 @@ mod tui_phat; pub use self::tui_phat::*;
|
|||
mod tui_repeat; pub use self::tui_repeat::*;
|
||||
mod tui_scroll; pub use self::tui_scroll::*;
|
||||
mod tui_string; pub use self::tui_string::*;
|
||||
|
||||
mod tui_number; //pub use self::tui_number::*;
|
||||
mod tui_tryptich; //pub use self::tui_tryptich::*;
|
||||
|
||||
pub struct TuiForeground<T>(pub(crate) Foreground<Color, T>);
|
||||
pub struct TuiBackground<T>(pub(crate) Background<Color, T>);
|
||||
impl<T: Content<TuiOut>> Draw<TuiOut> for Foreground<Color, T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let area = self.layout(to.area());
|
||||
to.fill_fg(area, self.0);
|
||||
to.place_at(area, &self.1);
|
||||
}
|
||||
}
|
||||
impl<T: Content<TuiOut>> Draw<TuiOut> for Background<Color, T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let area = self.layout(to.area());
|
||||
to.fill_bg(area, self.0);
|
||||
to.place_at(area, &self.1);
|
||||
}
|
||||
}
|
||||
pub struct Modify<T>(pub bool, pub Modifier, pub T);
|
||||
pub struct Styled<T>(pub Option<Style>, pub T);
|
||||
|
||||
impl<T: Layout<TuiOut>> Layout<TuiOut> for TuiForeground<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.0.layout(to)
|
||||
}
|
||||
}
|
||||
impl<T: Layout<TuiOut> + Draw<TuiOut>> Draw<TuiOut> for TuiForeground<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let area = self.layout(to.area());
|
||||
to.fill_fg(area, self.0.0);
|
||||
to.place_at(area, &self.0.1);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Layout<TuiOut>> Layout<TuiOut> for TuiBackground<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.0.layout(to)
|
||||
}
|
||||
}
|
||||
impl<T: Layout<TuiOut> + Draw<TuiOut>> Draw<TuiOut> for TuiBackground<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let area = self.layout(to.area());
|
||||
to.fill_bg(area, self.0.0);
|
||||
to.place_at(area, &self.0.1);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Layout<TuiOut>> Layout<TuiOut> for Modify<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.2.layout(to)
|
||||
}
|
||||
}
|
||||
impl<T: Draw<TuiOut>> Draw<TuiOut> for Modify<T> {
|
||||
impl<T: Content<TuiOut>> Layout<TuiOut> for Modify<T> {}
|
||||
impl<T: Content<TuiOut>> Draw<TuiOut> for Modify<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
to.fill_mod(to.area(), self.0, self.1);
|
||||
self.2.draw(to)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Layout<TuiOut>> Layout<TuiOut> for Styled<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
self.1.layout(to)
|
||||
}
|
||||
}
|
||||
impl<T: Layout<TuiOut> + Draw<TuiOut>> Draw<TuiOut> for Styled<T> {
|
||||
pub struct Styled<T>(pub Option<Style>, pub T);
|
||||
impl<T: Content<TuiOut>> Layout<TuiOut> for Styled<T> {}
|
||||
impl<T: Content<TuiOut>> Draw<TuiOut> for Styled<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
to.place(&self.1);
|
||||
// TODO write style over area
|
||||
}
|
||||
}
|
||||
|
||||
//impl<T: Draw<TuiOut> + Layout<TuiOut>> Content<TuiOut> for Result<T, Box<dyn std::error::Error>> {
|
||||
//fn content (&self) -> impl Draw<TuiOut> + Layout<TuiOut> + '_ {
|
||||
//impl<T: Draw<TuiOut>> Content<TuiOut> for Result<T, Box<dyn std::error::Error>> {
|
||||
//fn content (&self) -> impl Draw<TuiOut> + '_ {
|
||||
//Bsp::a(self.as_ref().ok(), self.as_ref().err().map(
|
||||
//|e|Tui::fg_bg(Color::Rgb(255,255,255), Color::Rgb(32,32,32), e.to_string())
|
||||
//))
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
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 Content<TuiOut>) -> impl Content<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 Content<TuiOut>) -> impl Content<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 Content<TuiOut>) -> impl Content<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<()> {
|
||||
|
|
|
|||
|
|
@ -1,38 +1,18 @@
|
|||
use crate::{*, Color::*};
|
||||
|
||||
pub fn button_2 <'a> (
|
||||
key: impl Draw<TuiOut> + Layout<TuiOut> + 'a,
|
||||
label: impl Draw<TuiOut> + Layout<TuiOut> + 'a,
|
||||
editing: bool,
|
||||
) -> impl Draw<TuiOut> + Layout<TuiOut> + 'a {
|
||||
let key = Tui::fg_bg(Tui::orange(), Tui::g(0), Bsp::e(
|
||||
Tui::fg(Tui::g(0), "▐"),
|
||||
Bsp::e(key, Tui::fg(Tui::g(96), "▐"))
|
||||
));
|
||||
let label = When::new(!editing, Tui::fg_bg(Tui::g(255), Tui::g(96), label));
|
||||
Tui::bold(true, Bsp::e(key, label))
|
||||
pub fn button_2 <'a> (key: impl Content<TuiOut>, label: impl Content<TuiOut>, editing: bool) -> impl Content<TuiOut> {
|
||||
Tui::bold(true, Bsp::e(
|
||||
Tui::fg_bg(Tui::orange(), Tui::g(0), Bsp::e(Tui::fg(Tui::g(0), &"▐"), Bsp::e(key, Tui::fg(Tui::g(96), &"▐")))),
|
||||
When::new(!editing, Tui::fg_bg(Tui::g(255), Tui::g(96), label))))
|
||||
}
|
||||
|
||||
pub fn button_3 <'a> (
|
||||
key: impl Draw<TuiOut> + Layout<TuiOut> + 'a,
|
||||
label: impl Draw<TuiOut> + Layout<TuiOut> + 'a,
|
||||
value: impl Draw<TuiOut> + Layout<TuiOut> + 'a,
|
||||
editing: bool,
|
||||
) -> impl Draw<TuiOut> + Layout<TuiOut> + 'a {
|
||||
let key = Tui::fg_bg(Tui::orange(), Tui::g(0),
|
||||
Bsp::e(Tui::fg(Tui::g(0), "▐"), Bsp::e(key, Tui::fg(if editing {
|
||||
Tui::g(128)
|
||||
} else {
|
||||
Tui::g(96)
|
||||
}, "▐"))));
|
||||
let label = Bsp::e(
|
||||
When::new(!editing, Bsp::e(
|
||||
Tui::fg_bg(Tui::g(255), Tui::g(96), label),
|
||||
Tui::fg_bg(Tui::g(128), Tui::g(96), "▐"),
|
||||
)),
|
||||
key: impl Content<TuiOut>, label: impl Content<TuiOut>, value: impl Content<TuiOut>, editing: bool,
|
||||
) -> impl Content<TuiOut> {
|
||||
Tui::bold(true, Bsp::e(
|
||||
Tui::fg_bg(Tui::orange(), Tui::g(0),
|
||||
Bsp::e(Tui::fg(Tui::g(0), &"▐"), Bsp::e(key, Tui::fg(if editing { Tui::g(128) } else { Tui::g(96) }, "▐")))),
|
||||
Bsp::e(
|
||||
Tui::fg_bg(Tui::g(224), Tui::g(128), value),
|
||||
Tui::fg_bg(Tui::g(128), Reset, "▌"),
|
||||
));
|
||||
Tui::bold(true, Bsp::e(key, label))
|
||||
When::new(!editing, Bsp::e(Tui::fg_bg(Tui::g(255), Tui::g(96), label), Tui::fg_bg(Tui::g(128), Tui::g(96), &"▐"),)),
|
||||
Bsp::e(Tui::fg_bg(Tui::g(224), Tui::g(128), value), Tui::fg_bg(Tui::g(128), Reset, &"▌"), ))))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,5 @@
|
|||
use crate::*;
|
||||
|
||||
impl<
|
||||
Label: Draw<TuiOut> + Layout<TuiOut>,
|
||||
Value: Draw<TuiOut> + Layout<TuiOut>
|
||||
> Content<TuiOut> for FieldH<ItemTheme, Label, Value> {
|
||||
fn content (&self) -> impl Draw<TuiOut> + Layout<TuiOut> + '_ {
|
||||
let Self(ItemTheme { darkest, dark, lightest, .. }, title, value) = self;
|
||||
row!(
|
||||
Tui::fg_bg(dark.rgb, darkest.rgb, "▐"),
|
||||
Tui::fg_bg(lightest.rgb, dark.rgb, title),
|
||||
Tui::fg_bg(dark.rgb, darkest.rgb, "▌"),
|
||||
Tui::fg_bg(lightest.rgb, darkest.rgb, Tui::bold(true, value)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
Label: Draw<TuiOut> + Layout<TuiOut>,
|
||||
Value: Draw<TuiOut> + Layout<TuiOut>
|
||||
> Content<TuiOut> for FieldV<ItemTheme, Label, Value> {
|
||||
fn content (&self) -> impl Draw<TuiOut> + Layout<TuiOut> + '_ {
|
||||
let Self(ItemTheme { darkest, dark, lightest, .. }, title, value) = self;
|
||||
Bsp::n(
|
||||
Align::w(Tui::bg(darkest.rgb, Tui::fg(lightest.rgb, Tui::bold(true, value)))),
|
||||
Fill::x(Align::w(row!(
|
||||
Tui::bg(darkest.rgb, Tui::fg(dark.rgb, "▐")),
|
||||
Tui::bg(dark.rgb, Tui::fg(lightest.rgb, title)),
|
||||
Tui::bg(darkest.rgb, Tui::fg(dark.rgb, "▌")),
|
||||
)))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
pub struct Field<T, U> {
|
||||
pub direction: Direction,
|
||||
|
|
@ -44,8 +12,8 @@ pub struct Field<T, U> {
|
|||
pub value_bg: Option<ItemColor>,
|
||||
pub value_align: Option<Direction>,
|
||||
}
|
||||
impl<T: Draw<TuiOut>, U: Draw<TuiOut>> Content<TuiOut> for Field<T, U> {
|
||||
fn content (&self) -> impl Draw<TuiOut> + Layout<TuiOut> + '_ {
|
||||
impl<T: Content<TuiOut>, U: Content<TuiOut>> HasContent<TuiOut> for Field<T, U> {
|
||||
fn content (&self) -> impl Content<TuiOut> {
|
||||
"TODO"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,21 +13,17 @@ impl<T> Phat<T> {
|
|||
pub const LO: &'static str = "▄";
|
||||
pub const HI: &'static str = "▀";
|
||||
/// A phat line
|
||||
pub fn lo (fg: Color, bg: Color) -> impl Draw<TuiOut> + Layout<TuiOut> {
|
||||
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(Self::LO)))
|
||||
}
|
||||
pub fn lo (fg: Color, bg: Color) -> impl Content<TuiOut> { Fixed::Y(1, Tui::fg_bg(fg, bg, RepeatH(Self::LO))) }
|
||||
/// A phat line
|
||||
pub fn hi (fg: Color, bg: Color) -> impl Draw<TuiOut> + Layout<TuiOut> {
|
||||
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(Self::HI)))
|
||||
}
|
||||
pub fn hi (fg: Color, bg: Color) -> impl Content<TuiOut> { Fixed::Y(1, Tui::fg_bg(fg, bg, RepeatH(Self::HI))) }
|
||||
}
|
||||
|
||||
impl<T: Layout<TuiOut> + Draw<TuiOut>> Content<TuiOut> for Phat<T> {
|
||||
fn content (&self) -> impl Draw<TuiOut> + Layout<TuiOut> + '_ {
|
||||
impl<T: Content<TuiOut>> HasContent<TuiOut> for Phat<T> {
|
||||
fn content (&self) -> impl Content<TuiOut> {
|
||||
let [fg, bg, hi, lo] = self.colors;
|
||||
let top = Fixed::y(1, Self::lo(bg, hi));
|
||||
let low = Fixed::y(1, Self::hi(bg, lo));
|
||||
let top = Fixed::Y(1, Self::lo(bg, hi));
|
||||
let low = Fixed::Y(1, Self::hi(bg, lo));
|
||||
let content = Tui::fg_bg(fg, bg, &self.content);
|
||||
Min::xy(self.width, self.height, Bsp::s(top, Bsp::n(low, Fill::xy(content))))
|
||||
Min::XY(self.width, self.height, Bsp::s(top, Bsp::n(low, Fill::XY(content))))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,6 @@ use crate::*;
|
|||
use ratatui::prelude::Position;
|
||||
|
||||
pub struct Repeat<'a>(pub &'a str);
|
||||
impl Layout<TuiOut> for Repeat<'_> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
to
|
||||
}
|
||||
}
|
||||
impl Draw<TuiOut> for Repeat<'_> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let [x, y, w, h] = to.area().xywh();
|
||||
|
|
@ -23,11 +18,7 @@ impl Draw<TuiOut> for Repeat<'_> {
|
|||
}
|
||||
|
||||
pub struct RepeatV<'a>(pub &'a str);
|
||||
impl Layout<TuiOut> for RepeatV<'_> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
to
|
||||
}
|
||||
}
|
||||
impl Layout<TuiOut> for RepeatV<'_> {}
|
||||
impl Draw<TuiOut> for RepeatV<'_> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let [x, y, _w, h] = to.area().xywh();
|
||||
|
|
@ -40,11 +31,7 @@ impl Draw<TuiOut> for RepeatV<'_> {
|
|||
}
|
||||
|
||||
pub struct RepeatH<'a>(pub &'a str);
|
||||
impl Layout<TuiOut> for RepeatH<'_> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
to
|
||||
}
|
||||
}
|
||||
impl Layout<TuiOut> for RepeatH<'_> {}
|
||||
impl Draw<TuiOut> for RepeatH<'_> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
let [x, y, w, _h] = to.area().xywh();
|
||||
|
|
|
|||
|
|
@ -1,18 +1,12 @@
|
|||
use crate::*;
|
||||
use crate::ratatui::prelude::Position;
|
||||
use unicode_width::{UnicodeWidthStr, UnicodeWidthChar};
|
||||
|
||||
tui_layout!(|self: &str, to|to.center_xy([width_chars_max(to.w(), self), 1]));
|
||||
tui_draw!(|self: &str, to|{
|
||||
let [x, y, w, ..] = self.layout(to.area());
|
||||
to.text(&self, x, y, w)
|
||||
});
|
||||
|
||||
tui_layout!(|self: Arc<str>, to|self.as_ref().layout(to));
|
||||
tui_draw!(|self: Arc<str>, to|self.as_ref().draw(to));
|
||||
|
||||
tui_layout!(|self: String, to|self.as_str().layout(to));
|
||||
tui_draw!(|self: String, to|self.as_str().draw(to));
|
||||
impl Layout<TuiOut> for &str { fn layout (&self, to: [u16;4]) -> [u16;4] { to.center_xy([width_chars_max(to.w(), self), 1]) } }
|
||||
impl Draw<TuiOut> for &str { fn draw (&self, to: &mut TuiOut) { let [x, y, w, ..] = self.layout(to.area()); to.text(&self, x, y, w) } }
|
||||
impl Layout<TuiOut> for String { fn layout (&self, to: [u16;4]) -> [u16;4] { self.as_str().layout(to) } }
|
||||
impl Draw<TuiOut> for String { fn draw (&self, to: &mut TuiOut) { self.as_str().draw(to) } }
|
||||
impl Layout<TuiOut> for Arc<str> { fn layout (&self, to: [u16;4]) -> [u16;4] { self.as_ref().layout(to) } }
|
||||
impl Draw<TuiOut> for Arc<str> { fn draw (&self, to: &mut TuiOut) { self.as_ref().draw(to) } }
|
||||
|
||||
fn width_chars_max (max: u16, text: impl AsRef<str>) -> u16 {
|
||||
let mut width: u16 = 0;
|
||||
|
|
@ -48,19 +42,13 @@ pub fn trim_string (max_width: usize, input: impl AsRef<str>) -> String {
|
|||
pub struct TrimString<T: AsRef<str>>(pub u16, pub T);
|
||||
|
||||
impl<'a, T: AsRef<str>> TrimString<T> {
|
||||
fn as_ref (&self) -> TrimStringRef<'_, T> {
|
||||
TrimStringRef(self.0, &self.1)
|
||||
}
|
||||
}
|
||||
impl<'a, T: AsRef<str>> Layout<TuiOut> for TrimString<T> {
|
||||
fn layout (&self, to: [u16; 4]) -> [u16;4] {
|
||||
Layout::layout(&self.as_ref(), to)
|
||||
}
|
||||
fn as_ref (&self) -> TrimStringRef<'_, T> { TrimStringRef(self.0, &self.1) }
|
||||
}
|
||||
impl<'a, T: AsRef<str>> Draw<TuiOut> for TrimString<T> {
|
||||
fn draw (&self, to: &mut TuiOut) {
|
||||
Draw::draw(&self.as_ref(), to)
|
||||
}
|
||||
fn draw (&self, to: &mut TuiOut) { Draw::draw(&self.as_ref(), to) }
|
||||
}
|
||||
impl<'a, T: AsRef<str>> Layout<TuiOut> for TrimString<T> {
|
||||
fn layout (&self, to: [u16; 4]) -> [u16;4] { Layout::layout(&self.as_ref(), to) }
|
||||
}
|
||||
|
||||
/// Displays a borrowed [str]-like with fixed maximum width
|
||||
|
|
@ -68,7 +56,7 @@ impl<'a, T: AsRef<str>> Draw<TuiOut> for TrimString<T> {
|
|||
/// Width is computed using [unicode_width].
|
||||
pub struct TrimStringRef<'a, T: AsRef<str>>(pub u16, pub &'a T);
|
||||
|
||||
impl<T: AsRef<str>> Layout<TuiOut> for TrimStringRef<'_, T> {
|
||||
impl<'a, T: AsRef<str>> Layout<TuiOut> for TrimStringRef<'a, T> {
|
||||
fn layout (&self, to: [u16; 4]) -> [u16;4] {
|
||||
[to.x(), to.y(), to.w().min(self.0).min(self.1.as_ref().width() as u16), to.h()]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,28 @@
|
|||
use crate::*;
|
||||
|
||||
impl<
|
||||
A: Draw<TuiOut> + Layout<TuiOut>,
|
||||
B: Draw<TuiOut> + Layout<TuiOut>,
|
||||
C: Draw<TuiOut> + Layout<TuiOut>,
|
||||
> Content<TuiOut> for Tryptich<A, B, C> {
|
||||
fn content (&self) -> impl Draw<TuiOut> + Layout<TuiOut> + '_ {
|
||||
A: Content<TuiOut>,
|
||||
B: Content<TuiOut>,
|
||||
C: Content<TuiOut>,
|
||||
> HasContent<TuiOut> for Tryptich<A, B, C> {
|
||||
fn content (&self) -> impl Content<TuiOut> {
|
||||
let Self { top, h, left: (w_a, ref a), middle: (w_b, ref b), right: (w_c, ref c) } = *self;
|
||||
Fixed::y(h, if top {
|
||||
Fixed::Y(h, if top {
|
||||
Bsp::a(
|
||||
Fill::x(Align::n(Fixed::x(w_b, Align::x(Tui::bg(Color::Reset, b))))),
|
||||
Fill::X(Align::n(Fixed::X(w_b, Align::x(Tui::bg(Color::Reset, b))))),
|
||||
Bsp::a(
|
||||
Fill::x(Align::nw(Fixed::x(w_a, Tui::bg(Color::Reset, a)))),
|
||||
Fill::x(Align::ne(Fixed::x(w_c, Tui::bg(Color::Reset, c)))),
|
||||
Fill::X(Align::nw(Fixed::X(w_a, Tui::bg(Color::Reset, a)))),
|
||||
Fill::X(Align::ne(Fixed::X(w_c, Tui::bg(Color::Reset, c)))),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
Bsp::a(
|
||||
Fill::xy(Align::c(Fixed::x(w_b, Align::x(Tui::bg(Color::Reset, b))))),
|
||||
Fill::XY(Align::c(Fixed::X(w_b, Align::x(Tui::bg(Color::Reset, b))))),
|
||||
Bsp::a(
|
||||
Fill::xy(Align::w(Fixed::x(w_a, Tui::bg(Color::Reset, a)))),
|
||||
Fill::xy(Align::e(Fixed::x(w_c, Tui::bg(Color::Reset, c)))),
|
||||
Fill::XY(Align::w(Fixed::X(w_a, Tui::bg(Color::Reset, a)))),
|
||||
Fill::XY(Align::e(Fixed::X(w_c, Tui::bg(Color::Reset, c)))),
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@ impl Out for TuiOut {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Layout<TuiOut> for fn(&mut TuiOut) {}
|
||||
|
||||
impl TuiOut {
|
||||
/// Spawn the output thread.
|
||||
pub fn run_output <T: Draw<TuiOut> + Send + Sync + 'static> (
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::*;
|
|||
//use std::sync::{Arc, RwLock};
|
||||
struct TestComponent(String);
|
||||
impl Content<TuiOut> for TestComponent {
|
||||
fn content (&self) -> impl Draw<TuiOut> + Layout<TuiOut> {
|
||||
fn content (&self) -> impl Draw<TuiOut> {
|
||||
Some(self.0.as_str())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue