1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#[macro_export] macro_rules! create_web_container { ($name:ident) => { use std::any::Any; use std::cell::RefCell; use std::rc::Rc; pub struct $name { pub parent: WeakNodeRc, pub self_substitute: Option<WeakNodeRc>, pub child: Option<NodeRc>, pub sibling: Option<NodeRc>, pub widget: web_sys::Element, } impl_drop_for_web_node!($name); }; } #[macro_export] macro_rules! impl_web_container { ($name:ident $element_name:literal) => { impl Node for $name { impl_node_as_any!(); impl_node_trait_init_sibling!(); impl_node_trait_init_child!(); impl_node_trait_get_widget!(); impl_node_trait_get_sibling!(); impl_node_trait_get_child!(); impl_node_trait_substitute!(); impl_add_for_web_node!(); fn new(parent: WeakNodeRc) -> NodeRc { let this: NodeRc = Rc::new(RefCell::new(Box::new(Self { parent, self_substitute: None, child: None, sibling: None, widget: { let window = web_sys::window().unwrap(); let document = window.document().unwrap(); document.create_element($element_name).unwrap() }, }))); { let mut this_borrow = this.as_ref().borrow_mut(); this_borrow.set_self_substitute(this.clone()); } this } } impl GlobalAttributes for $name {} }; }