1use crate::mark::{Mark, MarkBatch, MarkKey};
5use crate::transform::Affine2D;
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
9pub struct NodeId {
10 pub index: u32,
12 pub generation: u32,
14}
15
16pub enum NodeContent {
18 Container,
20 Mark(Mark),
22 Batch(MarkBatch),
24}
25
26pub struct Node {
28 pub parent: Option<NodeId>,
30 pub children: Vec<NodeId>,
32 pub transform: Affine2D,
34 pub clip: bool,
36 pub z_order: i32,
38 pub opacity: f32,
40 pub content: NodeContent,
42 pub key: Option<MarkKey>,
44}
45
46impl Node {
47 pub fn container() -> Self {
49 Self {
50 parent: None,
51 children: Vec::new(),
52 transform: Affine2D::IDENTITY,
53 clip: false,
54 z_order: 0,
55 opacity: 1.0,
56 content: NodeContent::Container,
57 key: None,
58 }
59 }
60
61 pub fn with_mark(mark: Mark) -> Self {
63 Self {
64 parent: None,
65 children: Vec::new(),
66 transform: Affine2D::IDENTITY,
67 clip: false,
68 z_order: 0,
69 opacity: 1.0,
70 content: NodeContent::Mark(mark),
71 key: None,
72 }
73 }
74
75 pub fn with_batch(batch: MarkBatch) -> Self {
77 Self {
78 parent: None,
79 children: Vec::new(),
80 transform: Affine2D::IDENTITY,
81 clip: false,
82 z_order: 0,
83 opacity: 1.0,
84 content: NodeContent::Batch(batch),
85 key: None,
86 }
87 }
88
89 pub fn transform(mut self, t: Affine2D) -> Self {
91 self.transform = t;
92 self
93 }
94
95 pub fn z_order(mut self, z: i32) -> Self {
97 self.z_order = z;
98 self
99 }
100
101 pub fn key(mut self, k: MarkKey) -> Self {
103 self.key = Some(k);
104 self
105 }
106}