Repository navigation
How to create a generic over generated globals and components? #13675
Replies: 4 comments
|
One more thing to add: Since the Android block is in |
|
You need to add more bounds: pub fn start_backend<T>
(
db_path: &PathBuf,
window: &'a T,
)
where
T: slint::ComponentHandle,
ProfileList: slint::Global<'a, T>
{
// ...snip
let profile_list = ProfilesList::get(window);
}something like that, but i haven't tried. |
|
ogoffart's bound is the right idea. There are two small things to get it to compile:
use slint::Global; // for ProfilesList::get
pub fn start_backend<'a, T>(db_path: &PathBuf, window: &'a T)
where
T: slint::ComponentHandle,
ProfilesList<'a>: slint::Global<'a, T>,
{
let profile_list = ProfilesList::get(window);
// or: let profile_list = window.global::<ProfilesList>();
// ...snip, profile_list.set_xxx(...) / on_xxx(...) work as usual
}Since your error shows both If you later need to keep the component around inside callbacks, take |
|
I tried the bound suggested above and it works: one generic function can serve both root components. fn start_backend<'a, T>(window: &'a T)
where
T: slint::ComponentHandle,
ProfilesList<'a>: slint::Global<'a, T>,
{
let profiles = ProfilesList::get(window); // or window.global::<ProfilesList>()
profiles.on_add(|name| println!("add {name}"));
}Tested with Slint 1.18.1 on Linux (Kali, rustc 1.99.0) and Windows (rustc 1.98.1), using One detail: the E0277 in the question comes from the missing |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
EDIT: This project is in Rust.
I am currently developing a cross-platoform (Linux+Android) application that pretty much uses the same core logic with major difference being UI design and platform-specific compatibility features.
I have two root components mainly,
DesktopWindowandMainWindow(Linux/Android), which share a global namedProfilesList.In one of my modules, I have:
I would then get a compiler error:
I wonder if there's a way to resolve this.
My last choice would be to have the project support only one platform then either fork or create an entirely new one for another platform.
All reactions