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