Generate an init function for sub-components

This allows something like this:

```
SubCompo := Rectangle {
    background: green;
}
App := Window {
    SubCompo {}
}
```
This commit is contained in:
Simon Hausmann 2021-11-05 10:10:12 +01:00
parent c506e87484
commit 5fa4bc6b70

View file

@ -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!(