mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 21:04:47 +00:00
46 lines
1.8 KiB
Rust
46 lines
1.8 KiB
Rust
/* LICENSE BEGIN
|
|
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
|
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
|
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
|
|
|
SPDX-License-Identifier: GPL-3.0-only
|
|
This file is also available under commercial licensing terms.
|
|
Please contact info@sixtyfps.io for more information.
|
|
LICENSE END */
|
|
//! After inlining and moving declarations, all Element::base_type should be Type::BuiltinElement. This pass resolves them
|
|
// to NativeClass and picking a variant that only contains the used properties.
|
|
|
|
use crate::object_tree::{recurse_elem, Component};
|
|
use crate::typeregister::Type;
|
|
|
|
pub fn resolve_native_classes(component: &Component) {
|
|
recurse_elem(&component.root_element, &(), &mut |elem, _| {
|
|
let new_native_class = {
|
|
let elem = elem.borrow();
|
|
|
|
let base_type = match &elem.base_type {
|
|
Type::Component(comp) => {
|
|
// Components at this point must be for example repeaters. Recurse.
|
|
resolve_native_classes(&comp);
|
|
return;
|
|
}
|
|
Type::Builtin(b) => b,
|
|
_ => panic!("This should not happen because of inlining"),
|
|
};
|
|
|
|
let native_properties_used = elem.bindings.keys().filter(|k| {
|
|
if elem.property_declarations.contains_key(*k) {
|
|
return false;
|
|
}
|
|
|
|
base_type.as_ref().properties.get(*k).is_some()
|
|
});
|
|
|
|
let current_native_class = elem.base_type.as_builtin().native_class.clone();
|
|
current_native_class
|
|
.select_minimal_class_based_on_property_usage(native_properties_used)
|
|
};
|
|
|
|
elem.borrow_mut().base_type = Type::Native(new_native_class);
|
|
})
|
|
}
|