mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
refactor: extract more tui_content modules
This commit is contained in:
parent
86236b76cd
commit
ea01deb854
6 changed files with 192 additions and 183 deletions
29
tui/src/tui_content/tui_phat.rs
Normal file
29
tui/src/tui_content/tui_phat.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use crate::*;
|
||||
|
||||
/// A cell that takes up 3 rows on its own,
|
||||
/// but stacks, giving (N+1)*2 rows per N cells.
|
||||
pub struct Phat<T> {
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
pub content: T,
|
||||
pub colors: [Color;4],
|
||||
}
|
||||
impl<T> Phat<T> {
|
||||
/// A phat line
|
||||
pub fn lo (fg: Color, bg: Color) -> impl Content<TuiOut> {
|
||||
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&"▄")))
|
||||
}
|
||||
/// A phat line
|
||||
pub fn hi (fg: Color, bg: Color) -> impl Content<TuiOut> {
|
||||
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&"▀")))
|
||||
}
|
||||
}
|
||||
impl<T: Content<TuiOut>> Content<TuiOut> for Phat<T> {
|
||||
fn content (&self) -> impl Render<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 content = Tui::fg_bg(fg, bg, &self.content);
|
||||
Min::xy(self.width, self.height, Bsp::s(top, Bsp::n(low, Fill::xy(content))))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue