mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 06:41:14 +00:00
Generate an init function for sub-components
This allows something like this: ``` SubCompo := Rectangle { background: green; } App := Window { SubCompo {} } ```
This commit is contained in:
parent
c506e87484
commit
5fa4bc6b70
1 changed files with 11 additions and 3 deletions
|
@ -543,6 +543,9 @@ fn generate_component(
|
||||||
let field_name = ident(&item.id);
|
let field_name = ident(&item.id);
|
||||||
let sub_component_id = self::inner_component_id(sub_component);
|
let sub_component_id = self::inner_component_id(sub_component);
|
||||||
|
|
||||||
|
// TODO: Use VRcMapped::map for sub-components
|
||||||
|
self.init.push(quote!(#sub_component_id::init(VRc::map(self_rc.clone(), |self_| Self::FIELD_OFFSETS.#field_name.apply_pin(self_)));));
|
||||||
|
|
||||||
self.sub_component_names.push(field_name);
|
self.sub_component_names.push(field_name);
|
||||||
self.sub_component_initializers.push(quote!(#sub_component_id::new()));
|
self.sub_component_initializers.push(quote!(#sub_component_id::new()));
|
||||||
self.sub_component_types.push(sub_component_id);
|
self.sub_component_types.push(sub_component_id);
|
||||||
|
@ -1063,6 +1066,11 @@ fn generate_component(
|
||||||
#create_self
|
#create_self
|
||||||
self_
|
self_
|
||||||
}
|
}
|
||||||
|
pub fn init(self_rc: sixtyfps::re_exports::VRcMapped<sixtyfps::re_exports::ComponentVTable, Self>) {
|
||||||
|
#![allow(unused)]
|
||||||
|
let _self = self_rc.as_pin_ref();
|
||||||
|
#(#init)*
|
||||||
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
quote!(
|
quote!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue