slint/internal/compiler/passes/lower_component_container.rs
Olivier Goffart 975abf3c42 Don't steal the x and y properties for dummy parents
Parents surch as Opacity, Clip, and co, used to steal the x and y
property of their children, making the property not what they ought to
be.

Now that we refactored recently the code so that geometry need not to be
always linked to a property of the same name, we can dissociate the x
and y property of these generated elements and their content so that the
actual "x" property of the former elementstay some value, despite its
relative item property is now 0.

Had to change a bit of code that was still assuming a literal "height"
or "width" or "y" or "x" property that no longer worked when the
geometry is dissociated from its property

Fix #1072
2023-10-21 07:30:46 +02:00

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::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 embedded_element = Element::make_rc(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(embedded_element);
}