1use crate::tree::{LayoutRect, NodeId};
4use astrelis_core::alloc::HashMap;
5
6#[derive(Debug, Clone, Default)]
8pub struct LayoutCache {
9 layouts: HashMap<NodeId, LayoutRect>,
10}
11
12impl LayoutCache {
13 pub fn new() -> Self {
15 Self {
16 layouts: HashMap::new(),
17 }
18 }
19
20 pub fn set(&mut self, node_id: NodeId, layout: LayoutRect) {
22 self.layouts.insert(node_id, layout);
23 }
24
25 pub fn get(&self, node_id: NodeId) -> Option<&LayoutRect> {
27 self.layouts.get(&node_id)
28 }
29
30 pub fn contains(&self, node_id: NodeId) -> bool {
32 self.layouts.contains_key(&node_id)
33 }
34
35 pub fn clear(&mut self) {
37 self.layouts.clear();
38 }
39
40 pub fn len(&self) -> usize {
42 self.layouts.len()
43 }
44
45 pub fn is_empty(&self) -> bool {
47 self.layouts.is_empty()
48 }
49}