use crate::mark::{Mark, MarkBatch, MarkKey};
use crate::transform::Affine2D;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct NodeId {
pub index: u32,
pub generation: u32,
}
pub enum NodeContent {
Container,
Mark(Mark),
Batch(MarkBatch),
}
pub struct Node {
pub parent: Option<NodeId>,
pub children: Vec<NodeId>,
pub transform: Affine2D,
pub clip: bool,
pub z_order: i32,
pub opacity: f32,
pub content: NodeContent,
pub key: Option<MarkKey>,
}
impl Node {
pub fn container() -> Self {
Self {
parent: None,
children: Vec::new(),
transform: Affine2D::IDENTITY,
clip: false,
z_order: 0,
opacity: 1.0,
content: NodeContent::Container,
key: None,
}
}
pub fn with_mark(mark: Mark) -> Self {
Self {
parent: None,
children: Vec::new(),
transform: Affine2D::IDENTITY,
clip: false,
z_order: 0,
opacity: 1.0,
content: NodeContent::Mark(mark),
key: None,
}
}
pub fn with_batch(batch: MarkBatch) -> Self {
Self {
parent: None,
children: Vec::new(),
transform: Affine2D::IDENTITY,
clip: false,
z_order: 0,
opacity: 1.0,
content: NodeContent::Batch(batch),
key: None,
}
}
pub fn transform(mut self, t: Affine2D) -> Self {
self.transform = t;
self
}
pub fn z_order(mut self, z: i32) -> Self {
self.z_order = z;
self
}
pub fn key(mut self, k: MarkKey) -> Self {
self.key = Some(k);
self
}
}