slint/internal/compiler/passes/collect_subcomponents.rs
Olivier Goffart 12d904a71c
Fix compiler panic with init in a component inlined into a repeater
The problem was that the code from #4322 inlined the init code in the
parent Component as at that point, the per-repeater component don't
exist yet.
Fix it by removing the workaround from #4322, but changing the order of
the passes so that the init code are already proccessed before any
inlining. This required to change the order of a bunch of passes.

Fixes #5146

As a drive-by, also add the missing C++ implementation of set_animated_value
for Brush that was discovered by the test. (Code wouldn't compile)
2024-04-29 15:34:12 +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.2 OR LicenseRef-Slint-commercial
//! Passes that fills the root component used_types.sub_components
use by_address::ByAddress;
use crate::langtype::ElementType;
use crate::object_tree::*;
use std::collections::HashSet;
use std::rc::Rc;
/// Fill the root_component's used_types.sub_components
pub fn collect_subcomponents(root_component: &Rc<Component>) {
let mut result = vec![];
let mut hash = HashSet::new();
collect_subcomponents_recursive(root_component, &mut result, &mut hash);
root_component.used_types.borrow_mut().sub_components = result;
}
fn collect_subcomponents_recursive(
component: &Rc<Component>,
result: &mut Vec<Rc<Component>>,
hash: &mut HashSet<ByAddress<Rc<Component>>>,
) {
hash.insert(ByAddress(component.clone()));
recurse_elem(&component.root_element, &(), &mut |elem: &ElementRc, &()| {
let base_comp = match &elem.borrow().base_type {
ElementType::Component(base_comp) => {
if hash.contains(&ByAddress(base_comp.clone())) {
return;
}
base_comp.clone()
}
_ => return,
};
collect_subcomponents_recursive(&base_comp, result, hash);
if base_comp.parent_element.upgrade().is_some() {
// This is not a sub-component, but is a repeated component
return;
}
result.push(base_comp);
});
for popup in component.popup_windows.borrow().iter() {
collect_subcomponents_recursive(&popup.component, result, hash);
}
}