Get rid of abi::datastructures::WindowProperties

Instead, pass a reference to the root item when mapping the window,
at which point we can downcast to the new Window item. If we have one,
then we'll read its width/height (for initial values) and install
bindings to keep them up-to-date.
This commit is contained in:
Simon Hausmann 2020-08-11 16:05:16 +02:00
parent 3d5d112deb
commit aafb96cb93
14 changed files with 150 additions and 116 deletions

View file

@ -642,24 +642,16 @@ fn generate_component(
}),
));
let window_props = |name| {
let root_elem = component.root_element.borrow();
if root_elem.lookup_property(name) == Type::Length {
format!("&this->{}.{}", root_elem.id, name)
} else {
"nullptr".to_owned()
}
};
let root_elem = component.root_element.borrow();
component_struct.members.push((
Access::Public,
Declaration::Function(Function {
name: "window_properties".into(),
signature: "() -> sixtyfps::WindowProperties".into(),
name: "root_item".into(),
signature: "() -> VRef<sixtyfps::internal::ItemVTable>".into(),
statements: Some(vec![format!(
"return {{ {} , {} }};",
window_props("width"),
window_props("height")
"return {{ &sixtyfps::{vt}, &this->{id} }};",
vt = root_elem.base_type.as_native().vtable_symbol,
id = root_elem.id
)]),
..Default::default()
}),

View file

@ -373,26 +373,14 @@ fn generate_component(
// FIXME: This field is public for testing.
maybe_window_field_decl.push(quote!(pub window: sixtyfps::re_exports::ComponentWindow));
maybe_window_field_init.push(quote!(window: sixtyfps::create_window()));
let window_props = |name| {
let root_elem = component.root_element.borrow();
if root_elem.lookup_property(name) == Type::Length {
let root_item_name = quote::format_ident!("{}", root_elem.id);
let root_item_ty =
quote::format_ident!("{}", root_elem.base_type.as_native().class_name);
let name = quote::format_ident!("{}", name);
quote!(Some((Self::FIELD_OFFSETS.#root_item_name + #root_item_ty::FIELD_OFFSETS.#name).apply_pin(self.as_ref())))
} else {
quote!(None)
}
};
let width_prop = window_props("width");
let height_prop = window_props("height");
let root_elem = component.root_element.borrow();
let root_item_name = quote::format_ident!("{}", root_elem.id);
property_and_signal_accessors.push(quote! {
pub fn run(self : core::pin::Pin<std::rc::Rc<Self>>) {
use sixtyfps::re_exports::*;
let window_props = WindowProperties {width: #width_prop, height: #height_prop};
self.as_ref().window.run(VRef::new_pin(self.as_ref()), &window_props);
let root_item = Self::FIELD_OFFSETS.#root_item_name.apply_pin(self.as_ref());
self.as_ref().window.run(VRef::new_pin(self.as_ref()), VRef::new_pin(root_item));
}
});
property_and_signal_accessors.push(quote! {

View file

@ -534,6 +534,8 @@ impl TypeRegister {
],
);
native_class(&mut r, "Window", &[("width", Type::Length), ("height", Type::Length)]);
let mut grid_layout = BuiltinElement::new(Rc::new(NativeClass::new("GridLayout")));
grid_layout.properties.insert("spacing".to_owned(), Type::Length);