wip: remodularize 2

This commit is contained in:
🪞👃🪞 2025-01-08 19:19:35 +01:00
parent 3b6ff81dad
commit d38dc14e84
27 changed files with 564 additions and 563 deletions

View file

@ -18,6 +18,7 @@ mod tui_style; pub use self::tui_style::*;
mod tui_theme; pub use self::tui_theme::*;
mod tui_border; pub use self::tui_border::*;
mod tui_field; pub use self::tui_field::*;
mod tui_buffer; pub use self::tui_buffer::*;
pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicUsize, AtomicBool, Ordering::*}};
pub(crate) use std::io::{stdout, Stdout};

27
tui/src/tui_buffer.rs Normal file
View file

@ -0,0 +1,27 @@
use crate::*;
#[derive(Default)]
pub struct BigBuffer {
pub width: usize,
pub height: usize,
pub content: Vec<Cell>
}
impl BigBuffer {
pub fn new (width: usize, height: usize) -> Self {
Self { width, height, content: vec![Cell::default(); width*height] }
}
pub fn get (&self, x: usize, y: usize) -> Option<&Cell> {
let i = self.index_of(x, y);
self.content.get(i)
}
pub fn get_mut (&mut self, x: usize, y: usize) -> Option<&mut Cell> {
let i = self.index_of(x, y);
self.content.get_mut(i)
}
pub fn index_of (&self, x: usize, y: usize) -> usize {
y * self.width + x
}
}
from!(|size:(usize, usize)| BigBuffer = Self::new(size.0, size.1));