mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
cleanup: sub 4k again
This commit is contained in:
parent
214061a419
commit
d8c9abf744
13 changed files with 101 additions and 505 deletions
34
src/view/table.rs
Normal file
34
src/view/table.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue