use std::{cell::RefCell, rc::Rc};
use crate::RuntimeContext;
pub use pax_runtime_api::*;
#[cfg(feature = "designtime")]
use {
crate::api::math::Point2, crate::node_interface::NodeInterface,
pax_designtime::DesigntimeManager, pax_manifest::UniqueTemplateNodeIdentifier,
};
#[derive(Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct NodeContext {
pub frames_elapsed: Property<u64>,
pub bounds_parent: Property<(f64, f64)>,
pub bounds_self: Property<(f64, f64)>,
#[allow(unused)]
pub(crate) runtime_context: Rc<RefCell<RuntimeContext>>,
#[cfg(feature = "designtime")]
pub designtime: Rc<RefCell<DesigntimeManager>>,
}
#[cfg(feature = "designtime")]
impl NodeContext<'_> {
pub fn raycast(&self, point: Point2<Window>) -> Vec<NodeInterface> {
let expanded_nodes = self
.runtime_context
.get_elements_beneath_ray(point, false, vec![]);
expanded_nodes
.into_iter()
.map(Into::<NodeInterface>::into)
.collect()
}
pub fn get_nodes_by_global_id(&self, uni: UniqueTemplateNodeIdentifier) -> Vec<NodeInterface> {
let expanded_nodes = self.runtime_context.get_expanded_nodes_by_global_ids(&uni);
expanded_nodes
.into_iter()
.map(Into::<NodeInterface>::into)
.collect()
}
pub fn get_nodes_by_id(&self, id: &str) -> Vec<NodeInterface> {
let expanded_nodes = self.runtime_context.get_expanded_nodes_by_id(id);
expanded_nodes
.into_iter()
.map(Into::<NodeInterface>::into)
.collect()
}
}