slint/internal/compiler/passes/collect_init_code.rs
Aurindam Jana 0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00

32 lines
1.1 KiB
Rust

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial
//! Passe that collects the code from init callbacks from elements and moves it into the component's init_code.
use std::rc::Rc;
use crate::langtype::ElementType;
use crate::object_tree::{recurse_elem, Component};
pub fn collect_init_code(component: &Rc<Component>) {
recurse_elem(&component.root_element, &(), &mut |elem, _| {
if elem.borrow().repeated.is_some() {
if let ElementType::Component(base) = &elem.borrow().base_type {
if base.parent_element.upgrade().is_some() {
collect_init_code(base);
}
}
}
if let Some(init_callback) = elem.borrow_mut().bindings.remove("init") {
component
.init_code
.borrow_mut()
.constructor_code
.push(init_callback.into_inner().expression);
}
});
for popup in component.popup_windows.borrow().iter() {
collect_init_code(&popup.component);
}
}