mod document;
use ratatui::text::Line;
use std::collections::HashMap;
pub use document::DocumentWidget;
#[derive(Debug, Default)]
pub struct LayoutCache {
cache: HashMap<(usize, u16), Vec<Line<'static>>>,
last_width: u16,
}
impl LayoutCache {
pub fn new() -> Self {
Self {
cache: HashMap::new(),
last_width: 0,
}
}
pub fn get(&self, element_index: usize, width: u16) -> Option<&Vec<Line<'static>>> {
self.cache.get(&(element_index, width))
}
pub fn insert(&mut self, element_index: usize, width: u16, lines: Vec<Line<'static>>) {
self.cache.insert((element_index, width), lines);
}
pub fn check_width(&mut self, width: u16) {
if width != self.last_width {
self.cache.clear();
self.last_width = width;
}
}
}