| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | //! Passe that collects the code from init callbacks from elements and moves it into the component's init_code. |
| 5 | |
| 6 | use std::rc::Rc; |
| 7 | |
| 8 | use crate::langtype::ElementType; |
| 9 | use crate::object_tree::{recurse_elem, Component}; |
| 10 | |
| 11 | pub fn collect_init_code(component: &Rc<Component>) { |
| 12 | recurse_elem(&component.root_element, &(), &mut |elem: &Rc>, _| { |
| 13 | if elem.borrow().repeated.is_some() { |
| 14 | if let ElementType::Component(base: &Rc) = &elem.borrow().base_type { |
| 15 | if base.parent_element.upgrade().is_some() { |
| 16 | collect_init_code(component:base); |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | if let Some(init_callback: RefCell) = elem.borrow_mut().bindings.remove(key:"init" ) { |
| 22 | componentVec |
| 23 | .init_code |
| 24 | .borrow_mut() |
| 25 | .constructor_code |
| 26 | .push(init_callback.into_inner().expression); |
| 27 | } |
| 28 | }); |
| 29 | for popup: &PopupWindow in component.popup_windows.borrow().iter() { |
| 30 | collect_init_code(&popup.component); |
| 31 | } |
| 32 | } |
| 33 | |