-
I am a beginner in Rust, looking for a practical and beautiful GUI. When I first saw Slint, I fell in love with her. But I have some doubts, why Slint is so much slower than egui f 20230725_230141.mp4or the same query code, a novice question. (my english is poor, sorry) |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
I get a 403 forbidden error when trying to access your code. |
Beta Was this translation helpful? Give feedback.
-
Thanks for reporting this issue. It looks like populating the large table is slow. It would indeed be interesting to see how the code looks like that you're using the populate the model. Like @Vadoola I can't seem to access the source code :(. Could it be that the repository is not public? (yes, I removed the trailing comma from the URL). |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks for updating the source code - I can see it now. I can't run it (because it requires access to the database), but from a glance at the code I think I can see what the issue might be. In the callback that's invoked when pressing the button (after selecting for example "Carton"), this function is called: fn get_carton_result(text: String,app_weak:Weak<App>) {
let rt = tokio::runtime::Runtime::new().unwrap();
let res = rt.block_on(async {
let row_data = carton_work(text).await;
app_weak
.unwrap()
.global::<TableView>()
.set_row_data(row_data.into());
// app_weak
// .unwrap()
// .global::<TableView>()
// .set_row_data(row_data.into());
});
// res
} The call to What I would recommend instead is something like we've done in cargo-ui:
This way the UI thread remains always responsive while your worker thread uses tokio to spawn tasks to interact with your database. Does that make sense? :) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the guide, I'm trying to use multithreading, but I'm getting an error, |
Beta Was this translation helpful? Give feedback.
-
@Vjze I can give you some reference app.global::<PanelViewGlobal>().on_clicked({
let app_weak = app.as_weak();
move || {
let app_weak = app_weak.clone();
//multi-thread
async_std::task::spawn(async move {
let mut i = 0;
loop {
if i > 90 {
break;
}
task::sleep(Duration::from_millis(200)).await;
app_weak
.upgrade_in_event_loop(|ui| {
ui.global::<PanelViewGlobal>().set_value(
chrono::Local::now()
.format("%Y-%m-%d %H:%M:%S")
.to_string()
.into(),
);
})
.unwrap();
i += 1;
}
});
}
}); |
Beta Was this translation helpful? Give feedback.
-
(I converted this issue to a discussion, since it is not really a bug report) Another way would be to use slint::spawn_local to run your without blocking the UI. |
Beta Was this translation helpful? Give feedback.
Thanks for updating the source code - I can see it now. I can't run it (because it requires access to the database), but from a glance at the code I think I can see what the issue might be.
In the callback that's invoked when pressing the button (after selecting for example "Carton"), this function is called: