1use slotmap::new_key_type;
4
5use crate::scene::container::Container;
6use crate::scene::flex_text::FlexText;
7use crate::scene::graphics::Graphics;
8use crate::scene::mesh::Mesh;
9use crate::scene::sprite::Sprite;
10use crate::scene::text::Text;
11
12new_key_type! {
13 pub struct NodeId;
15}
16
17#[derive(Debug, Clone)]
19pub enum Node {
20 Container(Container),
22 Sprite(Sprite),
24 Graphics(Graphics),
26 Text(Text),
28 FlexText(FlexText),
33 Mesh(Mesh),
35}
36
37impl Node {
38 #[must_use]
41 pub fn container(&self) -> &Container {
42 match self {
43 Self::Container(c) => c,
44 Self::Sprite(s) => &s.container,
45 Self::Graphics(g) => &g.container,
46 Self::Text(t) => &t.container,
47 Self::FlexText(f) => &f.container,
48 Self::Mesh(m) => &m.container,
49 }
50 }
51
52 pub fn container_mut(&mut self) -> &mut Container {
54 match self {
55 Self::Container(c) => c,
56 Self::Sprite(s) => &mut s.container,
57 Self::Graphics(g) => &mut g.container,
58 Self::Text(t) => &mut t.container,
59 Self::FlexText(f) => &mut f.container,
60 Self::Mesh(m) => &mut m.container,
61 }
62 }
63}
64
65impl From<Container> for Node {
66 fn from(c: Container) -> Self {
67 Self::Container(c)
68 }
69}
70
71impl From<Sprite> for Node {
72 fn from(s: Sprite) -> Self {
73 Self::Sprite(s)
74 }
75}
76
77impl From<Graphics> for Node {
78 fn from(g: Graphics) -> Self {
79 Self::Graphics(g)
80 }
81}
82
83impl From<Text> for Node {
84 fn from(t: Text) -> Self {
85 Self::Text(t)
86 }
87}
88
89impl From<FlexText> for Node {
90 fn from(f: FlexText) -> Self {
91 Self::FlexText(f)
92 }
93}
94
95impl From<Mesh> for Node {
96 fn from(m: Mesh) -> Self {
97 Self::Mesh(m)
98 }
99}