From bd79bb6ac8fa728700f8aa4b017be43b702edfd2 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 6 Apr 2021 13:42:09 +0200 Subject: [PATCH] Fix init order of generated C++ code Like in commit 625eb733d330a21318d78c5fb4ca422911854ef4 for the interpreter, call `set_component` on the Window before running the setup code that might set the focus_item. --- sixtyfps_compiler/generator/cpp.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sixtyfps_compiler/generator/cpp.rs b/sixtyfps_compiler/generator/cpp.rs index aa0c75ec4..724143df7 100644 --- a/sixtyfps_compiler/generator/cpp.rs +++ b/sixtyfps_compiler/generator/cpp.rs @@ -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::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)),