Fix init order of generated C++ code

Like in commit 625eb733d3 for the
interpreter, call `set_component` on the Window before running the setup
code that might set the focus_item.
This commit is contained in:
Simon Hausmann 2021-04-06 13:42:09 +02:00
parent 625eb733d3
commit bd79bb6ac8

View file

@ -931,10 +931,7 @@ fn generate_component(
Declaration::Function(Function {
name: "show".into(),
signature: "() const".into(),
statements: Some(vec![
"window.set_component(**self_weak.lock());".into(),
"window.show();".into(),
]),
statements: Some(vec!["window.show();".into()]),
..Default::default()
}),
));
@ -955,7 +952,6 @@ fn generate_component(
name: "run".into(),
signature: "() const".into(),
statements: Some(vec![
"window.set_component(**self_weak.lock());".into(),
"show();".into(),
"sixtyfps::run_event_loop();".into(),
"hide();".into(),
@ -976,6 +972,7 @@ fn generate_component(
format!("auto self_rc = vtable::VRc<sixtyfps::private_api::ComponentVTable, {0}>::make({1});", component_id, maybe_constructor_param),
format!("auto self = const_cast<{0} *>(&*self_rc);", component_id),
"self->self_weak = vtable::VWeak(self_rc);".into(),
"window.set_component(**self_weak.lock());".into(),
];
create_code.extend(
component.setup_code.borrow().iter().map(|code| compile_expression(code, component)),