feat(tui): add Tryptich (3-col layout)

This commit is contained in:
🪞👃🪞 2025-04-24 21:03:52 +03:00
parent 3861439c49
commit 91dfed1077
3 changed files with 68 additions and 9 deletions

View file

@ -1,3 +1,5 @@
#![feature(type_changing_struct_update)]
mod tui_engine; pub use self::tui_engine::*; mod tui_engine; pub use self::tui_engine::*;
mod tui_content; pub use self::tui_content::*; mod tui_content; pub use self::tui_content::*;

View file

@ -21,12 +21,13 @@ impl<T: Content<TuiOut>> Content<TuiOut> for std::sync::Arc<T> {
} }
} }
mod tui_border; pub use self::tui_border::*; mod tui_border; pub use self::tui_border::*;
mod tui_color; pub use self::tui_color::*; mod tui_color; pub use self::tui_color::*;
mod tui_field; pub use self::tui_field::*; mod tui_field; pub use self::tui_field::*;
mod tui_file; pub use self::tui_file::*; mod tui_file; pub use self::tui_file::*;
mod tui_phat; pub use self::tui_phat::*; mod tui_phat; pub use self::tui_phat::*;
mod tui_repeat; pub use self::tui_repeat::*; mod tui_repeat; pub use self::tui_repeat::*;
mod tui_scroll; pub use self::tui_scroll::*; mod tui_scroll; pub use self::tui_scroll::*;
mod tui_string; pub use self::tui_string::*; mod tui_string; pub use self::tui_string::*;
mod tui_style; pub use self::tui_style::*; mod tui_style; pub use self::tui_style::*;
mod tui_tryptich; pub use self::tui_tryptich::*;

View file

@ -0,0 +1,56 @@
use crate::*;
/// A three-column layout.
pub struct Tryptich<A, B, C> {
pub top: bool,
pub h: u16,
pub left: (u16, A),
pub middle: (u16, B),
pub right: (u16, C),
}
impl Tryptich<(), (), ()> {
pub fn center (h: u16) -> Self {
Self { h, top: false, left: (0, ()), middle: (0, ()), right: (0, ()) }
}
pub fn top (h: u16) -> Self {
Self { h, top: true, left: (0, ()), middle: (0, ()), right: (0, ()) }
}
}
impl<A, B, C> Tryptich<A, B, C> {
pub fn left <D> (self, w: u16, content: D) -> Tryptich<D, B, C> {
Tryptich { left: (w, content), ..self }
}
pub fn middle <D> (self, w: u16, content: D) -> Tryptich<A, D, C> {
Tryptich { middle: (w, content), ..self }
}
pub fn right <D> (self, w: u16, content: D) -> Tryptich<A, B, D> {
Tryptich { right: (w, content), ..self }
}
}
impl<A, B, C> Content<TuiOut> for Tryptich<A, B, C>
where A: Content<TuiOut>, B: Content<TuiOut>, C: Content<TuiOut> {
fn content (&self) -> impl Render<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 {
Bsp::a(
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)))),
),
)
} else {
Bsp::a(
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)))),
),
)
})
}
}