pax_std/core/
import_settings.rs1use std::iter;
2use std::rc::Rc;
3
4use pax_engine::pax;
5use pax_runtime::api::{borrow, use_RefCell, Layer};
6use pax_runtime::{
7 BaseInstance, ExpandedNode, InstanceFlags, InstanceNode, InstantiationArgs, RuntimeContext,
8};
9
10use_RefCell!();
11
12#[pax]
14#[engine_import_path("pax_engine")]
15#[primitive("pax_std::core::import_settings::ImportSettingsInstance")]
16pub struct ImportSettings {}
17
18pub struct ImportSettingsInstance {
19 base: BaseInstance,
20}
21
22impl InstanceNode for ImportSettingsInstance {
23 fn instantiate(args: InstantiationArgs) -> Rc<Self>
24 where
25 Self: Sized,
26 {
27 Rc::new(Self {
28 base: BaseInstance::new(
29 args,
30 InstanceFlags {
31 invisible_to_slot: false,
32 invisible_to_raycasting: true,
33 layer: Layer::DontCare,
34 is_component: false,
35 is_slot: false,
36 },
37 ),
38 })
39 }
40
41 fn handle_mount(
42 self: Rc<Self>,
43 expanded_node: &Rc<ExpandedNode>,
44 context: &Rc<RuntimeContext>,
45 ) {
46 let env = Rc::clone(&expanded_node.stack);
47 let children = borrow!(self.base().get_instance_children());
48 let sidecar_children = expanded_node.create_children_detached(
49 children.iter().cloned().zip(iter::repeat(env)),
50 context,
51 &Rc::downgrade(expanded_node),
52 );
53 let sidecar_children = expanded_node.attach_sidecar_children(
54 sidecar_children,
55 context,
56 &expanded_node.parent_frame,
57 );
58 for child in sidecar_children.iter() {
59 child.recurse_control_flow_expansion(context);
60 }
61 }
62
63 fn handle_unmount(&self, expanded_node: &Rc<ExpandedNode>, context: &Rc<RuntimeContext>) {
64 let sidecar_children = std::mem::take(&mut *expanded_node.sidecar_children.borrow_mut());
65 for child in sidecar_children {
66 child.recurse_unmount(context);
67 }
68 }
69
70 fn resolve_debug(
71 &self,
72 f: &mut std::fmt::Formatter,
73 _expanded_node: Option<&ExpandedNode>,
74 ) -> std::fmt::Result {
75 f.debug_struct("ImportSettings").finish()
76 }
77
78 fn base(&self) -> &BaseInstance {
79 &self.base
80 }
81}