slint
slint copied to clipboard
Implement .as_weak() and .upgrade() for global component instances
The idea to make it easier and more convenient to pass a reference to a Slint global instance into a Rust closure / lambda.
The current implementation works the following way:
pub fn init(blogica_api: &BLogicAAPI) {
blogica_api.on_update_data({
let blogica_api_weak = blogica_api.as_weak();
|bdata| {
let blogica_api = blogica_api_weak.upgrade().unwrap();
// It would have been very nice if the call to .global() could avoided, as it depends on the lifetime
// of the GlobalStrong<T> it's needed
let blogica_api = blogica_api_weak.to_global();
// Do stuff here with blogica_api
}
});
}
Fixes #9389