1use crate::style::Style;
5use crate::tree::Cache;
6use crate::tree::Layout;
7
8#[cfg(feature = "taffy_tree")]
9use slotmap::{DefaultKey, Key, KeyData};
10
11#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
16pub struct NodeId(u64);
17impl NodeId {
18 pub const fn new(val: u64) -> Self {
20 Self(val)
21 }
22}
23
24impl From<u64> for NodeId {
25 #[inline]
26 fn from(raw: u64) -> Self {
27 Self(raw)
28 }
29}
30impl From<NodeId> for u64 {
31 #[inline]
32 fn from(id: NodeId) -> Self {
33 id.0
34 }
35}
36impl From<usize> for NodeId {
37 #[inline]
38 fn from(raw: usize) -> Self {
39 Self(raw as u64)
40 }
41}
42impl From<NodeId> for usize {
43 #[inline]
44 fn from(id: NodeId) -> Self {
45 id.0 as usize
46 }
47}
48
49#[cfg(feature = "taffy_tree")]
50impl From<DefaultKey> for NodeId {
51 #[inline]
52 fn from(key: DefaultKey) -> Self {
53 Self(key.data().as_ffi())
54 }
55}
56
57#[cfg(feature = "taffy_tree")]
58impl From<NodeId> for DefaultKey {
59 #[inline]
60 fn from(key: NodeId) -> Self {
61 KeyData::from_ffi(key.0).into()
62 }
63}
64
65pub(crate) struct NodeData {
69 pub(crate) style: Style,
71
72 pub(crate) unrounded_layout: Layout,
75
76 pub(crate) final_layout: Layout,
79
80 pub(crate) needs_measure: bool,
82
83 pub(crate) cache: Cache,
85}
86
87impl NodeData {
88 #[must_use]
90 pub const fn new(style: Style) -> Self {
91 Self {
92 style,
93 cache: Cache::new(),
94 unrounded_layout: Layout::new(),
95 final_layout: Layout::new(),
96 needs_measure: false,
97 }
98 }
99
100 #[inline]
104 pub fn mark_dirty(&mut self) {
105 self.cache.clear()
106 }
107}