use crate::tree::{LayoutRect, NodeId};
use astrelis_core::alloc::HashMap;
#[derive(Debug, Clone, Default)]
pub struct LayoutCache {
layouts: HashMap<NodeId, LayoutRect>,
}
impl LayoutCache {
pub fn new() -> Self {
Self {
layouts: HashMap::new(),
}
}
pub fn set(&mut self, node_id: NodeId, layout: LayoutRect) {
self.layouts.insert(node_id, layout);
}
pub fn get(&self, node_id: NodeId) -> Option<&LayoutRect> {
self.layouts.get(&node_id)
}
pub fn contains(&self, node_id: NodeId) -> bool {
self.layouts.contains_key(&node_id)
}
pub fn clear(&mut self) {
self.layouts.clear();
}
pub fn len(&self) -> usize {
self.layouts.len()
}
pub fn is_empty(&self) -> bool {
self.layouts.is_empty()
}
}