refactor: extract more tui_content modules

This commit is contained in:
🪞👃🪞 2025-04-04 20:59:17 +03:00
parent 86236b76cd
commit ea01deb854
6 changed files with 192 additions and 183 deletions

View file

@ -0,0 +1,45 @@
use crate::*;
use ratatui::prelude::Position;
pub struct Repeat<'a>(pub &'a str);
impl Content<TuiOut> for Repeat<'_> {
fn layout (&self, to: [u16;4]) -> [u16;4] { to }
fn render (&self, to: &mut TuiOut) {
let [x, y, w, h] = to.area().xywh();
let a = self.0.len();
for (_v, y) in (y..y+h).enumerate() {
for (u, x) in (x..x+w).enumerate() {
if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) {
let u = u % a;
cell.set_symbol(&self.0[u..u+1]);
}
}
}
}
}
pub struct RepeatV<'a>(pub &'a str);
impl Content<TuiOut> for RepeatV<'_> {
fn layout (&self, to: [u16;4]) -> [u16;4] { to }
fn render (&self, to: &mut TuiOut) {
let [x, y, _w, h] = to.area().xywh();
for y in y..y+h {
if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) {
cell.set_symbol(&self.0);
}
}
}
}
pub struct RepeatH<'a>(pub &'a str);
impl Content<TuiOut> for RepeatH<'_> {
fn layout (&self, to: [u16;4]) -> [u16;4] { to }
fn render (&self, to: &mut TuiOut) {
let [x, y, w, _h] = to.area().xywh();
for x in x..x+w {
if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) {
cell.set_symbol(&self.0);
}
}
}
}