mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
feat(tui): add Tryptich (3-col layout)
This commit is contained in:
parent
3861439c49
commit
91dfed1077
3 changed files with 68 additions and 9 deletions
|
|
@ -1,3 +1,5 @@
|
|||
#![feature(type_changing_struct_update)]
|
||||
|
||||
mod tui_engine; pub use self::tui_engine::*;
|
||||
mod tui_content; pub use self::tui_content::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -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_color; pub use self::tui_color::*;
|
||||
mod tui_field; pub use self::tui_field::*;
|
||||
mod tui_file; pub use self::tui_file::*;
|
||||
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_style; pub use self::tui_style::*;
|
||||
mod tui_border; pub use self::tui_border::*;
|
||||
mod tui_color; pub use self::tui_color::*;
|
||||
mod tui_field; pub use self::tui_field::*;
|
||||
mod tui_file; pub use self::tui_file::*;
|
||||
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_style; pub use self::tui_style::*;
|
||||
mod tui_tryptich; pub use self::tui_tryptich::*;
|
||||
|
|
|
|||
56
tui/src/tui_content/tui_tryptich.rs
Normal file
56
tui/src/tui_content/tui_tryptich.rs
Normal 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)))),
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue