mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
71 lines
1.9 KiB
Rust
71 lines
1.9 KiB
Rust
use crate::*;
|
|
|
|
impl Content<TuiOut> for &str {
|
|
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
|
to.center_xy([self.chars().count() as u16, 1])
|
|
}
|
|
fn render (&self, to: &mut TuiOut) {
|
|
to.blit(self, to.area.x(), to.area.y(), None)
|
|
}
|
|
}
|
|
|
|
impl Content<TuiOut> for String {
|
|
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
|
to.center_xy([self.chars().count() as u16, 1])
|
|
}
|
|
fn render (&self, to: &mut TuiOut) {
|
|
to.blit(self, to.area.x(), to.area.y(), None)
|
|
}
|
|
}
|
|
|
|
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(ratatui::prelude::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(ratatui::prelude::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(ratatui::prelude::Position::from((x, y))) {
|
|
cell.set_symbol(&self.0);
|
|
}
|
|
}
|
|
}
|
|
}
|