mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 04:45:13 +00:00

... so that we have one that controls the embedding operation and one that we can turn into a dynamic tree node where the actual embedding happens. Mark the placeholder Element as `is_component_placeholder` and make sure to not optimize out that object in a later pass. Adapt Element creation to account for the new `is_component_placeholder`.
49 lines
1.7 KiB
Rust
49 lines
1.7 KiB
Rust
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
|
|
|
|
use crate::diagnostics::BuildDiagnostics;
|
|
use crate::langtype::ElementType;
|
|
use crate::object_tree::*;
|
|
use crate::typeregister::TypeRegister;
|
|
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
|
|
pub fn lower_component_container(
|
|
component: &Rc<Component>,
|
|
type_register: &TypeRegister,
|
|
diag: &mut BuildDiagnostics,
|
|
) {
|
|
let empty_type = type_register.empty_type();
|
|
|
|
recurse_elem_including_sub_components_no_borrow(component, &None, &mut |elem, _| {
|
|
if matches!(&elem.borrow().builtin_type(), Some(b) if b.name == "ComponentContainer") {
|
|
diagnose_component_container(elem, diag);
|
|
process_component_container(elem, &empty_type);
|
|
}
|
|
Some(elem.clone())
|
|
})
|
|
}
|
|
|
|
fn diagnose_component_container(element: &ElementRc, diag: &mut BuildDiagnostics) {
|
|
if !element.borrow().children.is_empty() {
|
|
diag.push_error("ComponentContainers may not have children".into(), &*element.borrow());
|
|
return;
|
|
}
|
|
}
|
|
|
|
fn process_component_container(element: &ElementRc, empty_type: &ElementType) {
|
|
let mut elem = element.borrow_mut();
|
|
|
|
let new = Rc::new(RefCell::new(Element {
|
|
base_type: empty_type.clone(),
|
|
id: elem.id.clone(),
|
|
node: elem.node.clone(),
|
|
enclosing_component: elem.enclosing_component.clone(),
|
|
default_fill_parent: (true, true),
|
|
is_legacy_syntax: elem.is_legacy_syntax,
|
|
inline_depth: elem.inline_depth,
|
|
is_component_placeholder: true,
|
|
..Default::default()
|
|
}));
|
|
elem.children.push(new);
|
|
}
|