tek/src/view/table.rs
2024-07-09 12:47:53 +03:00

34 lines
747 B
Rust

use crate::core::*;
pub struct Cell<T> {
text: String,
style: Option<Style>,
width: u16,
height: u16,
data: T
}
impl<T> Cell<T> {
pub fn new (text: &str, data: T) -> Self {
Self { text: text.to_string(), style: None, width: text.len() as u16, height: 1, data }
}
pub fn draw (&self, buf: &mut Buffer, x: u16, y: u16) {
self.text.blit(buf, x, y, self.style)
}
}
pub struct Table<T> {
columns: Vec<Vec<Cell<T>>>,
row: usize,
col: usize,
}
impl<T> Table<T> {
pub fn new (columns: Vec<Vec<Cell<T>>>) -> Self {
Self { columns, row: 0, col: 0 }
}
pub fn set (&mut self, col: usize, row: usize, cell: Cell<T>) {
self.columns[col][row] = cell;
}
}