use super::xml::{OptionalXmlNodeIndex, XmlTagParameters};
use super::visual::{PixelSource, NodeConfig, Margin, Size, Position};
use oakwood::{Cookie64, tree, index};
use super::event::Handlers;
use crate::{ArcStr, Box};
use core::any::Any;
#[cfg(doc)]
use super::event::Initializer;
index!(MutatorIndex, OptionalMutatorIndex, u16);
index!(StyleIndex, OptionalStyleIndex, u16);
tree!(NodeTree, Node, NodeKey, NodeIndex, OptionalNodeIndex, Cookie64);
#[derive(Debug, Default)]
pub struct Node { pub config: NodeConfig, pub margin: Margin,
pub size: Size, pub position: Position,
pub background: PixelSource, pub foreground: PixelSource,
pub factory: OptionalMutatorIndex, pub style_override: OptionalStyleIndex,
pub xml_node_index: OptionalXmlNodeIndex,
}
pub struct Mutator {
pub name: ArcStr,
pub xml_params: Option<XmlTagParameters>,
pub handlers: Handlers,
pub storage: Option<Box<dyn Any>>,
}
pub fn get_storage<T: Any>(mutators: &mut [Mutator], m: MutatorIndex) -> Option<&mut T> {
mutators[usize::from(m)].storage.as_mut()?.downcast_mut()
}
impl Clone for Mutator {
fn clone(&self) -> Self {
Self {
name: self.name.clone(),
xml_params: self.xml_params.clone(),
handlers: self.handlers.clone(),
storage: match self.storage.is_some() {
true => panic!("Tried to Clone Mutator with an initialized storage"),
false => None,
},
}
}
}