vizia_core/layout/
cache.rs1use crate::cache::CachedData;
2use morphorm::Cache;
3
4use crate::prelude::*;
5use bitflags::bitflags;
6
7bitflags! {
8 #[derive(Debug, Clone, Copy)]
10 pub struct GeoChanged: u8 {
11 const POSX_CHANGED = 1 << 0;
13 const POSY_CHANGED = 1 << 1;
15 const WIDTH_CHANGED = 1 << 2;
17 const HEIGHT_CHANGED = 1 << 3;
19 }
20}
21
22impl Cache for CachedData {
23 type Node = Entity;
24
25 fn set_bounds(&mut self, node: &Self::Node, posx: f32, posy: f32, width: f32, height: f32) {
26 if let Some(bounds) = self.relative_bounds.get_mut(*node) {
27 bounds.x = posx.round();
28 bounds.y = posy.round();
29 bounds.w = width;
30 bounds.h = height;
31 }
32 }
33
34 fn posx(&self, node: &Self::Node) -> f32 {
35 self.relative_bounds.get(*node).map_or(0.0, |b| b.x)
41 }
42
43 fn posy(&self, node: &Self::Node) -> f32 {
44 self.relative_bounds.get(*node).map_or(0.0, |b| b.y)
45 }
46
47 fn width(&self, node: &Self::Node) -> f32 {
48 self.relative_bounds.get(*node).map_or(0.0, |b| b.w)
49 }
50
51 fn height(&self, node: &Self::Node) -> f32 {
52 self.relative_bounds.get(*node).map_or(0.0, |b| b.h)
53 }
54}