use crate::internal_prelude::*;
crate::use_behaviors!(sandbox_member);
pub struct NodeList {
pub context: SandboxMemberBehaviorStorage,
pub(crate) nodelist_storage: NodeListStorage,
}
impl NodeList {
pub(crate) fn new(context: Weak<Sandbox>, nodelist_storage: NodeListStorage) -> Arc<NodeList> {
Arc::new(NodeList {
context: SandboxMemberBehaviorStorage::new(context),
nodelist_storage,
})
}
pub(crate) fn new_static(context: Weak<Sandbox>, elements: Vec<AnyNodeArc>) -> Arc<NodeList> {
let nodelist_storage = NodeListStorage::Static(elements);
NodeList::new(context, nodelist_storage)
}
pub fn length(&self) -> usize {
match &self.nodelist_storage {
NodeListStorage::Static(list) => list.len(),
NodeListStorage::Live(query) => match query {
Query::ChildNodes { children_of } => {
children_of.common.node_graph.static_child_nodes().len()
}
},
}
}
pub fn item(&self, index: usize) -> Option<AnyNodeArc> {
match &self.nodelist_storage {
NodeListStorage::Static(list) => list.get(index).cloned(),
NodeListStorage::Live(query) => match query {
Query::ChildNodes { children_of } => children_of
.common
.node_graph
.static_child_nodes()
.get(index)
.cloned(),
},
}
}
pub fn get(&self, index: usize) -> Option<AnyNodeArc> {
self.item(index)
}
}
impl_sandbox_member!(NodeList, context);
pub(crate) enum NodeListStorage {
Static(Vec<AnyNodeArc>),
Live(Query),
}
pub(crate) enum Query {
ChildNodes { children_of: AnyNodeArc },
}